summary refs log tree commit diff stats
path: root/src/sprite.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2021-01-31 12:08:02 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2021-01-31 12:08:02 -0500
commit908f792db6fdc04fde4b48e8873767edd5d59cea (patch)
treee1ec1659bfe9d7389d1dbc52aaa7045fdb652279 /src/sprite.h
parentf648c6776e0a1c5e1e3f6fcf9c81fefcb67a0c3e (diff)
downloadtanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.gz
tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.tar.bz2
tanetane-908f792db6fdc04fde4b48e8873767edd5d59cea.zip
Made use of new sprite sheet data!
Diffstat (limited to 'src/sprite.h')
-rw-r--r--src/sprite.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/sprite.h b/src/sprite.h index 82ea90c..dc26fad 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -8,6 +8,12 @@
8#include "renderer.h" 8#include "renderer.h"
9#include "vector.h" 9#include "vector.h"
10 10
11struct SpriteFrame {
12 SDL_Rect srcRect;
13 vec2i center;
14 vec2i size;
15};
16
11class Sprite { 17class Sprite {
12public: 18public:
13 19
@@ -21,11 +27,7 @@ public:
21 27
22 vec2i& loc() { return loc_; } 28 vec2i& loc() { return loc_; }
23 29
24 const vec2i& size() const { return size_; } 30 const SpriteFrame& getFrame() const { return frames_.at(animations_[curAnim_][curFrame_]); }
25
26 vec2i& size() { return size_; }
27
28 int getFrame() const { return animations_[curAnim_][curFrame_]; }
29 31
30 void setDirection(Direction dir); 32 void setDirection(Direction dir);
31 33
@@ -41,11 +43,11 @@ private:
41 43
42 int textureId_; 44 int textureId_;
43 vec2i loc_ { 0, 0 }; 45 vec2i loc_ { 0, 0 };
44 vec2i size_;
45 Direction curDir_ = Direction::down; 46 Direction curDir_ = Direction::down;
46 std::string state_; 47 std::string state_;
47 int curAnim_ = 0; 48 int curAnim_ = 0;
48 int curFrame_ = 0; 49 int curFrame_ = 0;
50 std::vector<SpriteFrame> frames_;
49 std::vector<std::vector<int>> animations_; 51 std::vector<std::vector<int>> animations_;
50 std::map<std::string, std::map<Direction, int>> stateDirToAnim_; 52 std::map<std::string, std::map<Direction, int>> stateDirToAnim_;
51}; 53};