diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-03 01:35:58 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-03 01:35:58 -0500 |
| commit | be09120d1d044b476ef8b516efbdb526f20d9e2d (patch) | |
| tree | f935389835d5f94a9cd3bb2059cf55174c9aad69 /src/sprite.h | |
| parent | 24918837c3ff9026d228657d14852c9cf39a5644 (diff) | |
| download | tanetane-be09120d1d044b476ef8b516efbdb526f20d9e2d.tar.gz tanetane-be09120d1d044b476ef8b516efbdb526f20d9e2d.tar.bz2 tanetane-be09120d1d044b476ef8b516efbdb526f20d9e2d.zip | |
Added animation system
Diffstat (limited to 'src/sprite.h')
| -rw-r--r-- | src/sprite.h | 46 |
1 files changed, 13 insertions, 33 deletions
| diff --git a/src/sprite.h b/src/sprite.h index dc26fad..e842192 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
| @@ -17,39 +17,19 @@ struct SpriteFrame { | |||
| 17 | class Sprite { | 17 | class Sprite { |
| 18 | public: | 18 | public: |
| 19 | 19 | ||
| 20 | Sprite(std::string_view filename, Renderer& renderer); | 20 | // Transform |
| 21 | 21 | vec2i loc { 0, 0 }; | |
| 22 | int getTextureId() const { | 22 | |
| 23 | return textureId_; | 23 | // Animation |
| 24 | } | 24 | bool isAnimated = false; |
| 25 | 25 | int textureId; | |
| 26 | const vec2i& loc() const { return loc_; } | 26 | Direction dir = Direction::down; |
| 27 | 27 | std::string animationName; | |
| 28 | vec2i& loc() { return loc_; } | 28 | int animationId = 0; |
| 29 | 29 | int animationFrame = 0; | |
| 30 | const SpriteFrame& getFrame() const { return frames_.at(animations_[curAnim_][curFrame_]); } | 30 | std::vector<SpriteFrame> frames; |
| 31 | 31 | std::vector<std::vector<int>> animations; | |
| 32 | void setDirection(Direction dir); | 32 | std::map<std::string, std::map<Direction, int>> nameDirToAnim; |
| 33 | |||
| 34 | Direction getDirection() const { return curDir_; } | ||
| 35 | |||
| 36 | void setState(std::string state); | ||
| 37 | |||
| 38 | void tickAnim(); | ||
| 39 | |||
| 40 | private: | ||
| 41 | |||
| 42 | void updateAnimation(); | ||
| 43 | |||
| 44 | int textureId_; | ||
| 45 | vec2i loc_ { 0, 0 }; | ||
| 46 | Direction curDir_ = Direction::down; | ||
| 47 | std::string state_; | ||
| 48 | int curAnim_ = 0; | ||
| 49 | int curFrame_ = 0; | ||
| 50 | std::vector<SpriteFrame> frames_; | ||
| 51 | std::vector<std::vector<int>> animations_; | ||
| 52 | std::map<std::string, std::map<Direction, int>> stateDirToAnim_; | ||
| 53 | }; | 33 | }; |
| 54 | 34 | ||
| 55 | #endif /* end of include guard: SPRITE_H_70503825 */ | 35 | #endif /* end of include guard: SPRITE_H_70503825 */ |
