summary refs log tree commit diff stats
path: root/src/entity.cpp
blob: 2b6cd7fcdecfdda9df69f62cedfb21fc8fe53f00 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "entity.h"

void Entity::addComponent(std::shared_ptr<Component> c)
{
  components.push_back(c);
}

void Entity::send(Game& game, const Message& msg)
{
  for (auto component : components)
  {
    component->receive(game, *this, msg);
  }
}

void Entity::tick(Game& game, double dt)
{
  for (auto component : components)
  {
    component->tick(game, *this, dt);
  }
}

void Entity::input(Game& game, int key, int action)
{
  for (auto component : components)
  {
    component->input(game, *this, key, action);
  }
}

void Entity::render(Game& game, Texture& buffer)
{
  for (auto component : components)
  {
    component->render(game, *this, buffer);
  }
}

void Entity::detectCollision(Game& game, Entity& collider, std::pair<double, double> old_position)
{
  for (auto component : components)
  {
    component->detectCollision(game, *this, collider, old_position);
  }
}