bbf3731cf4
* Add margins all around the board for better aestetics. * Add room for scoring * Because the texture atlas is a 32x32 grid, we can manipulate textures as positions on that grid and only create a rectangle for that texture in the rendering code. * Avoid hardcoded values in the rendering code.
22 lines
826 B
C++
22 lines
826 B
C++
#include "PacManAnimation.hpp"
|
|
|
|
SDL_Point PacManAnimation::animationFrame(Direction direction) const {
|
|
switch (direction) {
|
|
case Direction::NONE:
|
|
return closed;
|
|
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];
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|