From 1555c93bedc96258a022d092d1b73b27a6bd4406 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Tue, 29 Jul 2025 17:44:33 -0500 Subject: [PATCH] Set asteroid velocity so they move into play area It's functional, if not especially interesting. Forward to the next thing! --- src/asteroids.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/asteroids.rs b/src/asteroids.rs index f6f6451..b41d697 100644 --- a/src/asteroids.rs +++ b/src/asteroids.rs @@ -70,12 +70,17 @@ pub fn tick_asteroid_manager( spawn_distance * spawn_angle.sin(), ); - // TODO: Assign velocity such that asteroids will (probably) cross the viewport // Right now, I'm thinking I can use the opposite signs attached to the position Vec components. // pos.x == -100, then vel.x = + // pos.x == 100, then vel.x = - // etc, - let vel = Vec2::new(rng.random_range(-10.0..10.0), rng.random_range(-10.0..10.0)); + let mut vel = Vec2::new(rng.random_range(0.0..100.0), rng.random_range(0.0..100.0)); + if pos.x > 0.0 { + vel.x *= -1.0; + } + if pos.y > 0.0 { + vel.y *= -1.0; + } let size = match rng.random_range(0..=2) { 0 => AsteroidSize::Small,