From 29df5f872db2a26331e7d004e1544a7cfed217e2 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Thu, 4 Oct 2018 10:19:40 +0200 Subject: [PATCH] Character unable to jump when falling off an edge --- src/engine/character/mod.rs | 8 ++++++++ src/engine/scene/mod.rs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/engine/character/mod.rs b/src/engine/character/mod.rs index 03f952c..4257ffc 100644 --- a/src/engine/character/mod.rs +++ b/src/engine/character/mod.rs @@ -81,6 +81,7 @@ pub struct Character { impl Character { + /// Creates a character in (0, 0). fn generic(controls: Option) -> Character { Character { position: Vector2::new(0.0, 0.0), @@ -121,6 +122,13 @@ impl Character { self.jump_counter = self.max_jump; } + /// Make the player fall. + pub fn fall_off(&mut self) { + if self.jump_counter == self.max_jump { + self.jump_counter -= 1; + } + } + } impl Updatable for Character { diff --git a/src/engine/scene/mod.rs b/src/engine/scene/mod.rs index c1aa726..ea4253a 100644 --- a/src/engine/scene/mod.rs +++ b/src/engine/scene/mod.rs @@ -43,6 +43,8 @@ impl Scene { c.position.y = height; c.speed.y = 0.0; c.ground_collision(); + } else { + c.fall_off(); } } }