From 2c43bc699ed48602b2f77666400f18d2c11a5f75 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 29 Jul 2025 13:12:22 -0500 Subject: [PATCH] Begin work on event-based asteroid spawning The events are being emitted by the spawn manager, and consumed by the spawn_asteroid system. Now to wire in the spawn properties, and then make a good spawning manager. --- src/asteroids.rs | 37 +++++++++++++++++++++++++++---------- src/lib.rs | 4 +++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/asteroids.rs b/src/asteroids.rs index 909d01c..42344e9 100644 --- a/src/asteroids.rs +++ b/src/asteroids.rs @@ -2,7 +2,7 @@ use std::time::Duration; /// This is the module containing all the rock-related things /// not... not the whole game. -use bevy::prelude::*; +use bevy::{math::VectorSpace, prelude::*}; use crate::{GameAssets, Position, Rotation, Velocity}; @@ -32,16 +32,40 @@ impl AsteroidSpawner { } } +#[derive(Event)] +pub struct SpawnAsteroid { + pos: Vec2, + vel: Vec2, + size: AsteroidSize, +} + /// Update the asteroid spawn timer and spawn any asteroids /// that are due this frame. pub fn tick_asteroid_manager( - mut commands: Commands, + mut events: EventWriter, mut spawner: ResMut, - game_assets: Res, time: Res