use bevy::prelude::*; use super::health::Health; // 🎞️ #[derive(Component, Clone)] struct AnimationIndices { first: usize, // The first index of the animation last: usize, // The last index of the animation current_index: usize, // The current index of the animation } #[derive(Component, Deref, DerefMut)] struct AnimationTimer(Timer); // The timer for the animation #[derive(Component)] struct DeathAnimationPlayed(bool); // A boolean to track if the death animation has been played // Function to play the death animation for entities with 0 health fn play_death_animation( mut query: Query<(&mut AnimationIndices, &Health, &mut DeathAnimationPlayed, &mut TextureAtlas)> ) { // Iterate over the entities for (mut animation_indices, health, mut death_animation_played, mut atlas) in &mut query { // If the health of the entity is 0 and the death animation has not been played if health.current == 0 && !death_animation_played.0 { // Set the indices for the death animation animation_indices.first = 4; animation_indices.last = 4; animation_indices.current_index = 4; // Update the TextureAtlas index atlas.index = animation_indices.current_index; // Mark the death animation as played death_animation_played.0 = true; } } } // Function to animate the sprite of entities of type T fn animate_sprite( time: Res