diff --git a/src/main.rs b/src/main.rs index 2066e59..5c43b0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,36 +2,44 @@ use crate::common::messages::ExitRequestMessage; use crate::common::plugin::CommonUiPlugin; use crate::common::systems::exit_system; use bevy::camera::ScalingMode; +use bevy::log::LogPlugin; use bevy::prelude::*; - mod common; mod gameplay; mod states; mod ui; use crate::states::game::state::MainGameState; +use crate::states::linear::plugin::LinearPlayPlugin; use crate::states::main_menu::state::MainMenuState; use crate::states::settings_menu::state::SettingsMenuState; -use crate::states::linear::plugin::LinearPlayPlugin; const FACTOR: u32 = 40; const WIDTH: u32 = 32; const HEIGHT: u32 = 18; - fn main() { App::new() .add_message::() - .add_plugins(DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "alpha v0.2".into(), - resolution: (WIDTH * FACTOR, HEIGHT * FACTOR).into(), - resizable: true, - ..default() - }), - ..default() - })) + .add_plugins( + DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: "alpha v0.2".into(), + resolution: (WIDTH * FACTOR, HEIGHT * FACTOR).into(), + resizable: true, + ..default() + }), + ..default() + }) + // выводит много инфы, раскоментить по необходимости + // .set(LogPlugin { + // level: bevy::log::Level::DEBUG, + // filter: "bevy_ecs=debug".to_string(), + // ..default() + // }), + ) .add_plugins(( CommonUiPlugin, MainMenuState, diff --git a/src/states/linear/components_cannon.rs b/src/states/linear/components_cannon.rs index 89d3f11..c8f7d85 100644 --- a/src/states/linear/components_cannon.rs +++ b/src/states/linear/components_cannon.rs @@ -31,33 +31,9 @@ impl LinearCannonState { } } -#[derive(Component)] -pub struct RoundBallProjectile { - pub velocity: Vec2, - pub direction: Vec2, - pub previous_position: Vec2, - pub ball_type: RoundBallType, - pub hit_result: Option, -} - -pub struct ProjectileHit { - pub hit_progress: f32, - pub hit_position: Vec2, - pub segment_index: usize, -} - #[derive(Component)] pub struct ShotMarker; #[derive(Component)] pub struct SwapMarker; - -#[derive(Component)] -pub struct IntersectMarker; - -pub struct Intersection { - pub t: f32, - pub world_pos: Vec2, - pub segment_index: usize, -} \ No newline at end of file diff --git a/src/states/linear/components_projectile.rs b/src/states/linear/components_projectile.rs new file mode 100644 index 0000000..b32b275 --- /dev/null +++ b/src/states/linear/components_projectile.rs @@ -0,0 +1,33 @@ +use bevy::math::Vec2; +use bevy::prelude::Component; +use crate::states::linear::RoundBallType; + +#[derive(Component)] +pub struct RoundBallProjectile { + pub velocity: Vec2, + pub direction: Vec2, + pub previous_position: Vec2, + pub ball_type: RoundBallType, + pub hit_result: Option, + pub target_position: Option, +} + +#[derive(Copy, Clone)] +pub struct ProjectileHit { + pub hit_progress: f32, + pub hit_position: Vec2, + pub segment_index: usize, +} + + +#[derive(Component)] +pub struct IntersectMarker; + +pub struct Intersection { + pub t: f32, + pub world_pos: Vec2, + pub segment_index: usize, +} + +#[derive(Component)] +pub struct InsertMarker; \ No newline at end of file diff --git a/src/states/linear/mod.rs b/src/states/linear/mod.rs index bd0d3da..25a5727 100644 --- a/src/states/linear/mod.rs +++ b/src/states/linear/mod.rs @@ -25,6 +25,11 @@ mod components_cannon; pub use components_cannon::*; mod systems_cannon; pub use systems_cannon::*; +mod systems_projectile; +pub use systems_projectile::*; +mod components_projectile; +pub use components_projectile::*; + diff --git a/src/states/linear/plugin.rs b/src/states/linear/plugin.rs index b02d144..5c0ceac 100644 --- a/src/states/linear/plugin.rs +++ b/src/states/linear/plugin.rs @@ -13,34 +13,43 @@ pub enum LinearUpdateSet { impl Plugin for LinearPlayPlugin { fn build(&self, app: &mut App) { - app - .add_systems(OnEnter(LinearPlayState), (setup, spawn_linear_cannon).chain()) - .add_systems(OnEnter(LinearGameRestart), linear_restart) - .add_plugins(LinearUIPlugin) - .configure_sets( - Update, - LinearUpdateSet::Track.run_if(in_state(LinearPlayState)), - ) - .add_systems( - Update, - ( - toggle_debug_systems, - draw_track_gizmos, - draw_grid, - // draw_cannon_laser, - //несколько систем с соблюдением порядка - calculate_projectile_hits, - linear_move_projectiles, - cycle_cannon_balls, - update_linear_cannon_preview, - spawn_projectile_from_cannon, - spawn_round_ball, - move_round_balls, - rotate_linear_cannon, - ) - .in_set(LinearUpdateSet::Track), - ) - .add_systems(OnExit(LinearPlayState), cleanup); + app.add_systems( + OnEnter(LinearPlayState), + (setup, spawn_linear_cannon).chain(), + ) + .add_systems(OnEnter(LinearGameRestart), linear_restart) + .add_plugins(LinearUIPlugin) + .configure_sets( + Update, + LinearUpdateSet::Track.run_if(in_state(LinearPlayState)), + ).configure_sets( + FixedUpdate, + LinearUpdateSet::Track.run_if(in_state(LinearPlayState)), + ) + .add_systems( + Update, + ( + toggle_debug_systems, + draw_track_gizmos, + draw_grid, + // draw_cannon_laser, + cycle_cannon_balls, + update_linear_cannon_preview, + spawn_projectile_from_cannon, + rotate_linear_cannon, + ).in_set(LinearUpdateSet::Track), + ) + .add_systems( + FixedUpdate, + ( + spawn_round_ball, + move_round_balls, + calculate_projectile_hits, + linear_move_projectiles, + insert_projectile_into_track, + ).in_set(LinearUpdateSet::Track), + ) + .add_systems(OnExit(LinearPlayState), cleanup); } } @@ -51,10 +60,10 @@ fn setup(mut commands: Commands) { commands.insert_resource(build_track); commands.insert_resource(precalculated_track); commands.insert_resource(build_linear_cannon_state()); - - let debug_config = LinearDebugConfig{ - toggle_track: true, - toggle_grid: true, + + let debug_config = LinearDebugConfig { + toggle_track: false, + toggle_grid: false, toggle_laser: false, }; commands.insert_resource(debug_config); diff --git a/src/states/linear/systems_cannon.rs b/src/states/linear/systems_cannon.rs index 16865a5..09b394f 100644 --- a/src/states/linear/systems_cannon.rs +++ b/src/states/linear/systems_cannon.rs @@ -96,6 +96,7 @@ pub fn spawn_projectile_from_cannon( previous_position: spawn_pos_2d, ball_type, hit_result: None, + target_position: None, }, IntersectMarker, // маркер для фильтрации, что шарик-снаряд может иметь пересечения с треком LinearStateMarker, @@ -180,269 +181,3 @@ pub fn cycle_cannon_balls( cannon_state.cycle(); } } - -pub fn linear_move_projectiles( - mut commands: Commands, - mut projectiles: Query<(Entity, &mut RoundBallProjectile, &mut Transform)>, - time: Res