feat: add explosion animations on entity destruction
Spawn expanding/fading orange explosion effects when enemies or the player are destroyed. Explosions scale from 15x15 to 50x50 over 0.4s while fading from full opacity to transparent, then auto-despawn. Integration points: - Enemy killed by player bullet (bullet.rs) - Player hit by enemy bullet (bullet.rs) - Player collides with enemy (player.rs) - both explode - Captured player released (player.rs) Refs: GAL-44
This commit is contained in:
parent
db061820b9
commit
2ff561efb1
6 changed files with 77 additions and 2 deletions
|
|
@ -9,6 +9,7 @@ use crate::constants::{
|
|||
};
|
||||
use crate::game_state::AppState;
|
||||
use crate::resources::{PlayerLives, PlayerRespawnTimer};
|
||||
use crate::systems::spawn_explosion;
|
||||
|
||||
// Helper to spawn player (used in setup and respawn)
|
||||
pub fn spawn_player_ship(commands: &mut Commands) {
|
||||
|
|
@ -116,6 +117,7 @@ pub fn handle_captured_player(
|
|||
&mut respawn_timer,
|
||||
&mut next_state,
|
||||
entity,
|
||||
_player_pos,
|
||||
);
|
||||
continue; // Skip the rest of processing for this player
|
||||
}
|
||||
|
|
@ -131,6 +133,7 @@ pub fn handle_captured_player(
|
|||
&mut respawn_timer,
|
||||
&mut next_state,
|
||||
entity,
|
||||
transform.translation,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -144,11 +147,15 @@ fn lose_life_and_respawn(
|
|||
respawn_timer: &mut ResMut<PlayerRespawnTimer>,
|
||||
next_state: &mut ResMut<NextState<AppState>>,
|
||||
player_entity: Entity,
|
||||
player_position: Vec3,
|
||||
) {
|
||||
// Lose a life
|
||||
lives.count = lives.count.saturating_sub(1);
|
||||
println!("Lives remaining: {}", lives.count);
|
||||
|
||||
// Spawn explosion at player position before destroying
|
||||
spawn_explosion(commands, player_position);
|
||||
|
||||
// Destroy player
|
||||
commands.entity(player_entity).despawn();
|
||||
|
||||
|
|
@ -218,11 +225,13 @@ pub fn check_player_enemy_collisions(
|
|||
|
||||
if distance < PLAYER_ENEMY_COLLISION_THRESHOLD {
|
||||
println!("Player hit by enemy!");
|
||||
spawn_explosion(&mut commands, enemy_transform.translation);
|
||||
commands.entity(enemy_entity).despawn(); // Despawn enemy
|
||||
|
||||
lives.count = lives.count.saturating_sub(1); // Decrement lives safely
|
||||
println!("Lives remaining: {}", lives.count);
|
||||
|
||||
spawn_explosion(&mut commands, player_transform.translation);
|
||||
commands.entity(player_entity).despawn(); // Despawn player
|
||||
|
||||
if lives.count > 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue