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/sprite_renderable.cpp27
-rw-r--r--src/components/sprite_renderable.h25
-rw-r--r--src/components/transformable.cpp47
-rw-r--r--src/components/transformable.h27
4 files changed, 126 insertions, 0 deletions
diff --git a/src/components/sprite_renderable.cpp b/src/components/sprite_renderable.cpp new file mode 100644 index 0000000..4c61111 --- /dev/null +++ b/src/components/sprite_renderable.cpp
@@ -0,0 +1,27 @@
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}
diff --git a/src/components/sprite_renderable.h b/src/components/sprite_renderable.h new file mode 100644 index 0000000..b4465c3 --- /dev/null +++ b/src/components/sprite_renderable.h
@@ -0,0 +1,25 @@
1#ifndef SPRITE_RENDERABLE_H_D3AACBBF
2#define SPRITE_RENDERABLE_H_D3AACBBF
3
4#include "component.h"
5#include "renderer.h"
6
7class SpriteRenderableComponent : public Component {
8 public:
9 SpriteRenderableComponent(const char* filename, int frame_width, int frame_height, int frames_across);
10
11 int getFrame() const;
12 void setFrame(int frame);
13
14 const Texture& getTexture() const;
15 Rectangle getFrameRect() const;
16
17 private:
18 Texture texture;
19 int frame_width;
20 int frame_height;
21 int frames_across;
22 int frame = 0;
23};
24
25#endif /* end of include guard: SPRITE_RENDERABLE_H_D3AACBBF */
diff --git a/src/components/transformable.cpp b/src/components/transformable.cpp new file mode 100644 index 0000000..0d6b67e --- /dev/null +++ b/src/components/transformable.cpp
@@ -0,0 +1,47 @@
1#include "transformable.h"
2
3TransformableComponent::TransformableComponent(double x, double y, int w, int h)
4 : x(x), y(y), w(w), h(h)
5{
6
7}
8
9double TransformableComponent::getX() const
10{
11 return x;
12}
13
14double TransformableComponent::getY() const
15{
16 return y;
17}
18
19int TransformableComponent::getW() const
20{
21 return w;
22}
23
24int TransformableComponent::getH() const
25{
26 return h;
27}
28
29void TransformableComponent::setX(double v)
30{
31 x = v;
32}
33
34void TransformableComponent::setY(double v)
35{
36 y = v;
37}
38
39void TransformableComponent::setW(int v)
40{
41 w = v;
42}
43
44void TransformableComponent::setH(int v)
45{
46 h = v;
47}
diff --git a/src/components/transformable.h b/src/components/transformable.h new file mode 100644 index 0000000..87ba84d --- /dev/null +++ b/src/components/transformable.h
@@ -0,0 +1,27 @@
1#ifndef LOCATABLE_H_39E526CA
2#define LOCATABLE_H_39E526CA
3
4#include "component.h"
5
6class TransformableComponent : public Component {
7 public:
8 TransformableComponent(double x, double y, int w, int h);
9
10 double getX() const;
11 double getY() const;
12 int getW() const;
13 int getH() const;
14
15 void setX(double v);
16 void setY(double v);
17 void setW(int v);
18 void setH(int v);
19
20 private:
21 double x;
22 double y;
23 int w;
24 int h;
25};
26
27#endif /* end of include guard: LOCATABLE_H_39E526CA */