Gameover condition

This commit is contained in:
Rendo 2025-11-17 23:57:08 +05:00
commit 66797415bd
4 changed files with 16 additions and 11 deletions

View file

@ -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)]

View file

@ -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);
}
}

View file

@ -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<DamageableKilled>, mut commands: Commands) {
let Some(faction) = killed.killed_faction else {
return;
};
if faction == Factions::PlayerFaction {
commands.set_state(GameState::Gameover);
return;
}
}

View file

@ -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,