diff options
Diffstat (limited to 'src/entity.cpp')
| -rw-r--r-- | src/entity.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
| diff --git a/src/entity.cpp b/src/entity.cpp index 405de24..950969e 100644 --- a/src/entity.cpp +++ b/src/entity.cpp | |||
| @@ -5,34 +5,42 @@ void Entity::addComponent(std::shared_ptr<Component> c) | |||
| 5 | components.push_back(c); | 5 | components.push_back(c); |
| 6 | } | 6 | } |
| 7 | 7 | ||
| 8 | void Entity::send(message_t msg) | 8 | void Entity::send(Game& game, Message& msg) |
| 9 | { | 9 | { |
| 10 | for (auto it = components.begin(); it != components.end(); it++) | 10 | for (auto component : components) |
| 11 | { | 11 | { |
| 12 | (*it)->receive(msg); | 12 | component->receive(game, *this, msg); |
| 13 | } | 13 | } |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | void Entity::tick() | 16 | void Entity::tick(Game& game) |
| 17 | { | 17 | { |
| 18 | for (auto it = components.begin(); it != components.end(); it++) | 18 | for (auto component : components) |
| 19 | { | 19 | { |
| 20 | (*it)->tick(); | 20 | component->tick(game, *this); |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | void Entity::input(int key, int action) | 24 | void Entity::input(Game& game, int key, int action) |
| 25 | { | 25 | { |
| 26 | for (auto it = components.begin(); it != components.end(); it++) | 26 | for (auto component : components) |
| 27 | { | 27 | { |
| 28 | (*it)->input(key, action); | 28 | component->input(game, *this, key, action); |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | void Entity::render(Texture* buffer) | 32 | void Entity::render(Game& game, Texture& buffer) |
| 33 | { | 33 | { |
| 34 | for (auto it = components.begin(); it != components.end(); it++) | 34 | for (auto component : components) |
| 35 | { | 35 | { |
| 36 | (*it)->render(buffer); | 36 | component->render(game, *this, buffer); |
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | void Entity::detectCollision(Game& game, Entity& collider, std::pair<double, double> old_position) | ||
| 41 | { | ||
| 42 | for (auto component : components) | ||
| 43 | { | ||
| 44 | component->detectCollision(game, *this, collider, old_position); | ||
| 37 | } | 45 | } |
| 38 | } | 46 | } |
