diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-08 12:34:42 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-02-08 12:34:42 -0500 |
commit | cefe66cdbb8786dc455657376e36f0ff8785d5bc (patch) | |
tree | 7e90536fad90f2954b3834dc4959f402883c32b3 /src/animation.cpp | |
parent | cec0ed92c4035c4421d3cc2448f5423fcbb7f7d4 (diff) | |
download | therapy-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.cpp')
-rw-r--r-- | src/animation.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/animation.cpp b/src/animation.cpp new file mode 100644 index 0000000..31ba21f --- /dev/null +++ b/src/animation.cpp | |||
@@ -0,0 +1,35 @@ | |||
1 | #include "animation.h" | ||
2 | |||
3 | AnimationSet::AnimationSet( | ||
4 | Texture texture, | ||
5 | int frameWidth, | ||
6 | int frameHeight, | ||
7 | int framesAcross) : | ||
8 | texture_(std::move(texture)), | ||
9 | frameWidth_(frameWidth), | ||
10 | frameHeight_(frameHeight), | ||
11 | framesAcross_(framesAcross) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | void AnimationSet::emplaceAnimation( | ||
16 | std::string animation, | ||
17 | size_t firstFrame, | ||
18 | size_t numFrames, | ||
19 | size_t delay) | ||
20 | { | ||
21 | animations_.emplace( | ||
22 | std::piecewise_construct, | ||
23 | std::make_tuple(animation), | ||
24 | std::make_tuple(firstFrame, numFrames, delay)); | ||
25 | } | ||
26 | |||
27 | Rectangle AnimationSet::getFrameRect(int frame) const | ||
28 | { | ||
29 | return { | ||
30 | frameWidth_ * (frame % framesAcross_), | ||
31 | frameHeight_ * (frame / framesAcross_), | ||
32 | frameWidth_, | ||
33 | frameHeight_ | ||
34 | }; | ||
35 | } | ||