2020-11-28 12:04:14 +00:00
|
|
|
#include "PacManAnimation.hpp"
|
|
|
|
|
2021-06-20 16:52:34 +00:00
|
|
|
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];
|
2021-06-16 10:52:04 +00:00
|
|
|
case Direction::NONE:
|
|
|
|
default:
|
2021-06-24 11:32:52 +00:00
|
|
|
return Atlas::pacman_closed;
|
2020-11-28 12:04:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PacManAnimation::updateAnimationPosition(std::chrono::milliseconds time_delta) {
|
2021-06-22 13:37:36 +00:00
|
|
|
animation_position_delta += (0.02) * float(time_delta.count());
|
2020-11-28 12:04:14 +00:00
|
|
|
animation_position = int(animation_position + animation_position_delta) % 4;
|
|
|
|
animation_position_delta = (animation_position_delta < 1) ? animation_position_delta : (animation_position_delta - 1);
|
|
|
|
}
|
2021-06-24 07:46:58 +00:00
|
|
|
|
|
|
|
void PacManAnimation::pause() {
|
2021-06-24 11:32:52 +00:00
|
|
|
animation_position = 0;
|
|
|
|
animation_position_delta = 0;
|
2021-06-24 07:46:58 +00:00
|
|
|
}
|