Move Lifetime component to machinery module
This commit is contained in:
15
src/lib.rs
15
src/lib.rs
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,3 +76,19 @@ pub fn tick_asteroid_manager(
|
||||
events.write(SpawnAsteroid { pos, vel, size });
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Lifetime(pub Timer);
|
||||
|
||||
pub 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@ use bevy::{
|
||||
use bevy_rapier2d::prelude::{ActiveCollisionTypes, ActiveEvents, Collider, Sensor};
|
||||
|
||||
use crate::{
|
||||
AngularVelocity, GameAssets, GameState, Lifetime, Lives,
|
||||
AngularVelocity, GameAssets, GameState, Lives,
|
||||
config::ASTEROID_LIFETIME,
|
||||
events::{AsteroidDestroy, BulletDestroy, ShipDestroy, SpawnAsteroid},
|
||||
machinery::Lifetime,
|
||||
physics::{Velocity, Wrapping},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user