summary refs log tree commit diff stats
path: root/src/components.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components.h')
-rw-r--r--src/components.h33
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
19class PhysicsBodyComponent : public Component { 19class 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 {
30class PlayerSpriteComponent : public Component { 30class 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
59class MapRenderComponent : public Component { 59class 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
68class MapCollisionComponent : public Component { 68class 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