diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-06-18 12:14:05 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-06-18 12:14:05 -0400 |
commit | 55c8a14a7e2b2dadf0def3e09f970818164366f5 (patch) | |
tree | e05795e83aa61dc5b951a70328b8499d3c583ea6 /src/components | |
parent | 879c2c04d9c3879f871cfe79f9b25fd23c5184b4 (diff) | |
download | therapy-55c8a14a7e2b2dadf0def3e09f970818164366f5.tar.gz therapy-55c8a14a7e2b2dadf0def3e09f970818164366f5.tar.bz2 therapy-55c8a14a7e2b2dadf0def3e09f970818164366f5.zip |
Now displaying player character
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/sprite_renderable.cpp | 27 | ||||
-rw-r--r-- | src/components/sprite_renderable.h | 25 | ||||
-rw-r--r-- | src/components/transformable.cpp | 47 | ||||
-rw-r--r-- | src/components/transformable.h | 27 |
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 | |||
3 | SpriteRenderableComponent::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 | |||
9 | int SpriteRenderableComponent::getFrame() const | ||
10 | { | ||
11 | return frame; | ||
12 | } | ||
13 | |||
14 | void SpriteRenderableComponent::setFrame(int frame) | ||
15 | { | ||
16 | this->frame = frame; | ||
17 | } | ||
18 | |||
19 | const Texture& SpriteRenderableComponent::getTexture() const | ||
20 | { | ||
21 | return texture; | ||
22 | } | ||
23 | |||
24 | Rectangle 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 | |||
7 | class 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 | |||
3 | TransformableComponent::TransformableComponent(double x, double y, int w, int h) | ||
4 | : x(x), y(y), w(w), h(h) | ||
5 | { | ||
6 | |||
7 | } | ||
8 | |||
9 | double TransformableComponent::getX() const | ||
10 | { | ||
11 | return x; | ||
12 | } | ||
13 | |||
14 | double TransformableComponent::getY() const | ||
15 | { | ||
16 | return y; | ||
17 | } | ||
18 | |||
19 | int TransformableComponent::getW() const | ||
20 | { | ||
21 | return w; | ||
22 | } | ||
23 | |||
24 | int TransformableComponent::getH() const | ||
25 | { | ||
26 | return h; | ||
27 | } | ||
28 | |||
29 | void TransformableComponent::setX(double v) | ||
30 | { | ||
31 | x = v; | ||
32 | } | ||
33 | |||
34 | void TransformableComponent::setY(double v) | ||
35 | { | ||
36 | y = v; | ||
37 | } | ||
38 | |||
39 | void TransformableComponent::setW(int v) | ||
40 | { | ||
41 | w = v; | ||
42 | } | ||
43 | |||
44 | void 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 | |||
6 | class 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 */ | ||