diff options
Diffstat (limited to 'src/animation.h')
| -rw-r--r-- | src/animation.h | 39 |
1 files changed, 39 insertions, 0 deletions
| diff --git a/src/animation.h b/src/animation.h new file mode 100644 index 0000000..0108c12 --- /dev/null +++ b/src/animation.h | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #ifndef ANIMATION_H_332518EB | ||
| 2 | #define ANIMATION_H_332518EB | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | #include <map> | ||
| 6 | #include <vector> | ||
| 7 | #include <string_view> | ||
| 8 | #include <SDL.h> | ||
| 9 | #include "direction.h" | ||
| 10 | #include "timer.h" | ||
| 11 | |||
| 12 | class Animation { | ||
| 13 | public: | ||
| 14 | explicit Animation(std::string_view path); | ||
| 15 | |||
| 16 | void setDirection(Direction dir); | ||
| 17 | void setAnimation(std::string_view anim); | ||
| 18 | |||
| 19 | const SDL_Rect& getRenderRect() const { | ||
| 20 | return frames_.at(animations_.at(animationId_).at(animationFrame_)); | ||
| 21 | } | ||
| 22 | |||
| 23 | void update(int dt); | ||
| 24 | |||
| 25 | private: | ||
| 26 | |||
| 27 | void updateAnim(); | ||
| 28 | |||
| 29 | std::vector<SDL_Rect> frames_; | ||
| 30 | std::vector<std::vector<int>> animations_; | ||
| 31 | std::map<std::string, std::map<Direction, int>> nameDirToAnim_; | ||
| 32 | Direction dir_ = Direction::down; | ||
| 33 | std::string animationName_ = "still"; | ||
| 34 | int animationId_ = 0; | ||
| 35 | int animationFrame_ = 0; | ||
| 36 | Timer animTimer_ = {1000/5}; | ||
| 37 | }; | ||
| 38 | |||
| 39 | #endif /* end of include guard: ANIMATION_H_332518EB */ | ||
