diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-12 12:09:58 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2022-03-12 12:09:58 -0500 |
commit | be9ccb73bc20b03f62c77f5d529602a10ef4eda9 (patch) | |
tree | 6f88a9b780a75e52b2f04b6f61167f4ef46590a7 /src/animation.h | |
parent | c1a88a064a0cddbc1df2e716ef2102d22bbf681b (diff) | |
download | ether-be9ccb73bc20b03f62c77f5d529602a10ef4eda9.tar.gz ether-be9ccb73bc20b03f62c77f5d529602a10ef4eda9.tar.bz2 ether-be9ccb73bc20b03f62c77f5d529602a10ef4eda9.zip |
player has a sprite now thanks to world of solaria
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 */ | ||