Add "rand" crate, store an RNG in AsteroidSpawner

This commit is contained in:
2025-07-29 13:32:26 -05:00
parent eee039339e
commit c80ada4aa6
3 changed files with 6 additions and 0 deletions

View File

@@ -6,3 +6,4 @@ edition = "2021"
[dependencies] [dependencies]
bevy = { version = "0.16", features = ["dynamic_linking"] } bevy = { version = "0.16", features = ["dynamic_linking"] }
bevy-inspector-egui = "0.32.0" bevy-inspector-egui = "0.32.0"
rand = "0.9.2"

View File

@@ -1,4 +1,5 @@
use std::time::Duration; use std::time::Duration;
use rand::SeedableRng;
/// This is the module containing all the rock-related things /// This is the module containing all the rock-related things
/// not... not the whole game. /// not... not the whole game.
@@ -17,6 +18,7 @@ pub enum AsteroidSize {
#[derive(Resource)] #[derive(Resource)]
pub struct AsteroidSpawner { pub struct AsteroidSpawner {
rng: std::sync::Mutex<rand::rngs::StdRng>,
timer: Timer, timer: Timer,
// TODO: Configurables? // TODO: Configurables?
// - interval // - interval
@@ -27,6 +29,7 @@ pub struct AsteroidSpawner {
impl AsteroidSpawner { impl AsteroidSpawner {
pub fn new() -> Self { pub fn new() -> Self {
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), timer: Timer::new(Duration::from_secs(3), TimerMode::Repeating),
} }
} }

View File

@@ -16,3 +16,5 @@ pub(crate) const ASTEROID_SMALL_COLOR: Color = Color::srgb(1.0, 0., 0.);
pub(crate) const SHIP_THRUST: f32 = 1.0; pub(crate) const SHIP_THRUST: f32 = 1.0;
pub(crate) const SHIP_ROTATION: f32 = 0.1; // +/- rotation speed in... radians per frame pub(crate) const SHIP_ROTATION: f32 = 0.1; // +/- rotation speed in... radians per frame
pub const RNG_SEED: [u8; 32] = *b"12345678909876543210123456789098";