From 67ddcb0c6581eefbc3834fe129419777fc3af15f Mon Sep 17 00:00:00 2001 From: nquidox Date: Sun, 19 Apr 2026 22:18:40 +0300 Subject: [PATCH] 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