summary refs log tree commit diff stats
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/animatable.cpp27
-rw-r--r--src/components/animatable.h (renamed from src/components/sprite_renderable.h)10
-rw-r--r--src/components/controllable.cpp71
-rw-r--r--src/components/controllable.h36
-rw-r--r--src/components/droppable.cpp11
-rw-r--r--src/components/droppable.h15
-rw-r--r--src/components/ponderable.cpp41
-rw-r--r--src/components/ponderable.h24
-rw-r--r--src/components/sprite_renderable.cpp27
9 files changed, 233 insertions, 29 deletions
diff --git a/src/components/animatable.cpp b/src/components/animatable.cpp new file mode 100644 index 0000000..fcd277c --- /dev/null +++ b/src/components/animatable.cpp
@@ -0,0 +1,27 @@
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/sprite_renderable.h b/src/components/animatable.h index b4465c3..cf6ee54 100644 --- a/src/components/sprite_renderable.h +++ b/src/components/animatable.h
@@ -3,10 +3,11 @@
3 3
4#include "component.h" 4#include "component.h"
5#include "renderer.h" 5#include "renderer.h"
6#include "direction.h"
6 7
7class SpriteRenderableComponent : public Component { 8class AnimatableComponent : public Component {
8 public: 9 public:
9 SpriteRenderableComponent(const char* filename, int frame_width, int frame_height, int frames_across); 10 AnimatableComponent(const char* filename, int frame_width, int frame_height, int frames_across);
10 11
11 int getFrame() const; 12 int getFrame() const;
12 void setFrame(int frame); 13 void setFrame(int frame);
@@ -14,6 +15,11 @@ class SpriteRenderableComponent : public Component {
14 const Texture& getTexture() const; 15 const Texture& getTexture() const;
15 Rectangle getFrameRect() const; 16 Rectangle getFrameRect() const;
16 17
18 void setDirection(Direction dir) {};
19 void setWalking(bool w) {};
20 void setJumping(bool w) {};
21 void setCrouching(bool w) {};
22
17 private: 23 private:
18 Texture texture; 24 Texture texture;
19 int frame_width; 25 int frame_width;
diff --git a/src/components/controllable.cpp b/src/components/controllable.cpp new file mode 100644 index 0000000..a4d45f2 --- /dev/null +++ b/src/components/controllable.cpp
@@ -0,0 +1,71 @@
1#include "controllable.h"
2
3int ControllableComponent::getLeftKey() const
4{
5 return leftKey;
6}
7
8void ControllableComponent::setLeftKey(int k)
9{
10 leftKey = k;
11}
12
13int ControllableComponent::getRightKey() const
14{
15 return rightKey;
16}
17
18void ControllableComponent::setRightKey(int k)
19{
20 rightKey = k;
21}
22
23int ControllableComponent::getJumpKey() const
24{
25 return jumpKey;
26}
27
28void ControllableComponent::setJumpKey(int k)
29{
30 jumpKey = k;
31}
32
33int ControllableComponent::getDropKey() const
34{
35 return dropKey;
36}
37
38void ControllableComponent::setDropKey(int k)
39{
40 dropKey = k;
41}
42
43bool ControllableComponent::isFrozen() const
44{
45 return frozen;
46}
47
48void ControllableComponent::setFrozen(bool f)
49{
50 frozen = f;
51}
52
53bool ControllableComponent::isHoldingLeft() const
54{
55 return holdingLeft;
56}
57
58void ControllableComponent::setHoldingLeft(bool f)
59{
60 holdingLeft = f;
61}
62
63bool ControllableComponent::isHoldingRight() const
64{
65 return holdingRight;
66}
67
68void ControllableComponent::setHoldingRight(bool f)
69{
70 holdingRight = f;
71}
diff --git a/src/components/controllable.h b/src/components/controllable.h new file mode 100644 index 0000000..317d68d --- /dev/null +++ b/src/components/controllable.h
@@ -0,0 +1,36 @@
1#ifndef CONTROLLABLE_H_4E0B85B4
2#define CONTROLLABLE_H_4E0B85B4
3
4#include "component.h"
5#include "renderer.h"
6
7class ControllableComponent : public Component {
8 public:
9 int getLeftKey() const;
10 void setLeftKey(int k);
11 int getRightKey() const;
12 void setRightKey(int k);
13 int getJumpKey() const;
14 void setJumpKey(int k);
15 int getDropKey() const;
16 void setDropKey(int k);
17
18 bool isFrozen() const;
19 void setFrozen(bool f);
20 bool isHoldingLeft() const;
21 void setHoldingLeft(bool f);
22 bool isHoldingRight() const;
23 void setHoldingRight(bool f);
24
25 private:
26 int leftKey = GLFW_KEY_LEFT;
27 int rightKey = GLFW_KEY_RIGHT;
28 int jumpKey = GLFW_KEY_UP;
29 int dropKey = GLFW_KEY_DOWN;
30
31 bool frozen = false;
32 bool holdingLeft = false;
33 bool holdingRight = false;
34};
35
36#endif /* end of include guard: CONTROLLABLE_H_4E0B85B4 */
diff --git a/src/components/droppable.cpp b/src/components/droppable.cpp new file mode 100644 index 0000000..534fd9a --- /dev/null +++ b/src/components/droppable.cpp
@@ -0,0 +1,11 @@
1#include "droppable.h"
2
3void DroppableComponent::setDroppable(bool can)
4{
5 droppable = can;
6}
7
8bool DroppableComponent::isDroppable() const
9{
10 return droppable;
11}
diff --git a/src/components/droppable.h b/src/components/droppable.h new file mode 100644 index 0000000..1f5608b --- /dev/null +++ b/src/components/droppable.h
@@ -0,0 +1,15 @@
1#ifndef DROPPABLE_H_5DB254EF
2#define DROPPABLE_H_5DB254EF
3
4#include "component.h"
5
6class DroppableComponent : public Component {
7 public:
8 void setDroppable(bool can);
9 bool isDroppable() const;
10
11 private:
12 bool droppable = false;
13};
14
15#endif /* end of include guard: DROPPABLE_H_5DB254EF */
diff --git a/src/components/ponderable.cpp b/src/components/ponderable.cpp new file mode 100644 index 0000000..2cfa6a6 --- /dev/null +++ b/src/components/ponderable.cpp
@@ -0,0 +1,41 @@
1#include "ponderable.h"
2
3double PonderableComponent::getVelocityX() const
4{
5 return velocityX;
6}
7
8void PonderableComponent::setVelocityX(double v)
9{
10 velocityX = v;
11}
12
13double PonderableComponent::getVelocityY() const
14{
15 return velocityY;
16}
17
18void PonderableComponent::setVelocityY(double v)
19{
20 velocityY = v;
21}
22
23double PonderableComponent::getAccelX() const
24{
25 return accelX;
26}
27
28void PonderableComponent::setAccelX(double v)
29{
30 accelX = v;
31}
32
33double PonderableComponent::getAccelY() const
34{
35 return accelY;
36}
37
38void PonderableComponent::setAccelY(double v)
39{
40 accelY = v;
41}
diff --git a/src/components/ponderable.h b/src/components/ponderable.h new file mode 100644 index 0000000..5aab4b3 --- /dev/null +++ b/src/components/ponderable.h
@@ -0,0 +1,24 @@
1#ifndef TANGIBLE_H_746DB3EE
2#define TANGIBLE_H_746DB3EE
3
4#include "component.h"
5
6class PonderableComponent : public Component {
7 public:
8 double getVelocityX() const;
9 void setVelocityX(double v);
10 double getVelocityY() const;
11 void setVelocityY(double v);
12 double getAccelX() const;
13 void setAccelX(double v);
14 double getAccelY() const;
15 void setAccelY(double v);
16
17 private:
18 double velocityX = 0.0;
19 double velocityY = 0.0;
20 double accelX = 0.0;
21 double accelY = 0.0;
22};
23
24#endif /* end of include guard: TANGIBLE_H_746DB3EE */
diff --git a/src/components/sprite_renderable.cpp b/src/components/sprite_renderable.cpp deleted file mode 100644 index 4c61111..0000000 --- a/src/components/sprite_renderable.cpp +++ /dev/null
@@ -1,27 +0,0 @@
1#include "sprite_renderable.h"
2
3SpriteRenderableComponent::SpriteRenderableComponent(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 SpriteRenderableComponent::getFrame() const
10{
11 return frame;
12}
13
14void SpriteRenderableComponent::setFrame(int frame)
15{
16 this->frame = frame;
17}
18
19const Texture& SpriteRenderableComponent::getTexture() const
20{
21 return texture;
22}
23
24Rectangle SpriteRenderableComponent::getFrameRect() const
25{
26 return {frame_width * (frame % frames_across), frame_height * (frame / frames_across), frame_width, frame_height};
27}