Use a more lenient asteroid spawning strategy
Two large asteroids are created to start. New asteroids are only created when the total asteroid area is below 12. Large asteroids have 4 area, medium asteroids have 2, and small asteroids have 1. Asteroid true sizes are based on multiples of a base number.
This commit is contained in:
parent
154517654e
commit
36da3483ae
|
@ -1,6 +1,6 @@
|
||||||
use crate::{HEIGHT, WIDTH};
|
use crate::{HEIGHT, WIDTH};
|
||||||
use macroquad::{prelude::*, rand::gen_range};
|
use macroquad::{prelude::*, rand::gen_range};
|
||||||
#[derive(Clone)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub enum AsteroidSize {
|
pub enum AsteroidSize {
|
||||||
Large,
|
Large,
|
||||||
Medium,
|
Medium,
|
||||||
|
@ -19,12 +19,14 @@ pub struct Asteroid {
|
||||||
pub alive: bool,
|
pub alive: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BASE_SIZE: f32 = 20.;
|
||||||
|
|
||||||
impl Asteroid {
|
impl Asteroid {
|
||||||
pub fn new(size: AsteroidSize) -> Self {
|
pub fn new(size: AsteroidSize) -> Self {
|
||||||
let (sides, radius) = match size {
|
let (sides, radius) = match size {
|
||||||
AsteroidSize::Large => (gen_range(6, 10), gen_range(50., 65.)),
|
AsteroidSize::Large => (gen_range(6, 10), BASE_SIZE * 4.),
|
||||||
AsteroidSize::Medium => (gen_range(5, 6), gen_range(35., 50.)),
|
AsteroidSize::Medium => (gen_range(5, 6), BASE_SIZE * 2.),
|
||||||
AsteroidSize::Small => (gen_range(3, 5), 25.),
|
AsteroidSize::Small => (gen_range(3, 5), BASE_SIZE),
|
||||||
};
|
};
|
||||||
let mut r = vec2(
|
let mut r = vec2(
|
||||||
if gen_range(0., 1.) > 0.5 { -1. } else { 1. },
|
if gen_range(0., 1.) > 0.5 { -1. } else { 1. },
|
||||||
|
|
24
src/world.rs
24
src/world.rs
|
@ -29,9 +29,6 @@ impl World {
|
||||||
asteroids: vec![
|
asteroids: vec![
|
||||||
Asteroid::new_to(vec2(0., 0.), 1.5, AsteroidSize::Large),
|
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),
|
|
||||||
Asteroid::new(AsteroidSize::Large),
|
|
||||||
],
|
],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
@ -115,7 +112,26 @@ impl World {
|
||||||
// }) < self.max_asteroids
|
// }) < self.max_asteroids
|
||||||
// || self.player.lifespan % 200 == 0
|
// || 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
|
self.asteroids
|
||||||
.push(Asteroid::new_to(self.player.pos, 1.5, AsteroidSize::Large));
|
.push(Asteroid::new_to(self.player.pos, 1.5, AsteroidSize::Large));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue