diff --git a/src/ships/enemy.rs b/src/ships/enemy.rs index 00396ab..496fa3b 100644 --- a/src/ships/enemy.rs +++ b/src/ships/enemy.rs @@ -1,10 +1,10 @@ +use crate::velocity::Velocity; use bevy::prelude::*; use crate::{ collision::Collider, damagable::Damagable, ships::{Factions, gun::Gun, player::PlayerMovement}, - velocity::{self, Velocity}, }; #[derive(Component)] diff --git a/src/ships/mod.rs b/src/ships/mod.rs index 80218e3..3bc2035 100644 --- a/src/ships/mod.rs +++ b/src/ships/mod.rs @@ -41,7 +41,8 @@ impl Plugin for ShipsPlugin { gun::gun_shooting_system.run_if(in_state(GameState::Game)), enemy::enemy_ai_system.run_if(in_state(GameState::Game)), ), - ); + ) + .add_observer(player::player_death_observer); } } diff --git a/src/ships/player.rs b/src/ships/player.rs index 7f6655b..4d6240b 100644 --- a/src/ships/player.rs +++ b/src/ships/player.rs @@ -1,6 +1,7 @@ use crate::{ + GameState, collision::Collider, - damagable::Damagable, + damagable::{Damagable, DamageableKilled}, ships::{Factions, enemy::Enemy, gun::Gun}, velocity::Velocity, }; @@ -95,3 +96,14 @@ pub fn player_shooting_system( let mut gun = query.into_inner(); gun.shoot = keyboard_input.pressed(KeyCode::Space); } + +pub fn player_death_observer(killed: On, mut commands: Commands) { + let Some(faction) = killed.killed_faction else { + return; + }; + + if faction == Factions::PlayerFaction { + commands.set_state(GameState::Gameover); + return; + } +} diff --git a/src/velocity.rs b/src/velocity.rs index 77e5324..400b94e 100644 --- a/src/velocity.rs +++ b/src/velocity.rs @@ -24,14 +24,6 @@ pub struct Velocity { } impl Velocity { - pub fn stopped(max_linear_speed: f32, max_rotation_speed: f32) -> Velocity { - Velocity { - linear_speed: 0., - rotation_speed: 0., - max_linear_speed: max_linear_speed, - max_rotation_speed: max_rotation_speed, - } - } pub fn moving(max_linear_speed: f32, max_rotation_speed: f32) -> Velocity { Velocity { linear_speed: max_linear_speed,