summary refs log tree commit diff stats
path: root/src/animation.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-17 15:55:37 -0400
committerGitHub <noreply@github.com>2018-05-17 15:55:37 -0400
commit90aadf3844386824140a20d7fbb847bc16009a94 (patch)
tree6f83fce90e71abb22b1a8f3e09c79963b2a34d5d /src/animation.h
parentbc63fa57ced1c7329f7fdcfd168eaf7e290158bc (diff)
parent86f0106d0523825549f1e74b835688c78a10cf6c (diff)
downloadtherapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.gz
therapy-90aadf3844386824140a20d7fbb847bc16009a94.tar.bz2
therapy-90aadf3844386824140a20d7fbb847bc16009a94.zip
Merge pull request #7 from hatkirby/es-rewrite
The ECS rewrite exceeds the original branch in functionality, so it is time to merge it in.
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..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
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 */