diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-10 19:42:04 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-10 19:42:04 -0400 |
| commit | 0e0389752a0912614737e5c059b5cd4719ef9cf2 (patch) | |
| tree | fc39e676bd819ee973f27fc40150a7874d2f8503 /src/components.h | |
| parent | 7f0e8c7ef70c62814c274f110367db92f01cbb26 (diff) | |
| download | therapy-0e0389752a0912614737e5c059b5cd4719ef9cf2.tar.gz therapy-0e0389752a0912614737e5c059b5cd4719ef9cf2.tar.bz2 therapy-0e0389752a0912614737e5c059b5cd4719ef9cf2.zip | |
Const correctness!
Also created savefile and refactored collisions a bit.
Diffstat (limited to 'src/components.h')
| -rw-r--r-- | src/components.h | 33 |
1 files changed, 17 insertions, 16 deletions
| diff --git a/src/components.h b/src/components.h index f9b6e1e..985025c 100644 --- a/src/components.h +++ b/src/components.h | |||
| @@ -18,11 +18,11 @@ class UserMovementComponent : public Component { | |||
| 18 | 18 | ||
| 19 | class PhysicsBodyComponent : public Component { | 19 | class PhysicsBodyComponent : public Component { |
| 20 | public: | 20 | public: |
| 21 | void receive(Game& game, Entity& entity, Message& msg); | 21 | void receive(Game& game, Entity& entity, const Message& msg); |
| 22 | void tick(Game& game, Entity& entity); | 22 | void tick(Game& game, Entity& entity); |
| 23 | void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position); | 23 | void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position); |
| 24 | 24 | ||
| 25 | private: | 25 | private: |
| 26 | std::pair<double, double> velocity; | 26 | std::pair<double, double> velocity; |
| 27 | std::pair<double, double> accel; | 27 | std::pair<double, double> accel; |
| 28 | }; | 28 | }; |
| @@ -30,7 +30,7 @@ class PhysicsBodyComponent : public Component { | |||
| 30 | class PlayerSpriteComponent : public Component { | 30 | class PlayerSpriteComponent : public Component { |
| 31 | public: | 31 | public: |
| 32 | void render(Game& game, Entity& entity, Texture& buffer); | 32 | void render(Game& game, Entity& entity, Texture& buffer); |
| 33 | void receive(Game& game, Entity& entity, Message& msg); | 33 | void receive(Game& game, Entity& entity, const Message& msg); |
| 34 | void tick(Game& game, Entity& entity); | 34 | void tick(Game& game, Entity& entity); |
| 35 | 35 | ||
| 36 | private: | 36 | private: |
| @@ -44,7 +44,7 @@ class PlayerPhysicsComponent : public Component { | |||
| 44 | public: | 44 | public: |
| 45 | PlayerPhysicsComponent(); | 45 | PlayerPhysicsComponent(); |
| 46 | void tick(Game& game, Entity& entity); | 46 | void tick(Game& game, Entity& entity); |
| 47 | void receive(Game& game, Entity& entity, Message& msg); | 47 | void receive(Game& game, Entity& entity, const Message& msg); |
| 48 | 48 | ||
| 49 | private: | 49 | private: |
| 50 | std::pair<double, double> velocity; | 50 | std::pair<double, double> velocity; |
| @@ -58,7 +58,7 @@ class PlayerPhysicsComponent : public Component { | |||
| 58 | 58 | ||
| 59 | class MapRenderComponent : public Component { | 59 | class MapRenderComponent : public Component { |
| 60 | public: | 60 | public: |
| 61 | MapRenderComponent(Map& map); | 61 | MapRenderComponent(const Map& map); |
| 62 | void render(Game& game, Entity& entity, Texture& buffer); | 62 | void render(Game& game, Entity& entity, Texture& buffer); |
| 63 | 63 | ||
| 64 | private: | 64 | private: |
| @@ -67,29 +67,30 @@ class MapRenderComponent : public Component { | |||
| 67 | 67 | ||
| 68 | class MapCollisionComponent : public Component { | 68 | class MapCollisionComponent : public Component { |
| 69 | public: | 69 | public: |
| 70 | MapCollisionComponent(Map& map); | 70 | MapCollisionComponent(const Map& map); |
| 71 | void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position); | 71 | void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair<double, double> old_position); |
| 72 | 72 | ||
| 73 | private: | 73 | private: |
| 74 | enum direction_t { | 74 | enum class Direction { |
| 75 | up, left, down, right | 75 | up, left, down, right |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | typedef struct { | 78 | struct Collision { |
| 79 | int axis; | 79 | int axis; |
| 80 | int lower; | 80 | int lower; |
| 81 | int upper; | 81 | int upper; |
| 82 | int type; | 82 | int type; |
| 83 | } collision_t; | 83 | }; |
| 84 | 84 | ||
| 85 | void add_collision(int axis, int lower, int upper, direction_t dir, int type); | 85 | void addCollision(int axis, int lower, int upper, Direction dir, int type); |
| 86 | void processCollision(Game& game, Entity& collider, Collision collision, Direction dir); | ||
| 86 | 87 | ||
| 87 | std::list<collision_t> left_collisions; | 88 | std::list<Collision> left_collisions; |
| 88 | std::list<collision_t> right_collisions; | 89 | std::list<Collision> right_collisions; |
| 89 | std::list<collision_t> up_collisions; | 90 | std::list<Collision> up_collisions; |
| 90 | std::list<collision_t> down_collisions; | 91 | std::list<Collision> down_collisions; |
| 91 | Map* leftMap; | 92 | const Map* leftMap; |
| 92 | Map* rightMap; | 93 | const Map* rightMap; |
| 93 | }; | 94 | }; |
| 94 | 95 | ||
| 95 | #endif | 96 | #endif |
