//! Systems, Components, and any other items for powering the game logic. //! //! Where the objects (ship, asteroid, etc) carry their own behavioral systems, //! the *game* keeps its main logic here. Its for ambient behaviors, like //! asteroid spawning, or eventually the flying saucer spawns. use rand::{Rng, SeedableRng}; use std::time::Duration; use bevy::prelude::*; use crate::{WorldSize, events::SpawnAsteroid, objects::AsteroidSize}; /// Asteroid spawning parameters and state. /// /// This struct keeps track of the rng and timer for spawning asteroids. In the /// future it may contain additional fields to allow for more control. /// /// It's values are operated by the [`tick_asteroid_manager`] system. #[derive(Resource)] pub struct AsteroidSpawner { rng: std::sync::Mutex, timer: Timer, // TODO: Configurables? // - interval // - density // - size distribution } impl AsteroidSpawner { pub fn new() -> Self { Self { rng: std::sync::Mutex::new(rand::rngs::StdRng::from_seed(crate::config::RNG_SEED)), timer: Timer::new(Duration::from_secs(3), TimerMode::Repeating), } } } /// Update the asteroid spawn timer in the [`AsteroidSpawner`] resource, and /// spawns any asteroids that are due this frame. pub fn tick_asteroid_manager( mut events: EventWriter, mut spawner: ResMut, time: Res