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.
This commit is contained in:
2025-08-15 15:02:28 -05:00
parent 0967795d51
commit 73ee5e554b

View File

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