Use the lifetime limiters on Bullets & Asteroids
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 7m3s

Closes #14

Despawn bullets to limit range.

Despawn asteroids to limit random garbage floating around the scene.
This commit is contained in:
2025-08-10 17:13:25 -05:00
parent 2f463303a0
commit 364fbd7530
3 changed files with 9 additions and 4 deletions

View File

@@ -7,7 +7,7 @@ use std::time::Duration;
use bevy::prelude::*; use bevy::prelude::*;
use crate::{GameAssets, WorldSize, physics::Velocity}; use crate::{GameAssets, Lifetime, WorldSize, config::ASTEROID_LIFETIME, physics::Velocity};
#[derive(Component, Deref, DerefMut)] #[derive(Component, Deref, DerefMut)]
pub struct Asteroid(AsteroidSize); pub struct Asteroid(AsteroidSize);
@@ -124,6 +124,7 @@ pub fn spawn_asteroid(
Velocity(spawn.vel), Velocity(spawn.vel),
Mesh2d(mesh), Mesh2d(mesh),
MeshMaterial2d(material), MeshMaterial2d(material),
Lifetime(Timer::from_seconds(ASTEROID_LIFETIME, TimerMode::Once)),
)); ));
} }
} }

View File

@@ -17,5 +17,8 @@ pub(crate) const SHIP_THRUST: f32 = 1.0;
pub(crate) const SHIP_ROTATION: f32 = 4.0; // +/- rotation speed in... radians per frame pub(crate) const SHIP_ROTATION: f32 = 4.0; // +/- rotation speed in... radians per frame
pub(crate) const BULLET_SPEED: f32 = 150.0; pub(crate) const BULLET_SPEED: f32 = 150.0;
pub(crate) const BULLET_LIFETIME: f32 = 2.0;
pub(crate) const ASTEROID_LIFETIME: f32 = 40.0;
pub const RNG_SEED: [u8; 32] = *b"12345678909876543210123456789098"; pub const RNG_SEED: [u8; 32] = *b"12345678909876543210123456789098";

View File

@@ -8,9 +8,9 @@ mod title_screen;
use crate::asteroids::{Asteroid, AsteroidSpawner}; use crate::asteroids::{Asteroid, AsteroidSpawner};
use crate::config::{ use crate::config::{
ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, BULLET_COLOR, BULLET_SPEED, PLAYER_SHIP_COLOR, ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, BULLET_COLOR, BULLET_LIFETIME, BULLET_SPEED,
SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE, PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE,
WINDOW_SIZE, SHIP_THRUSTER_COLOR_INACTIVE, WINDOW_SIZE,
}; };
use crate::physics::AngularVelocity; use crate::physics::AngularVelocity;
use crate::ship::{Bullet, Ship}; use crate::ship::{Bullet, Ship};
@@ -340,6 +340,7 @@ fn input_ship_shoot(
Mesh2d(game_assets.bullet().0), Mesh2d(game_assets.bullet().0),
MeshMaterial2d(game_assets.bullet().1), MeshMaterial2d(game_assets.bullet().1),
ship_pos.clone(), // clone ship transform ship_pos.clone(), // clone ship transform
Lifetime(Timer::from_seconds(BULLET_LIFETIME, TimerMode::Once)),
)); ));
} }
} }