diff options
Diffstat (limited to 'src/animation.h')
-rw-r--r-- | src/animation.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/animation.h b/src/animation.h new file mode 100644 index 0000000..58df616 --- /dev/null +++ b/src/animation.h | |||
@@ -0,0 +1,100 @@ | |||
1 | #ifndef ANIMATION_H_74EB0901 | ||
2 | #define ANIMATION_H_74EB0901 | ||
3 | |||
4 | #include "renderer/texture.h" | ||
5 | #include <string> | ||
6 | #include <map> | ||
7 | #include <stdexcept> | ||
8 | |||
9 | class Animation { | ||
10 | public: | ||
11 | |||
12 | Animation( | ||
13 | size_t firstFrame, | ||
14 | size_t numFrames, | ||
15 | size_t delay) : | ||
16 | firstFrame_(firstFrame), | ||
17 | numFrames_(numFrames), | ||
18 | delay_(delay) | ||
19 | { | ||
20 | } | ||
21 | |||
22 | inline size_t getFirstFrame() const | ||
23 | { | ||
24 | return firstFrame_; | ||
25 | } | ||
26 | |||
27 | inline size_t getNumFrames() const | ||
28 | { | ||
29 | return numFrames_; | ||
30 | } | ||
31 | |||
32 | inline size_t getDelay() const | ||
33 | { | ||
34 | return delay_; | ||
35 | } | ||
36 | |||
37 | private: | ||
38 | |||
39 | size_t firstFrame_; | ||
40 | size_t numFrames_; | ||
41 | size_t delay_; | ||
42 | }; | ||
43 | |||
44 | class AnimationSet { | ||
45 | public: | ||
46 | |||
47 | AnimationSet( | ||
48 | Texture texture, | ||
49 | int frameWidth, | ||
50 | int frameHeight, | ||
51 | int framesAcross); | ||
52 | |||
53 | void emplaceAnimation( | ||
54 | std::string animation, | ||
55 | size_t firstFrame, | ||
56 | size_t numFrames, | ||
57 | size_t delay); | ||
58 | |||
59 | inline const Animation& getAnimation(std::string animation) const | ||
60 | { | ||
61 | if (!animations_.count(animation)) | ||
62 | { | ||
63 | throw std::invalid_argument("Animation does not exist"); | ||
64 | } | ||
65 | |||
66 | return animations_.at(animation); | ||
67 | } | ||
68 | |||
69 | inline const Texture& getTexture() const | ||
70 | { | ||
71 | return texture_; | ||
72 | } | ||
73 | |||
74 | inline int getFrameWidth() const | ||
75 | { | ||
76 | return frameWidth_; | ||
77 | } | ||
78 | |||
79 | inline int getFrameHeight() const | ||
80 | { | ||
81 | return frameHeight_; | ||
82 | } | ||
83 | |||
84 | inline int getFramesAcross() const | ||
85 | { | ||
86 | return framesAcross_; | ||
87 | } | ||
88 | |||
89 | Rectangle getFrameRect(int frame) const; | ||
90 | |||
91 | private: | ||
92 | |||
93 | std::map<std::string, Animation> animations_; | ||
94 | Texture texture_; | ||
95 | int frameWidth_; | ||
96 | int frameHeight_; | ||
97 | int framesAcross_; | ||
98 | }; | ||
99 | |||
100 | #endif /* end of include guard: ANIMATION_H_74EB0901 */ | ||