pacman/lib/PacManAnimation.cpp

40 lines
1.2 KiB
C++
Raw Normal View History

2020-11-28 12:04:14 +00:00
#include "PacManAnimation.hpp"
PositionInt PacManAnimation::animationFrame(Direction direction) const {
2020-11-28 12:04:14 +00:00
switch (direction) {
case Direction::LEFT:
return left_animation[animation_position];
case Direction::RIGHT:
return right_animation[animation_position];
case Direction::UP:
return up_animation[animation_position];
case Direction::DOWN:
return down_animation[animation_position];
case Direction::NONE:
default:
2021-06-24 11:32:52 +00:00
return Atlas::pacman_closed;
2020-11-28 12:04:14 +00:00
}
}
2021-06-28 10:42:21 +00:00
[[nodiscard]] PositionInt PacManAnimation::deathAnimationFrame(Direction direction) const {
return PositionInt{ animation_position, 1 };
}
void PacManAnimation::updateAnimationPosition(std::chrono::milliseconds time_delta, bool dead) {
if (dead && animation_position >= 11)
return;
2021-07-05 09:40:10 +00:00
animation_position_delta += (0.02) * double(time_delta.count());
2021-06-28 10:42:21 +00:00
animation_position = int(animation_position + animation_position_delta);
if (!dead)
animation_position = animation_position % 4;
2020-11-28 12:04:14 +00:00
animation_position_delta = (animation_position_delta < 1) ? animation_position_delta : (animation_position_delta - 1);
}
void PacManAnimation::pause() {
2021-06-24 11:32:52 +00:00
animation_position = 0;
animation_position_delta = 0;
}