+
+////////// WALKING /////////////////////////////////////////////////////////////
+
+struct WalkTrigger;
+
+impl Trigger for WalkTrigger {
+ fn update(&mut self, body: &Body, ctrl: &Controller, _dt: Duration) -> Option<Box<dyn State>> {
+ if body.standing_on.is_some() && (ctrl.mov.x < -0.1 || ctrl.mov.x > 0.1) {
+ Some(Box::new(WalkState))
+ } else {
+ None
+ }
+ }
+}
+
+struct WalkState;
+
+impl State for WalkState {
+ fn enter(&mut self, body: &mut Body, ctrl: &Controller, _objects: &mut Objects) {
+ if let Some(wall) = &body.standing_on {
+ if ctrl.mov.to_point().length() < 0.1 {
+ body.vel = wall.normal().into();
+ } else {
+ body.vel = ctrl.mov.to_point();
+ }
+ body.vel *= 5.0;
+ body.pos += body.vel * 0.1;
+ body.standing_on = None;
+ }
+ }
+
+ fn update(&mut self, body: &mut Body, ctrl: &Controller, _objects: &mut Objects, lvl: &Level, _dt: Duration) -> Option<Box<dyn State>> {
+ body.vel += lvl.gravity;
+ body.pos += body.vel;
+
+ match ctrl.mov.x {
+ v if v < -0.9 && body.vel.x > -5.0 => { body.vel.x -= 0.5 }
+ v if v > 0.9 && body.vel.x < 5.0 => { body.vel.x += 0.5 }
+ _ => {}