Gameover condition
This commit is contained in:
parent
d5bd76a3b7
commit
66797415bd
4 changed files with 16 additions and 11 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
|
use crate::velocity::Velocity;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
collision::Collider,
|
collision::Collider,
|
||||||
damagable::Damagable,
|
damagable::Damagable,
|
||||||
ships::{Factions, gun::Gun, player::PlayerMovement},
|
ships::{Factions, gun::Gun, player::PlayerMovement},
|
||||||
velocity::{self, Velocity},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ impl Plugin for ShipsPlugin {
|
||||||
gun::gun_shooting_system.run_if(in_state(GameState::Game)),
|
gun::gun_shooting_system.run_if(in_state(GameState::Game)),
|
||||||
enemy::enemy_ai_system.run_if(in_state(GameState::Game)),
|
enemy::enemy_ai_system.run_if(in_state(GameState::Game)),
|
||||||
),
|
),
|
||||||
);
|
)
|
||||||
|
.add_observer(player::player_death_observer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
|
GameState,
|
||||||
collision::Collider,
|
collision::Collider,
|
||||||
damagable::Damagable,
|
damagable::{Damagable, DamageableKilled},
|
||||||
ships::{Factions, enemy::Enemy, gun::Gun},
|
ships::{Factions, enemy::Enemy, gun::Gun},
|
||||||
velocity::Velocity,
|
velocity::Velocity,
|
||||||
};
|
};
|
||||||
|
|
@ -95,3 +96,14 @@ pub fn player_shooting_system(
|
||||||
let mut gun = query.into_inner();
|
let mut gun = query.into_inner();
|
||||||
gun.shoot = keyboard_input.pressed(KeyCode::Space);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,14 +24,6 @@ pub struct Velocity {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
pub fn moving(max_linear_speed: f32, max_rotation_speed: f32) -> Velocity {
|
||||||
Velocity {
|
Velocity {
|
||||||
linear_speed: max_linear_speed,
|
linear_speed: max_linear_speed,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue