From 2b93654491d24ab9ee92e5e79b9ac2f8576a8ea5 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 29 Jul 2025 16:31:35 -0500 Subject: [PATCH] Randomly assign asteroid spawning positions I need to close the circle down to touch the corners of the play area, but this demonstrates the principle. Next, I need to generate a velocity and "fix" it so that the asteroid crosses through the viewport. I left a TODO about this, which I think will work well enough. Although it might allow for some asteroids to slip past, or bias the density in a funny way. Oh well, it's just an Asteroids game. --- src/asteroids.rs | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/asteroids.rs b/src/asteroids.rs index c1d09e4..f6f6451 100644 --- a/src/asteroids.rs +++ b/src/asteroids.rs @@ -1,11 +1,11 @@ +use rand::{Rng, SeedableRng}; use std::time::Duration; -use rand::SeedableRng; /// This is the module containing all the rock-related things /// not... not the whole game. use bevy::prelude::*; -use crate::{GameAssets, Position, Rotation, Velocity}; +use crate::{GameAssets, Position, Rotation, Velocity, WorldSize}; #[derive(Component, Deref, DerefMut)] pub struct Asteroid(AsteroidSize); @@ -48,14 +48,43 @@ pub fn tick_asteroid_manager( mut events: EventWriter, mut spawner: ResMut, time: Res