pacman/lib/PacManAnimation.cpp
Corentin Jabot c7ef086d3d Migrate from SDL to SFML
This simplifies the rendering code and remove all(!) pointers.

There is a number of unresolved issues

* Windows build ?
* position delta computation: migrating to SFML seems to have modified
the frame rate.
2021-06-22 13:17:12 +02:00

23 lines
841 B
C++

#include "PacManAnimation.hpp"
PositionInt PacManAnimation::animationFrame(Direction direction) const {
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:
return closed;
}
}
void PacManAnimation::updateAnimationPosition(std::chrono::milliseconds time_delta) {
animation_position_delta += (time_delta.count() / 100.0);
animation_position = int(animation_position + animation_position_delta) % 4;
animation_position_delta = (animation_position_delta < 1) ? animation_position_delta : (animation_position_delta - 1);
}