From 214ac5f56ff3702a83bdb10d9e5f931109795592 Mon Sep 17 00:00:00 2001 From: Thom Bruce Date: Sat, 18 Nov 2023 09:41:00 +0000 Subject: [PATCH 1/5] spawn enemies on a timer --- CHANGELOG.md | 1 + src/ships/enemy.rs | 37 +++++++++++++++++++++++-------------- src/ships/mod.rs | 3 ++- src/systems/mod.rs | 2 +- src/ui/hud/indicator.rs | 2 ++ 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 085a1e3..ccffb49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add game score that increases when player damages or destroys an enemy +- Spawn timer; enemies will now spawn continuously ### Changed diff --git a/src/ships/enemy.rs b/src/ships/enemy.rs index 44acaeb..8613862 100644 --- a/src/ships/enemy.rs +++ b/src/ships/enemy.rs @@ -11,6 +11,16 @@ use super::{ ship::{ship_rotation, ship_thrust, Health, Ship}, }; +pub struct SpawnTimerPlugin; +impl Plugin for SpawnTimerPlugin { + fn build(&self, app: &mut App) { + app.insert_resource(SpawnTimer(Timer::from_seconds(6.0, TimerMode::Repeating))); + } +} + +#[derive(Resource)] +pub struct SpawnTimer(pub Timer); + /// Enemy component #[derive(Component)] pub struct Enemy; @@ -69,19 +79,17 @@ pub struct Adversaries(pub Vec); // retrieval/use at a later time. /// The setup function -pub(crate) fn spawn_enemies(mut commands: Commands, sprites: Res) { - // Spawns enemy ships - for (_i, pos) in [ - (250.0 as f32, 250.0 as f32), - (-250.0 as f32, -250.0 as f32), - (-25000.0 as f32, 0.0 as f32), - (25000.0 as f32, 0.0 as f32), - (0.0 as f32, 25000.0 as f32), - (0.0 as f32, -25000.0 as f32), - ] - .iter() - .enumerate() - { +pub(crate) fn spawn_enemies( + time: Res