diff --git a/src/engine/character/mod.rs b/src/engine/character/mod.rs index 4257ffc..ff22b8e 100644 --- a/src/engine/character/mod.rs +++ b/src/engine/character/mod.rs @@ -77,6 +77,9 @@ pub struct Character { /// The timer of the character's animation. animation_timer: Option, + + /// Indicates that the player has released the jump button. + can_jump: bool, } impl Character { @@ -91,6 +94,7 @@ impl Character { jump_counter: 1, max_jump: 1, animation_timer: None, + can_jump: true, } } @@ -111,7 +115,7 @@ impl Character { /// Makes the character jump. pub fn jump(&mut self) { - if self.jump_counter > 0 { + if self.can_jump && self.jump_counter > 0 { self.jump_counter -= 1; self.speed.y = physics::JUMP_SPEED.y; } @@ -179,7 +183,15 @@ impl Updatable for Character { Event::KeyPressed { code: Key::Return, .. - } => self.jump(), + } => { + self.jump(); + self.can_jump = false; + } + , + + Event::KeyReleased { + code: Key::Return, .. + } => self.can_jump = true, _ => (), }