diff options
Diffstat (limited to 'src/entity.h')
-rw-r--r-- | src/entity.h | 81 |
1 files changed, 34 insertions, 47 deletions
diff --git a/src/entity.h b/src/entity.h index 5a37147..803a9b8 100644 --- a/src/entity.h +++ b/src/entity.h | |||
@@ -3,42 +3,45 @@ | |||
3 | 3 | ||
4 | class Entity; | 4 | class Entity; |
5 | class Component; | 5 | class Component; |
6 | class Locatable; | ||
7 | class Collidable; | ||
8 | 6 | ||
9 | #include <list> | 7 | #include <list> |
10 | #include "renderer.h" | 8 | #include "renderer.h" |
11 | #include "world.h" | 9 | #include "game.h" |
12 | 10 | ||
13 | enum message_type { | 11 | class Message { |
14 | CM_WALK_LEFT, | 12 | public: |
15 | CM_WALK_RIGHT, | 13 | enum class Type { |
16 | CM_STOP_WALKING, | 14 | walkLeft, |
17 | CM_COLLISION, | 15 | walkRight, |
18 | CM_JUMP, | 16 | stopWalking, |
19 | CM_STOP_JUMP, | 17 | stopMovingHorizontally, |
20 | CM_DROP, | 18 | stopMovingVertically, |
21 | CM_CAN_DROP, | 19 | collision, |
22 | CM_CANT_DROP | 20 | jump, |
21 | stopJump, | ||
22 | drop, | ||
23 | canDrop, | ||
24 | cantDrop | ||
25 | }; | ||
26 | |||
27 | Message(Type type) : type(type) {} | ||
28 | |||
29 | Type type; | ||
30 | Entity* collisionEntity; | ||
31 | int dropAxis; | ||
23 | }; | 32 | }; |
24 | 33 | ||
25 | typedef struct { | ||
26 | message_type type; | ||
27 | Entity* collisionEntity; | ||
28 | int dropAxis; | ||
29 | } message_t; | ||
30 | |||
31 | class Entity { | 34 | class Entity { |
32 | public: | 35 | public: |
33 | Entity(World* world) : world(world) {} | ||
34 | ~Entity() {}; | ||
35 | void addComponent(std::shared_ptr<Component> c); | 36 | void addComponent(std::shared_ptr<Component> c); |
36 | void send(message_t msg); | 37 | void send(Game& game, Message& msg); |
37 | void tick(); | 38 | void tick(Game& game); |
38 | void input(int key, int action); | 39 | void input(Game& game, int key, int action); |
39 | void render(Texture* buffer); | 40 | void render(Game& game, Texture& buffer); |
41 | void detectCollision(Game& game, Entity& collider, std::pair<double, double> old_position); | ||
40 | 42 | ||
41 | World* world; | 43 | std::pair<double, double> position; |
44 | std::pair<int, int> size; | ||
42 | 45 | ||
43 | private: | 46 | private: |
44 | std::list<std::shared_ptr<Component>> components; | 47 | std::list<std::shared_ptr<Component>> components; |
@@ -46,27 +49,11 @@ class Entity { | |||
46 | 49 | ||
47 | class Component { | 50 | class Component { |
48 | public: | 51 | public: |
49 | Component(Entity& entity) : entity(entity) {} | 52 | virtual void receive(Game&, Entity&, Message&) {} |
50 | virtual ~Component() {}; | 53 | virtual void render(Game&, Entity&, Texture&) {} |
51 | virtual void receive(message_t msg) {(void)msg;} | 54 | virtual void tick(Game&, Entity&) {} |
52 | virtual void render(Texture* tex) {(void)tex;} | 55 | virtual void input(Game&, Entity&, int, int) {} |
53 | virtual void tick() {} | 56 | virtual void detectCollision(Game&, Entity&, Entity&, std::pair<double, double>) {} |
54 | virtual void input(int key, int action) {(void)key; (void)action;} | ||
55 | |||
56 | Entity& entity; | ||
57 | }; | ||
58 | |||
59 | class Locatable { | ||
60 | public: | ||
61 | std::pair<double, double> position; | ||
62 | std::pair<int, int> size; | ||
63 | std::pair<double, double> velocity; | ||
64 | std::pair<double, double> accel; | ||
65 | }; | ||
66 | |||
67 | class Collidable { | ||
68 | public: | ||
69 | virtual void detectCollision(Entity& player, Locatable& physics, std::pair<double, double> old_position) = 0; | ||
70 | }; | 57 | }; |
71 | 58 | ||
72 | #endif | 59 | #endif |