Make pacman mouth wide open while he doesn't move
This commit is contained in:
parent
57cb71e5c9
commit
42ee04203f
4 changed files with 19 additions and 7 deletions
|
@ -18,10 +18,11 @@ Position PacMan::positionInGrid() const {
|
|||
|
||||
void PacMan::update(std::chrono::milliseconds time_delta, InputState state, const Board & board) {
|
||||
setDirection(state);
|
||||
auto old = pos;
|
||||
const auto old = pos;
|
||||
updateMazePosition(time_delta, board);
|
||||
if(old != pos)
|
||||
updateAnimationPosition(time_delta);
|
||||
|
||||
const bool paused = pos == old;
|
||||
updateAnimationPosition(time_delta, paused);
|
||||
}
|
||||
|
||||
void PacMan::setDirection(const InputState & state) {
|
||||
|
@ -35,9 +36,14 @@ void PacMan::setDirection(const InputState & state) {
|
|||
desired_direction = Direction::DOWN;
|
||||
}
|
||||
|
||||
void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta) {
|
||||
void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta, bool paused) {
|
||||
if(paused) {
|
||||
pacManAnimation.pause();
|
||||
}
|
||||
else {
|
||||
pacManAnimation.updateAnimationPosition(time_delta);
|
||||
}
|
||||
}
|
||||
|
||||
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta, const Board & board) {
|
||||
float position_delta = 0.004 * time_delta.count();
|
||||
|
|
|
@ -29,7 +29,6 @@ private:
|
|||
|
||||
void setDirection(const InputState & state);
|
||||
|
||||
void updateAnimationPosition(std::chrono::milliseconds time_delta);
|
||||
|
||||
void updateAnimationPosition(std::chrono::milliseconds time_delta, bool paused);
|
||||
void updateMazePosition(std::chrono::milliseconds time_delta, const Board & board);
|
||||
};
|
||||
|
|
|
@ -21,3 +21,8 @@ void PacManAnimation::updateAnimationPosition(std::chrono::milliseconds time_del
|
|||
animation_position = int(animation_position + animation_position_delta) % 4;
|
||||
animation_position_delta = (animation_position_delta < 1) ? animation_position_delta : (animation_position_delta - 1);
|
||||
}
|
||||
|
||||
void PacManAnimation::pause() {
|
||||
animation_position = 0;
|
||||
animation_position_delta = 0;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ public:
|
|||
[[nodiscard]] PositionInt animationFrame(Direction direction) const;
|
||||
|
||||
void updateAnimationPosition(std::chrono::milliseconds time_delta);
|
||||
void pause();
|
||||
|
||||
|
||||
private:
|
||||
uint8_t animation_position = 0;
|
||||
|
|
Loading…
Reference in a new issue