diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-14 19:25:23 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-14 19:25:23 -0400 |
commit | 6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b (patch) | |
tree | 0a884ddd12b4e5b0afcc9c4ecaea5ecc73605b57 /src/components.h | |
parent | d9349f10d6d1972e87aea76d502703fae128a0e5 (diff) | |
download | therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.tar.gz therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.tar.bz2 therapy-6b1dcc5df51df4a2d8b724187eb1bcdb4fd9df8b.zip |
Added sound when you hit the ground
Also split up components.cpp into files for each class, fixed a bug concerning falling off the screen when you change maps, and converted collision data into doubles.
Diffstat (limited to 'src/components.h')
-rw-r--r-- | src/components.h | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/src/components.h b/src/components.h deleted file mode 100644 index e0c4a24..0000000 --- a/src/components.h +++ /dev/null | |||
@@ -1,125 +0,0 @@ | |||
1 | #ifndef COMPONENTS_H | ||
2 | #define COMPONENTS_H | ||
3 | |||
4 | #include <utility> | ||
5 | #include <list> | ||
6 | #include "renderer.h" | ||
7 | #include "entity.h" | ||
8 | #include "game.h" | ||
9 | |||
10 | class Map; | ||
11 | |||
12 | class UserMovementComponent : public Component { | ||
13 | public: | ||
14 | void input(Game& game, Entity& entity, int key, int action); | ||
15 | void receive(Game&, Entity&, const Message& msg); | ||
16 | |||
17 | private: | ||
18 | bool holdingLeft = false; | ||
19 | bool holdingRight = false; | ||
20 | bool frozen = false; | ||
21 | }; | ||
22 | |||
23 | class PhysicsBodyComponent : public Component { | ||
24 | public: | ||
25 | void receive(Game& game, Entity& entity, const Message& msg); | ||
26 | void tick(Game& game, Entity& entity, double dt); | ||
27 | void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position); | ||
28 | |||
29 | protected: | ||
30 | std::pair<double, double> velocity; | ||
31 | std::pair<double, double> accel; | ||
32 | }; | ||
33 | |||
34 | class PlayerSpriteComponent : public Component { | ||
35 | public: | ||
36 | void render(Game& game, Entity& entity, Texture& buffer); | ||
37 | void receive(Game& game, Entity& entity, const Message& msg); | ||
38 | |||
39 | private: | ||
40 | Texture sprite {"../res/Starla.png"}; | ||
41 | int animFrame = 0; | ||
42 | bool facingLeft = false; | ||
43 | bool isMoving = false; | ||
44 | bool dying = false; | ||
45 | }; | ||
46 | |||
47 | class PlayerPhysicsComponent : public PhysicsBodyComponent { | ||
48 | public: | ||
49 | PlayerPhysicsComponent(); | ||
50 | void tick(Game& game, Entity& entity, double dt); | ||
51 | void receive(Game& game, Entity& entity, const Message& msg); | ||
52 | |||
53 | private: | ||
54 | double jump_velocity; | ||
55 | double jump_gravity; | ||
56 | double jump_gravity_short; | ||
57 | int direction = 0; | ||
58 | bool canDrop = false; | ||
59 | bool frozen = false; | ||
60 | }; | ||
61 | |||
62 | class MapRenderComponent : public Component { | ||
63 | public: | ||
64 | MapRenderComponent(const Map& map); | ||
65 | void render(Game& game, Entity& entity, Texture& buffer); | ||
66 | |||
67 | private: | ||
68 | Texture screen{GAME_WIDTH, GAME_HEIGHT}; | ||
69 | }; | ||
70 | |||
71 | class MapCollisionComponent : public Component { | ||
72 | public: | ||
73 | MapCollisionComponent(const Map& map); | ||
74 | void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position); | ||
75 | |||
76 | private: | ||
77 | enum class Direction { | ||
78 | up, left, down, right | ||
79 | }; | ||
80 | |||
81 | struct Collision { | ||
82 | enum class Type { | ||
83 | wall, | ||
84 | wrap, | ||
85 | teleport, | ||
86 | reverse, | ||
87 | platform, | ||
88 | danger | ||
89 | }; | ||
90 | |||
91 | int axis; | ||
92 | int lower; | ||
93 | int upper; | ||
94 | Type type; | ||
95 | }; | ||
96 | |||
97 | void addCollision(int axis, int lower, int upper, Direction dir, Collision::Type type); | ||
98 | bool processCollision(Game& game, Entity& collider, Collision collision, Direction dir); | ||
99 | |||
100 | std::list<Collision> left_collisions; | ||
101 | std::list<Collision> right_collisions; | ||
102 | std::list<Collision> up_collisions; | ||
103 | std::list<Collision> down_collisions; | ||
104 | const Map& map; | ||
105 | }; | ||
106 | |||
107 | class StaticImageComponent : public Component { | ||
108 | public: | ||
109 | StaticImageComponent(const char* filename); | ||
110 | void render(Game& game, Entity& entity, Texture& buffer); | ||
111 | |||
112 | private: | ||
113 | Texture sprite; | ||
114 | }; | ||
115 | |||
116 | class SimpleColliderComponent : public Component { | ||
117 | public: | ||
118 | SimpleColliderComponent(std::function<void (Game& game, Entity& collider)> callback); | ||
119 | void receive(Game& game, Entity& entity, const Message& msg); | ||
120 | |||
121 | private: | ||
122 | std::function<void (Game& game, Entity& collider)> callback; | ||
123 | }; | ||
124 | |||
125 | #endif | ||