summary refs log tree commit diff stats
path: root/src/animation.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-02-08 12:34:42 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-02-08 12:34:42 -0500
commitcefe66cdbb8786dc455657376e36f0ff8785d5bc (patch)
tree7e90536fad90f2954b3834dc4959f402883c32b3 /src/animation.h
parentcec0ed92c4035c4421d3cc2448f5423fcbb7f7d4 (diff)
downloadtherapy-cefe66cdbb8786dc455657376e36f0ff8785d5bc.tar.gz
therapy-cefe66cdbb8786dc455657376e36f0ff8785d5bc.tar.bz2
therapy-cefe66cdbb8786dc455657376e36f0ff8785d5bc.zip
Introduced animated sprites
Also restyled a lot of the code.
Diffstat (limited to 'src/animation.h')
-rw-r--r--src/animation.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/animation.h b/src/animation.h new file mode 100644 index 0000000..50446d0 --- /dev/null +++ b/src/animation.h
@@ -0,0 +1,100 @@
1#ifndef ANIMATION_H_74EB0901
2#define ANIMATION_H_74EB0901
3
4#include "renderer.h"
5#include <string>
6#include <map>
7#include <stdexcept>
8
9class Animation {
10public:
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
37private:
38
39 size_t firstFrame_;
40 size_t numFrames_;
41 size_t delay_;
42};
43
44class AnimationSet {
45public:
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
91private:
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 */