From 0e0389752a0912614737e5c059b5cd4719ef9cf2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 10 Mar 2015 19:42:04 -0400 Subject: Const correctness! Also created savefile and refactored collisions a bit. --- src/components.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/components.h') 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 { class PhysicsBodyComponent : public Component { public: - void receive(Game& game, Entity& entity, Message& msg); + void receive(Game& game, Entity& entity, const Message& msg); void tick(Game& game, Entity& entity); void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair old_position); - private: + private: std::pair velocity; std::pair accel; }; @@ -30,7 +30,7 @@ class PhysicsBodyComponent : public Component { class PlayerSpriteComponent : public Component { public: void render(Game& game, Entity& entity, Texture& buffer); - void receive(Game& game, Entity& entity, Message& msg); + void receive(Game& game, Entity& entity, const Message& msg); void tick(Game& game, Entity& entity); private: @@ -44,7 +44,7 @@ class PlayerPhysicsComponent : public Component { public: PlayerPhysicsComponent(); void tick(Game& game, Entity& entity); - void receive(Game& game, Entity& entity, Message& msg); + void receive(Game& game, Entity& entity, const Message& msg); private: std::pair velocity; @@ -58,7 +58,7 @@ class PlayerPhysicsComponent : public Component { class MapRenderComponent : public Component { public: - MapRenderComponent(Map& map); + MapRenderComponent(const Map& map); void render(Game& game, Entity& entity, Texture& buffer); private: @@ -67,29 +67,30 @@ class MapRenderComponent : public Component { class MapCollisionComponent : public Component { public: - MapCollisionComponent(Map& map); + MapCollisionComponent(const Map& map); void detectCollision(Game& game, Entity& entity, Entity& collider, std::pair old_position); private: - enum direction_t { + enum class Direction { up, left, down, right }; - typedef struct { + struct Collision { int axis; int lower; int upper; int type; - } collision_t; + }; - void add_collision(int axis, int lower, int upper, direction_t dir, int type); + void addCollision(int axis, int lower, int upper, Direction dir, int type); + void processCollision(Game& game, Entity& collider, Collision collision, Direction dir); - std::list left_collisions; - std::list right_collisions; - std::list up_collisions; - std::list down_collisions; - Map* leftMap; - Map* rightMap; + std::list left_collisions; + std::list right_collisions; + std::list up_collisions; + std::list down_collisions; + const Map* leftMap; + const Map* rightMap; }; #endif -- cgit 1.4.1