From 782e446c462e751b70bce52b445fe74088f348b8 Mon Sep 17 00:00:00 2001 From: Rendo Date: Sun, 16 Nov 2025 14:43:15 +0500 Subject: [PATCH 1/2] Unused content cleanup --- src/ships/mod.rs | 8 -------- src/velocity.rs | 13 ------------- 2 files changed, 21 deletions(-) diff --git a/src/ships/mod.rs b/src/ships/mod.rs index 85a35dd..cc5e492 100644 --- a/src/ships/mod.rs +++ b/src/ships/mod.rs @@ -9,7 +9,6 @@ pub mod player; pub enum Factions { PlayerFaction, EnemyFaction, - NeutralFaction, } impl Factions { @@ -18,17 +17,10 @@ impl Factions { Factions::PlayerFaction => match other { Factions::PlayerFaction => false, Factions::EnemyFaction => true, - Factions::NeutralFaction => false, }, Factions::EnemyFaction => match other { Factions::PlayerFaction => true, Factions::EnemyFaction => false, - Factions::NeutralFaction => false, - }, - Factions::NeutralFaction => match other { - Factions::EnemyFaction => false, - Factions::NeutralFaction => false, - Factions::PlayerFaction => false, }, } } diff --git a/src/velocity.rs b/src/velocity.rs index ae44d10..77e5324 100644 --- a/src/velocity.rs +++ b/src/velocity.rs @@ -24,19 +24,6 @@ pub struct Velocity { } impl Velocity { - pub fn new( - linear_speed: f32, - rotation_speed: f32, - max_linear_speed: f32, - max_rotation_speed: f32, - ) -> Velocity { - Velocity { - linear_speed, - rotation_speed, - max_linear_speed: max_linear_speed, - max_rotation_speed: max_rotation_speed, - } - } pub fn stopped(max_linear_speed: f32, max_rotation_speed: f32) -> Velocity { Velocity { linear_speed: 0., From 9c774fdccf90af56d62c0349cb522b5ac49d1169 Mon Sep 17 00:00:00 2001 From: Rendo Date: Sun, 16 Nov 2025 17:45:58 +0500 Subject: [PATCH 2/2] Decouple gun from player --- src/projectile.rs | 41 +++++++++---------------------- src/ships/gun.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++ src/ships/mod.rs | 6 +++-- src/ships/player.rs | 42 +++++--------------------------- 4 files changed, 81 insertions(+), 67 deletions(-) create mode 100644 src/ships/gun.rs diff --git a/src/projectile.rs b/src/projectile.rs index 030b85f..16d6a29 100644 --- a/src/projectile.rs +++ b/src/projectile.rs @@ -1,12 +1,6 @@ use bevy::prelude::*; -use crate::{ - GameState, - collision::{Collided, Collider}, - damagable::Damagable, - ships::Factions, - velocity::Velocity, -}; +use crate::{GameState, collision::Collided, damagable::Damagable, ships::Factions}; #[derive(Component)] pub struct Projectile { @@ -16,7 +10,10 @@ pub struct Projectile { } #[derive(Resource)] -pub struct ProjectileSprite(Handle); +pub struct ProjectileSprite { + pub player_projectile: Handle, + pub enemy_projectile: Handle, +} pub struct ProjectilePlugin; @@ -32,16 +29,20 @@ impl Projectile { impl Plugin for ProjectilePlugin { fn build(&self, app: &mut App) { - app.add_systems(OnEnter(GameState::Game), projectile_startup) + app.add_systems(Startup, projectile_startup) .add_systems( FixedPreUpdate, projectile_despawn_countdown.run_if(in_state(GameState::Game)), - ); + ) + .add_observer(observe_collision); } } pub fn projectile_startup(mut commands: Commands, asset_server: Res) { - commands.insert_resource(ProjectileSprite(asset_server.load("projectile.png"))); + commands.insert_resource(ProjectileSprite { + player_projectile: asset_server.load("projectile.png"), + enemy_projectile: asset_server.load("enemy_projectile.png"), + }); } pub fn projectile_despawn_countdown( @@ -57,24 +58,6 @@ pub fn projectile_despawn_countdown( } } -pub fn spawn_projectile( - commands: &mut Commands, - sprite: Res, - transform: Transform, - damage: u32, - faction: Factions, -) { - commands - .spawn(( - Projectile::new(damage, faction), - Sprite::from(sprite.0.clone()), - Collider::new(8.), - transform, - Velocity::moving(1024.0, 0.0), - )) - .observe(observe_collision); -} - pub fn observe_collision( collision: On, mut commands: Commands, diff --git a/src/ships/gun.rs b/src/ships/gun.rs new file mode 100644 index 0000000..c402c2e --- /dev/null +++ b/src/ships/gun.rs @@ -0,0 +1,59 @@ +use bevy::prelude::*; +use rand::random_range; + +use crate::{ + collision::Collider, + projectile::{Projectile, ProjectileSprite}, + ships::Factions, + velocity::Velocity, +}; + +#[derive(Component)] +pub struct Gun { + pub shoot: bool, + shoot_timer: Timer, + damage: u32, + spread_radius: f32, +} + +impl Gun { + pub fn new(damage: u32, spread: f32, firerate: f32) -> Self { + Self { + shoot: false, + shoot_timer: Timer::from_seconds(firerate, TimerMode::Once), + damage, + spread_radius: spread, + } + } +} + +pub fn gun_shooting_system( + mut commands: Commands, + time: Res