summary refs log tree commit diff stats
path: root/src/components
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/components
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/components')
-rw-r--r--src/components/animatable.cpp27
-rw-r--r--src/components/animatable.h75
-rw-r--r--src/components/orientable.h24
-rw-r--r--src/components/ponderable.h13
4 files changed, 90 insertions, 49 deletions
diff --git a/src/components/animatable.cpp b/src/components/animatable.cpp deleted file mode 100644 index fcd277c..0000000 --- a/src/components/animatable.cpp +++ /dev/null
@@ -1,27 +0,0 @@
1#include "animatable.h"
2
3AnimatableComponent::AnimatableComponent(const char* filename, int frame_width, int frame_height, int frames_across)
4 : texture(filename), frame_width(frame_width), frame_height(frame_height), frames_across(frames_across)
5{
6
7}
8
9int AnimatableComponent::getFrame() const
10{
11 return frame;
12}
13
14void AnimatableComponent::setFrame(int frame)
15{
16 this->frame = frame;
17}
18
19const Texture& AnimatableComponent::getTexture() const
20{
21 return texture;
22}
23
24Rectangle AnimatableComponent::getFrameRect() const
25{
26 return {frame_width * (frame % frames_across), frame_height * (frame / frames_across), frame_width, frame_height};
27}
diff --git a/src/components/animatable.h b/src/components/animatable.h index cf6ee54..ed0133e 100644 --- a/src/components/animatable.h +++ b/src/components/animatable.h
@@ -2,30 +2,61 @@
2#define SPRITE_RENDERABLE_H_D3AACBBF 2#define SPRITE_RENDERABLE_H_D3AACBBF
3 3
4#include "component.h" 4#include "component.h"
5#include "renderer.h" 5#include "animation.h"
6#include "direction.h" 6#include <string>
7 7
8class AnimatableComponent : public Component { 8class AnimatableComponent : public Component {
9 public: 9public:
10 AnimatableComponent(const char* filename, int frame_width, int frame_height, int frames_across); 10
11 11 AnimatableComponent(
12 int getFrame() const; 12 AnimationSet animationSet,
13 void setFrame(int frame); 13 std::string animation) :
14 14 animationSet_(std::move(animationSet)),
15 const Texture& getTexture() const; 15 animation_(std::move(animation))
16 Rectangle getFrameRect() const; 16 {
17 17 }
18 void setDirection(Direction dir) {}; 18
19 void setWalking(bool w) {}; 19 inline size_t getFrame() const
20 void setJumping(bool w) {}; 20 {
21 void setCrouching(bool w) {}; 21 return frame_;
22 22 }
23 private: 23
24 Texture texture; 24 inline void setFrame(size_t v)
25 int frame_width; 25 {
26 int frame_height; 26 frame_ = v;
27 int frames_across; 27 }
28 int frame = 0; 28
29 inline size_t getCountdown() const
30 {
31 return countdown_;
32 }
33
34 inline void setCountdown(size_t v)
35 {
36 countdown_ = v;
37 }
38
39 inline const AnimationSet& getAnimationSet() const
40 {
41 return animationSet_;
42 }
43
44 inline const Animation& getAnimation() const
45 {
46 return animationSet_.getAnimation(animation_);
47 }
48
49 inline void setAnimation(std::string animation)
50 {
51 animation_ = std::move(animation);
52 }
53
54private:
55
56 AnimationSet animationSet_;
57 std::string animation_;
58 size_t frame_ = 0;
59 size_t countdown_ = 0;
29}; 60};
30 61
31#endif /* end of include guard: SPRITE_RENDERABLE_H_D3AACBBF */ 62#endif /* end of include guard: SPRITE_RENDERABLE_H_D3AACBBF */
diff --git a/src/components/orientable.h b/src/components/orientable.h new file mode 100644 index 0000000..8f56912 --- /dev/null +++ b/src/components/orientable.h
@@ -0,0 +1,24 @@
1#ifndef ORIENTABLE_H_EDB6C4A1
2#define ORIENTABLE_H_EDB6C4A1
3
4#include "component.h"
5
6class OrientableComponent : public Component {
7public:
8
9 inline bool isFacingRight() const
10 {
11 return facingRight_;
12 }
13
14 inline void setFacingRight(bool v)
15 {
16 facingRight_ = v;
17 }
18
19private:
20
21 bool facingRight_ = false;
22};
23
24#endif /* end of include guard: ORIENTABLE_H_EDB6C4A1 */
diff --git a/src/components/ponderable.h b/src/components/ponderable.h index 80100d7..dfbf908 100644 --- a/src/components/ponderable.h +++ b/src/components/ponderable.h
@@ -6,6 +6,13 @@
6class PonderableComponent : public Component { 6class PonderableComponent : public Component {
7public: 7public:
8 8
9 enum class state {
10 grounded,
11 jumping,
12 falling,
13 dropping
14 };
15
9 inline double getVelocityX() const 16 inline double getVelocityX() const
10 { 17 {
11 return velX_; 18 return velX_;
@@ -51,12 +58,18 @@ public:
51 return state_; 58 return state_;
52 } 59 }
53 60
61 inline void setState(state arg)
62 {
63 state_ = arg;
64 }
65
54private: 66private:
55 67
56 double velX_ = 0.0; 68 double velX_ = 0.0;
57 double velY_ = 0.0; 69 double velY_ = 0.0;
58 double accelX_ = 0.0; 70 double accelX_ = 0.0;
59 double accelY_ = 0.0; 71 double accelY_ = 0.0;
72 state state_ = state::grounded;
60}; 73};
61 74
62#endif /* end of include guard: TANGIBLE_H_746DB3EE */ 75#endif /* end of include guard: TANGIBLE_H_746DB3EE */