summary refs log tree commit diff stats
path: root/src/entity.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity.h')
-rw-r--r--src/entity.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/entity.h b/src/entity.h new file mode 100644 index 0000000..5a37147 --- /dev/null +++ b/src/entity.h
@@ -0,0 +1,72 @@
1#ifndef ENTITY_H
2#define ENTITY_H
3
4class Entity;
5class Component;
6class Locatable;
7class Collidable;
8
9#include <list>
10#include "renderer.h"
11#include "world.h"
12
13enum message_type {
14 CM_WALK_LEFT,
15 CM_WALK_RIGHT,
16 CM_STOP_WALKING,
17 CM_COLLISION,
18 CM_JUMP,
19 CM_STOP_JUMP,
20 CM_DROP,
21 CM_CAN_DROP,
22 CM_CANT_DROP
23};
24
25typedef struct {
26 message_type type;
27 Entity* collisionEntity;
28 int dropAxis;
29} message_t;
30
31class Entity {
32 public:
33 Entity(World* world) : world(world) {}
34 ~Entity() {};
35 void addComponent(std::shared_ptr<Component> c);
36 void send(message_t msg);
37 void tick();
38 void input(int key, int action);
39 void render(Texture* buffer);
40
41 World* world;
42
43 private:
44 std::list<std::shared_ptr<Component>> components;
45};
46
47class Component {
48 public:
49 Component(Entity& entity) : entity(entity) {}
50 virtual ~Component() {};
51 virtual void receive(message_t msg) {(void)msg;}
52 virtual void render(Texture* tex) {(void)tex;}
53 virtual void tick() {}
54 virtual void input(int key, int action) {(void)key; (void)action;}
55
56 Entity& entity;
57};
58
59class 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
67class Collidable {
68 public:
69 virtual void detectCollision(Entity& player, Locatable& physics, std::pair<double, double> old_position) = 0;
70};
71
72#endif