Skip to content

Commit

Permalink
Introducing another fix to the queueing up
Browse files Browse the repository at this point in the history
  • Loading branch information
InnocentusLime committed Nov 6, 2022
1 parent 720952b commit 83835cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/moveable/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ impl<'a> MoveableQueryItem<'a> {
*self.state = MoveableState::Idle;
}

/// Returns the progress of the movement of a moveable.
/// If the moveable is idle, `None` is returned.
pub fn movement_progress(&self) -> Option<f32> {
match &*self.state {
MoveableState::Idle => None,
MoveableState::Moving { timer, .. } => Some(timer.percent()),
}
}

/// Asks the game to slide the moveable in some direction (See [MoveableState::Moving]).
///
/// Note that this won't announce to other systems that the moveable has
Expand Down
6 changes: 6 additions & 0 deletions src/player/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ pub fn player_controls(

match movement {
Some(dir) => query.for_each_mut(|m| {
// Ignore inputs, that happened too early
match m.movement_progress() {
Some(x) if x <= 0.1f32 => return,
_ => (),
}

if !player_flip(m, dir) {
queue.0 = movement;
}
Expand Down

0 comments on commit 83835cc

Please sign in to comment.