Use the lifetime limiters on Bullets & Asteroids
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 7m3s
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:
@@ -7,7 +7,7 @@ use std::time::Duration;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{GameAssets, WorldSize, physics::Velocity};
|
||||
use crate::{GameAssets, Lifetime, WorldSize, config::ASTEROID_LIFETIME, physics::Velocity};
|
||||
|
||||
#[derive(Component, Deref, DerefMut)]
|
||||
pub struct Asteroid(AsteroidSize);
|
||||
@@ -124,6 +124,7 @@ pub fn spawn_asteroid(
|
||||
Velocity(spawn.vel),
|
||||
Mesh2d(mesh),
|
||||
MeshMaterial2d(material),
|
||||
Lifetime(Timer::from_seconds(ASTEROID_LIFETIME, TimerMode::Once)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 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";
|
||||
|
||||
@@ -8,9 +8,9 @@ mod title_screen;
|
||||
|
||||
use crate::asteroids::{Asteroid, AsteroidSpawner};
|
||||
use crate::config::{
|
||||
ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, BULLET_COLOR, BULLET_SPEED, PLAYER_SHIP_COLOR,
|
||||
SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE,
|
||||
WINDOW_SIZE,
|
||||
ASTEROID_SMALL_COLOR, BACKGROUND_COLOR, BULLET_COLOR, BULLET_LIFETIME, BULLET_SPEED,
|
||||
PLAYER_SHIP_COLOR, SHIP_ROTATION, SHIP_THRUST, SHIP_THRUSTER_COLOR_ACTIVE,
|
||||
SHIP_THRUSTER_COLOR_INACTIVE, WINDOW_SIZE,
|
||||
};
|
||||
use crate::physics::AngularVelocity;
|
||||
use crate::ship::{Bullet, Ship};
|
||||
@@ -340,6 +340,7 @@ fn input_ship_shoot(
|
||||
Mesh2d(game_assets.bullet().0),
|
||||
MeshMaterial2d(game_assets.bullet().1),
|
||||
ship_pos.clone(), // clone ship transform
|
||||
Lifetime(Timer::from_seconds(BULLET_LIFETIME, TimerMode::Once)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user