Add "rand" crate, store an RNG in AsteroidSpawner
This commit is contained in:
@@ -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"
|
||||||
|
|||||||
@@ -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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|||||||
Reference in New Issue
Block a user