diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-01-30 13:01:01 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-01-30 13:01:01 -0500 |
commit | f3166702d7dd30312b5a401f52941aad43ac51c3 (patch) | |
tree | 08f15a0fde9ee7be08c9b4fe510dfa6ed04d4a78 /src/sprite.h | |
parent | 763bd80603dbace9f14c25309159ed07ec6e9a93 (diff) | |
download | tanetane-f3166702d7dd30312b5a401f52941aad43ac51c3.tar.gz tanetane-f3166702d7dd30312b5a401f52941aad43ac51c3.tar.bz2 tanetane-f3166702d7dd30312b5a401f52941aad43ac51c3.zip |
Added standing/walking animations
Diffstat (limited to 'src/sprite.h')
-rw-r--r-- | src/sprite.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/sprite.h b/src/sprite.h index 1f917d9..5e8003b 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
@@ -1,14 +1,17 @@ | |||
1 | #ifndef SPRITE_H_70503825 | 1 | #ifndef SPRITE_H_70503825 |
2 | #define SPRITE_H_70503825 | 2 | #define SPRITE_H_70503825 |
3 | 3 | ||
4 | #include <map> | ||
4 | #include <string_view> | 5 | #include <string_view> |
6 | #include <vector> | ||
7 | #include "direction.h" | ||
5 | #include "renderer.h" | 8 | #include "renderer.h" |
6 | #include "vector.h" | 9 | #include "vector.h" |
7 | 10 | ||
8 | class Sprite { | 11 | class Sprite { |
9 | public: | 12 | public: |
10 | 13 | ||
11 | Sprite(std::string_view filename, Renderer& renderer, int width, int height); | 14 | Sprite(std::string_view filename, Renderer& renderer); |
12 | 15 | ||
13 | int getTextureId() const { | 16 | int getTextureId() const { |
14 | return textureId_; | 17 | return textureId_; |
@@ -22,11 +25,30 @@ public: | |||
22 | 25 | ||
23 | vec2i& size() { return size_; } | 26 | vec2i& size() { return size_; } |
24 | 27 | ||
28 | int getFrame() const { return animations_[curAnim_][curFrame_]; } | ||
29 | |||
30 | void setDirection(Direction dir); | ||
31 | |||
32 | Direction getDirection() const { return curDir_; } | ||
33 | |||
34 | void setWalking(bool walking); | ||
35 | |||
36 | void tickAnim(); | ||
37 | |||
25 | private: | 38 | private: |
26 | 39 | ||
40 | void updateAnimation(); | ||
41 | |||
27 | int textureId_; | 42 | int textureId_; |
28 | vec2i loc_ { 0, 0 }; | 43 | vec2i loc_ { 0, 0 }; |
29 | vec2i size_; | 44 | vec2i size_; |
45 | Direction curDir_ = Direction::down; | ||
46 | bool isWalking_ = false; | ||
47 | int curAnim_ = 0; | ||
48 | int curFrame_ = 0; | ||
49 | std::vector<std::vector<int>> animations_; | ||
50 | std::map<Direction, int> stillAnims_; | ||
51 | std::map<Direction, int> walkingAnims_; | ||
30 | }; | 52 | }; |
31 | 53 | ||
32 | #endif /* end of include guard: SPRITE_H_70503825 */ | 54 | #endif /* end of include guard: SPRITE_H_70503825 */ |