Give new planets a random amount of moons
This commit is contained in:
parent
0268740cf6
commit
3fa3f3d48b
1 changed files with 57 additions and 7 deletions
54
src/main.rs
54
src/main.rs
|
@ -499,6 +499,16 @@ impl Menu {
|
||||||
false,
|
false,
|
||||||
"A new planet... It has most certainly been a while.",
|
"A new planet... It has most certainly been a while.",
|
||||||
),
|
),
|
||||||
|
Menu::pause(500.0, false),
|
||||||
|
Menu::text(
|
||||||
|
50.0,
|
||||||
|
HEIGHT_F - 100.0,
|
||||||
|
40.0,
|
||||||
|
false,
|
||||||
|
"Please, go out and create the new universe, and again..",
|
||||||
|
),
|
||||||
|
Menu::pause(300.0, false),
|
||||||
|
Menu::text(50.0, HEIGHT_F - 60.0, 40.0, false, "Thank you."),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,11 +676,19 @@ impl RotatingParticleSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, dt: f64) {
|
fn update(&mut self, dt: f64) {
|
||||||
|
if self.particle_system.is_rect {
|
||||||
let saved_rect = self.particle_system.host_rect;
|
let saved_rect = self.particle_system.host_rect;
|
||||||
self.particle_system.host_rect.pos +=
|
self.particle_system.host_rect.pos +=
|
||||||
Transform::rotate(self.r) * Vector::new(self.offset, 0.0);
|
Transform::rotate(self.r) * Vector::new(self.offset, 0.0);
|
||||||
self.particle_system.update(dt);
|
self.particle_system.update(dt);
|
||||||
self.particle_system.host_rect = saved_rect;
|
self.particle_system.host_rect = saved_rect;
|
||||||
|
} else {
|
||||||
|
let saved_cir = self.particle_system.host_circle;
|
||||||
|
self.particle_system.host_circle.pos +=
|
||||||
|
Transform::rotate(self.r) * Vector::new(self.offset, 0.0);
|
||||||
|
self.particle_system.update(dt);
|
||||||
|
self.particle_system.host_circle = saved_cir;
|
||||||
|
}
|
||||||
self.r += self.velr * dt as f32;
|
self.r += self.velr * dt as f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -787,15 +805,18 @@ struct Planet {
|
||||||
circle: Circle,
|
circle: Circle,
|
||||||
color: Color,
|
color: Color,
|
||||||
particle_system: ParticleSystem,
|
particle_system: ParticleSystem,
|
||||||
|
moons: Vec<RotatingParticleSystem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Planet {
|
impl Planet {
|
||||||
fn new(circle: Circle, color: Color) -> Self {
|
fn new(circle: Circle, color: Color) -> Self {
|
||||||
Planet {
|
let mut smaller_circle = circle;
|
||||||
|
smaller_circle.radius /= 4.0;
|
||||||
|
let mut planet = Planet {
|
||||||
circle,
|
circle,
|
||||||
color,
|
color,
|
||||||
particle_system: ParticleSystem::new(
|
particle_system: ParticleSystem::new(
|
||||||
3500.0,
|
rand::thread_rng().gen_range(2000.0, 3800.0),
|
||||||
900.0,
|
900.0,
|
||||||
Rectangle::new((0.0, 0.0), (1.0, 1.0)),
|
Rectangle::new((0.0, 0.0), (1.0, 1.0)),
|
||||||
circle,
|
circle,
|
||||||
|
@ -805,16 +826,45 @@ impl Planet {
|
||||||
1.0,
|
1.0,
|
||||||
0.3,
|
0.3,
|
||||||
),
|
),
|
||||||
|
moons: Vec::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut r: f32 = rand::thread_rng().gen_range(0.0, 360.0);
|
||||||
|
for i in 0..rand::thread_rng().gen_range(0, 5) {
|
||||||
|
planet.moons.push(RotatingParticleSystem::new(
|
||||||
|
rand::thread_rng().gen_range(1000.0, 2600.0),
|
||||||
|
600.0,
|
||||||
|
Rectangle::new((0.0, 0.0), (1.0, 1.0)),
|
||||||
|
smaller_circle,
|
||||||
|
false,
|
||||||
|
Vector::new(0.0, 0.0),
|
||||||
|
color,
|
||||||
|
1.0,
|
||||||
|
r,
|
||||||
|
rand::thread_rng().gen_range(0.05, 0.15),
|
||||||
|
rand::thread_rng().gen_range(35.0, 200.0),
|
||||||
|
0.2,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
planet
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, dt: f64) {
|
fn update(&mut self, dt: f64) {
|
||||||
|
self.particle_system.host_circle.pos = self.circle.pos;
|
||||||
self.particle_system.update(dt);
|
self.particle_system.update(dt);
|
||||||
|
for moon in &mut self.moons {
|
||||||
|
moon.particle_system.host_circle.pos = self.circle.pos;
|
||||||
|
moon.update(dt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self, window: &mut Window, transform: Transform) {
|
fn draw(&mut self, window: &mut Window, transform: Transform) {
|
||||||
self.particle_system.draw(window, transform);
|
self.particle_system.draw(window, transform);
|
||||||
window.draw_ex(&self.circle, Col(self.color), transform, 1);
|
window.draw_ex(&self.circle, Col(self.color), transform, 1);
|
||||||
|
for moon in &mut self.moons {
|
||||||
|
moon.draw(window, transform);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue