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) {
|
void PacMan::update(std::chrono::milliseconds time_delta, InputState state, const Board & board) {
|
||||||
setDirection(state);
|
setDirection(state);
|
||||||
auto old = pos;
|
const auto old = pos;
|
||||||
updateMazePosition(time_delta, board);
|
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) {
|
void PacMan::setDirection(const InputState & state) {
|
||||||
|
@ -35,8 +36,13 @@ void PacMan::setDirection(const InputState & state) {
|
||||||
desired_direction = Direction::DOWN;
|
desired_direction = Direction::DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta) {
|
void PacMan::updateAnimationPosition(std::chrono::milliseconds time_delta, bool paused) {
|
||||||
pacManAnimation.updateAnimationPosition(time_delta);
|
if(paused) {
|
||||||
|
pacManAnimation.pause();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pacManAnimation.updateAnimationPosition(time_delta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta, const Board & board) {
|
void PacMan::updateMazePosition(std::chrono::milliseconds time_delta, const Board & board) {
|
||||||
|
|
|
@ -29,7 +29,6 @@ private:
|
||||||
|
|
||||||
void setDirection(const InputState & state);
|
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);
|
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 = int(animation_position + animation_position_delta) % 4;
|
||||||
animation_position_delta = (animation_position_delta < 1) ? animation_position_delta : (animation_position_delta - 1);
|
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;
|
[[nodiscard]] PositionInt animationFrame(Direction direction) const;
|
||||||
|
|
||||||
void updateAnimationPosition(std::chrono::milliseconds time_delta);
|
void updateAnimationPosition(std::chrono::milliseconds time_delta);
|
||||||
|
void pause();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t animation_position = 0;
|
uint8_t animation_position = 0;
|
||||||
|
|
Loading…
Reference in a new issue