From 73ee5e554bbdfe583cdc7d68a9166d5785e7bb80 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Fri, 15 Aug 2025 15:02:28 -0500 Subject: [PATCH] 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. --- src/objects.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/objects.rs b/src/objects.rs index d44a1b4..52650e9 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -197,20 +197,21 @@ pub fn ship_impact_listener( game_assets: Res, ) { 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; }