Compare commits
2 Commits
0967795d51
...
746de2bd80
| Author | SHA1 | Date | |
|---|---|---|---|
| 746de2bd80 | |||
| 73ee5e554b |
@@ -197,20 +197,21 @@ pub fn ship_impact_listener(
|
||||
game_assets: Res<GameAssets>,
|
||||
) {
|
||||
for _ in events.read() {
|
||||
// STEP 1: Decrement lives (and maybe go to game over)
|
||||
// STEP 1: Clear asteroids
|
||||
for rock in rocks {
|
||||
commands.entity(rock).despawn();
|
||||
}
|
||||
|
||||
// STEP 2: Decrement lives
|
||||
if lives.0 == 0 {
|
||||
// If already at 0, game is over.
|
||||
// If the player has run out, return early with a state change.
|
||||
next_state.set(GameState::GameOver);
|
||||
return;
|
||||
} else {
|
||||
// Decrease life count.
|
||||
lives.0 -= 1;
|
||||
}
|
||||
|
||||
// STEP 2: Clear asteroids
|
||||
for rock in rocks {
|
||||
commands.entity(rock).despawn();
|
||||
}
|
||||
|
||||
// STEP 3: spawn the debris field where the player used to be.
|
||||
for i in 0..10 {
|
||||
let angle_rads = (i as f32) / 10.0 * std::f32::consts::TAU;
|
||||
@@ -228,7 +229,7 @@ pub fn ship_impact_listener(
|
||||
));
|
||||
}
|
||||
|
||||
// STEP 3: Respawn player (teleport them to the origin)
|
||||
// STEP 4: Respawn player (teleport them to the origin)
|
||||
player.0.translation = Vec3::ZERO;
|
||||
player.1.0 = Vec2::ZERO;
|
||||
}
|
||||
|
||||
@@ -216,6 +216,11 @@ fn spawn_gameover_ui(mut commands: Commands) {
|
||||
..default()
|
||||
},
|
||||
children![
|
||||
(
|
||||
Text::new("Game Over"),
|
||||
TextFont::from_font_size(35.0),
|
||||
TextShadow::default(),
|
||||
),
|
||||
(button_bundle("Main Menu"), ButtonMenuAction::ToMainMenu,),
|
||||
(button_bundle("Quit"), ButtonMenuAction::Quit),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user