-
Notifications
You must be signed in to change notification settings - Fork 1
/
Entity.cpp
53 lines (46 loc) · 983 Bytes
/
Entity.cpp
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
47
48
49
50
51
52
53
#include "Entity.h"
#include "Component.h"
Entity::Entity(Vector2 iPosition)
{
position = iPosition;
}
Entity::Entity(float iX, float iY)
{
position.x = iX;
position.y = iY;
}
Entity::Entity(Entity* iEntity)
{
position = iEntity->position;
for(auto component : iEntity->components)
{
auto currentComp = component.get()->clone();
currentComp.get()->entity = this;
components.push_back(currentComp);
}
}
void Entity::start()
{
for(auto component : components)
{
component.get()->start();
}
}
void Entity::update(float deltaTime)
{
for(auto component : components)
{
component.get()->update(deltaTime);
}
}
void Entity::sendMessage(std::string iMessage)
{
for(std::shared_ptr<Component> component : components)
{
component.get()->receiveMessage(iMessage);
}
}
void Entity::addComponent(std::shared_ptr<Component> iComponent)
{
components.push_back(iComponent);
}