pacman/lib/PacManAnimation.cpp
Patricia Aas 68f63f3f66
Canvas rewrite (#6)
* Beginning rewrite

* Move all constants to canvas, wire sprite handling code

* Make Sprite a struct and reformat

* Fix warning

Co-authored-by: Corentin Jabot <corentinjabot@gmail.com>
2021-06-16 12:52:04 +02:00

23 lines
839 B
C++

#include "PacManAnimation.hpp"
SDL_Point 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);
}