Holding jump dont make you jump again

This commit is contained in:
Thomas Forgione 2018-10-04 21:47:29 +02:00
parent 4a08afee59
commit 9b2f8113f3
1 changed files with 14 additions and 2 deletions

View File

@ -77,6 +77,9 @@ pub struct Character {
/// The timer of the character's animation.
animation_timer: Option<Instant>,
/// 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,
_ => (),
}