2 Commits

Author SHA1 Message Date
746de2bd80 Add "Game Over" text to the game over screen
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 7m18s
2025-08-15 15:26:11 -05:00
73ee5e554b Reorder ship-collision steps, rm frozen debris
When the player gets a game-over, the debris is spawned and then frozen
in place as the physics system gets turned off. I can make sure it never
appears by writing the state change and returning early from the
function.

This means the asteroid despawning needs to happen before that point,
otherwise the asteroids would be left on screen.
2025-08-15 15:02:28 -05:00
2 changed files with 14 additions and 8 deletions

View File

@@ -197,20 +197,21 @@ pub fn ship_impact_listener(
game_assets: Res<GameAssets>, game_assets: Res<GameAssets>,
) { ) {
for _ in events.read() { 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 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); next_state.set(GameState::GameOver);
return;
} else { } else {
// Decrease life count. // Decrease life count.
lives.0 -= 1; 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. // STEP 3: spawn the debris field where the player used to be.
for i in 0..10 { for i in 0..10 {
let angle_rads = (i as f32) / 10.0 * std::f32::consts::TAU; 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.0.translation = Vec3::ZERO;
player.1.0 = Vec2::ZERO; player.1.0 = Vec2::ZERO;
} }

View File

@@ -216,6 +216,11 @@ fn spawn_gameover_ui(mut commands: Commands) {
..default() ..default()
}, },
children![ children![
(
Text::new("Game Over"),
TextFont::from_font_size(35.0),
TextShadow::default(),
),
(button_bundle("Main Menu"), ButtonMenuAction::ToMainMenu,), (button_bundle("Main Menu"), ButtonMenuAction::ToMainMenu,),
(button_bundle("Quit"), ButtonMenuAction::Quit), (button_bundle("Quit"), ButtonMenuAction::Quit),
], ],