add projectile lifetimes

This commit is contained in:
Jim 2025-09-02 14:00:37 -04:00
parent 68f4b0d8a0
commit 69bab35998
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
3 changed files with 25 additions and 5 deletions

View file

@ -1,11 +1,11 @@
(
map: {
MouseButton(Middle): [
CameraOrbitEnable,
],
KeyCode(ShiftLeft): [
MultiPlaceTower,
],
MouseButton(Middle): [
CameraOrbitEnable,
],
KeyCode(F1): [
ToggleDebugUI,
],

View file

@ -16,7 +16,13 @@ pub(crate) struct ProjectilePlugin;
impl Plugin for ProjectilePlugin {
fn build(&self, app: &mut App) {
app.add_systems(FixedUpdate, fire_launcher.in_set(GameSystemSet::Execute));
app.add_systems(
FixedUpdate,
(
fire_launcher.in_set(GameSystemSet::Execute),
tick_lifetime.in_set(GameSystemSet::PostTick),
),
);
}
}
@ -154,6 +160,20 @@ fn fire_launcher(
}
}
fn tick_lifetime(
mut projectiles: Query<(Entity, &mut Projectile)>,
mut commands: Commands,
time: Res<Time>,
) {
let delta = time.delta();
for (entity, mut projectile) in projectiles.iter_mut() {
projectile.lifetime = projectile.lifetime.saturating_sub(delta);
if projectile.lifetime == Duration::ZERO {
commands.entity(entity).despawn();
}
}
}
/// may shoot higher than height if delta y is too big
pub fn get_launch_vector(start: Vec3, target: Vec3, height: f32, spread: f32) -> Vec3 {
// actually +/-, but go with + for now

View file

@ -11,7 +11,7 @@ x improve enemy AI
- More towers
- More upgrades
x More enemy types
- More resource deposit types
x More resource deposit types
- Improve wave generation
--- STILL PRETTY IMPORTANT ---