From 8520323cca0d04ff0c4c7307c80d61cb63607d21 Mon Sep 17 00:00:00 2001 From: nquidox Date: Sat, 18 Apr 2026 21:54:43 +0300 Subject: [PATCH 1/4] format + todo --- src/states/linear/ui.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/states/linear/ui.rs b/src/states/linear/ui.rs index 9ceb97c..c8d1839 100644 --- a/src/states/linear/ui.rs +++ b/src/states/linear/ui.rs @@ -4,7 +4,7 @@ use crate::states::linear::plugin::LinearUpdateSet; use crate::states::linear::{DebugToggle, LinearRestartMarker, LinearStateMarker}; use crate::ui::button_click::ButtonClickMessage; use crate::ui::click::handle_click_system; -use crate::ui::{ButtonStyle, spawn_button, spawn_background}; +use crate::ui::{ButtonStyle, spawn_button}; use bevy::prelude::*; use crate::{FACTOR, HEIGHT, WIDTH}; @@ -67,6 +67,7 @@ fn setup_ui(mut commands: Commands, asset_server: Res) { Transform::from_xyz(0.0, 0.0, -10.0), LinearStateMarker, )); + // TODO - изменить функцию спавна бгшки, чтоб можно было задавать параметры окна // spawn_background(&mut commands, bg_image, LinearStateMarker); spawn_button( @@ -100,8 +101,6 @@ fn setup_ui(mut commands: Commands, asset_server: Res) { &button_style, DebugToggle::Laser, ); - - } pub fn restart_game_button_system( From f502cdb0ce82c4b5ec23d9dfc23edb983fe389bb Mon Sep 17 00:00:00 2001 From: nquidox Date: Sat, 18 Apr 2026 21:55:00 +0300 Subject: [PATCH 2/4] debug logger --- src/main.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) 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, From eeebdbd2722a311e4a21da816a4794ba54220070 Mon Sep 17 00:00:00 2001 From: nquidox Date: Sat, 18 Apr 2026 21:55:27 +0300 Subject: [PATCH 3/4] moved critical systems to fixed update schedule --- src/states/linear/plugin.rs | 69 +++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/states/linear/plugin.rs b/src/states/linear/plugin.rs index b02d144..3b5a724 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, + ).in_set(LinearUpdateSet::Track), + ) + .add_systems(OnExit(LinearPlayState), cleanup); } } @@ -51,8 +60,8 @@ 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{ + + let debug_config = LinearDebugConfig { toggle_track: true, toggle_grid: true, toggle_laser: false, From 67ddcb0c6581eefbc3834fe129419777fc3af15f Mon Sep 17 00:00:00 2001 From: nquidox Date: Sun, 19 Apr 2026 22:18:40 +0300 Subject: [PATCH 4/4] factor ou projectile components and systems --- src/states/linear/components_cannon.rs | 24 -- src/states/linear/components_projectile.rs | 33 ++ src/states/linear/mod.rs | 5 + src/states/linear/plugin.rs | 6 +- src/states/linear/systems_cannon.rs | 267 +------------- src/states/linear/systems_projectile.rs | 384 +++++++++++++++++++++ 6 files changed, 426 insertions(+), 293 deletions(-) create mode 100644 src/states/linear/components_projectile.rs create mode 100644 src/states/linear/systems_projectile.rs 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 3b5a724..5c0ceac 100644 --- a/src/states/linear/plugin.rs +++ b/src/states/linear/plugin.rs @@ -33,7 +33,6 @@ impl Plugin for LinearPlayPlugin { draw_track_gizmos, draw_grid, // draw_cannon_laser, - //несколько систем с соблюдением порядка cycle_cannon_balls, update_linear_cannon_preview, spawn_projectile_from_cannon, @@ -47,6 +46,7 @@ impl Plugin for LinearPlayPlugin { move_round_balls, calculate_projectile_hits, linear_move_projectiles, + insert_projectile_into_track, ).in_set(LinearUpdateSet::Track), ) .add_systems(OnExit(LinearPlayState), cleanup); @@ -62,8 +62,8 @@ fn setup(mut commands: Commands) { commands.insert_resource(build_linear_cannon_state()); let debug_config = LinearDebugConfig { - toggle_track: true, - toggle_grid: true, + 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