Move Lifetime component to machinery module

This commit is contained in:
2025-08-11 23:33:56 -05:00
parent 34ee2fcc7d
commit 9a262fcffc
3 changed files with 20 additions and 14 deletions

View File

@@ -22,6 +22,7 @@ use bevy_rapier2d::{
prelude::*,
render::RapierDebugRenderPlugin,
};
use machinery::Lifetime;
use resources::{GameAssets, Lives, Score, WorldSize};
pub struct AsteroidPlugin;
@@ -64,7 +65,7 @@ impl Plugin for AsteroidPlugin {
physics::collision_listener,
// TODO: Remove debug printing
debug_collision_event_printer,
tick_lifetimes,
machinery::tick_lifetimes,
)
.run_if(in_state(GameState::Playing)),
)
@@ -98,9 +99,6 @@ pub enum GameState {
GameOver, // Game has ended. Present game over dialogue and await user restart
}
#[derive(Component)]
struct Lifetime(Timer);
fn spawn_camera(mut commands: Commands) {
commands.spawn(Camera2d);
}
@@ -196,12 +194,3 @@ fn spawn_ui(mut commands: Commands, score: Res<Score>, lives: Res<Lives>) {
TextFont::from_font_size(25.0),
));
}
fn tick_lifetimes(mut commands: Commands, time: Res<Time>, query: Query<(Entity, &mut Lifetime)>) {
for (e, mut life) in query {
life.0.tick(time.delta());
if life.0.just_finished() {
commands.entity(e).despawn();
}
}
}