use AppState;
-use common::Point2D;
+use ActiveState;
+use common::{Point2D, Radians};
+use core::app::StateChange;
use core::controller::Controller;
use core::controller::ControllerManager;
use core::level::Level;
fn leave(&mut self) {}
- fn update(&mut self, dt: Duration) {
+ fn update(&mut self, dt: Duration) -> Option<StateChange> {
self.world.update(dt);
+ None
}
fn render(&mut self, renderer: &mut Renderer, sprites: &SpriteManager) {
self.world.render(renderer, sprites);
}
- fn handle_event(&mut self, event: Event) {
+ fn handle_event(&mut self, event: Event) -> Option<StateChange> {
match event {
+ Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
+ return Some(StateChange::Pop)
+ }
+ Event::KeyDown { keycode: Some(Keycode::Return), .. } => {
+ return Some(StateChange::Push(Box::new(ActiveState::new((800, 600)))))
+ }
Event::KeyDown { keycode: Some(Keycode::Space), .. } => {
- self.world.level.regenerate();
+ self.world.level = Level::new(self.world.level.gravity);
}
Event::KeyDown { keycode: Some(Keycode::KpPlus), .. } => {
self.world.level.increase_iteration();
}
_ => {}
}
+ None
}
}
if self.bounces == 0 {
return Dead
}
- self.vel *= -0.5;
+ self.vel *= -0.25;
+ self.pos += self.vel;
self.bounces -= 1;
use rand::distributions::{Distribution, Normal};
- let normal = Normal::new(0.5, 0.4);
+ let mut rng = rand::thread_rng();
+ let a = Radians(self.vel.to_radians().0 + Normal::new(0.0, 0.75).sample(&mut rng));
objects.push(Box::new(Boll {
- vel: self.vel * normal.sample(&mut rand::thread_rng()),
+ vel: Point2D::from(a) * Normal::new(1.0, 0.25).sample(&mut rng) * self.vel.length(),
..*self
}));
}