diff --git a/src/asteroids.rs b/src/asteroids.rs index afdd673..3c1bd78 100644 --- a/src/asteroids.rs +++ b/src/asteroids.rs @@ -1,6 +1,6 @@ use crate::{HEIGHT, WIDTH}; use macroquad::{prelude::*, rand::gen_range}; -#[derive(Clone)] +#[derive(Clone, PartialEq, Eq)] pub enum AsteroidSize { Large, Medium, @@ -19,12 +19,14 @@ pub struct Asteroid { pub alive: bool, } +const BASE_SIZE: f32 = 20.; + impl Asteroid { pub fn new(size: AsteroidSize) -> Self { let (sides, radius) = match size { - AsteroidSize::Large => (gen_range(6, 10), gen_range(50., 65.)), - AsteroidSize::Medium => (gen_range(5, 6), gen_range(35., 50.)), - AsteroidSize::Small => (gen_range(3, 5), 25.), + AsteroidSize::Large => (gen_range(6, 10), BASE_SIZE * 4.), + AsteroidSize::Medium => (gen_range(5, 6), BASE_SIZE * 2.), + AsteroidSize::Small => (gen_range(3, 5), BASE_SIZE), }; let mut r = vec2( if gen_range(0., 1.) > 0.5 { -1. } else { 1. }, diff --git a/src/world.rs b/src/world.rs index 6b9fc2f..8a53849 100644 --- a/src/world.rs +++ b/src/world.rs @@ -29,9 +29,6 @@ impl World { asteroids: vec![ Asteroid::new_to(vec2(0., 0.), 1.5, AsteroidSize::Large), Asteroid::new(AsteroidSize::Large), - Asteroid::new(AsteroidSize::Large), - Asteroid::new(AsteroidSize::Large), - Asteroid::new(AsteroidSize::Large), ], ..Default::default() } @@ -115,7 +112,26 @@ impl World { // }) < self.max_asteroids // || self.player.lifespan % 200 == 0 // { - if self.player.lifespan % 200 == 0 { + let num_small: usize = self + .asteroids + .iter() + .filter(|a| a.size == AsteroidSize::Small) + .map(|_| 1) + .sum(); + let num_medium: usize = self + .asteroids + .iter() + .filter(|a| a.size == AsteroidSize::Medium) + .map(|_| 1) + .sum(); + let num_large: usize = self + .asteroids + .iter() + .filter(|a| a.size == AsteroidSize::Large) + .map(|_| 1) + .sum(); + let area = num_small + num_medium * 2 + num_large * 4; + if self.player.lifespan % 200 == 0 && area < 12 { self.asteroids .push(Asteroid::new_to(self.player.pos, 1.5, AsteroidSize::Large)); }