-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameObject.cpp
More file actions
99 lines (82 loc) · 1.74 KB
/
gameObject.cpp
File metadata and controls
99 lines (82 loc) · 1.74 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "gameObject.h"
#include "spriteWrapper.h"
int GameObject::nextID = 1;
GameObject::GameObject()
{
this->gameID = nextID++;
this->isQueuedForRemoval = false;
this->transform = new Transform(this);
// this->transform gets deleted via this->components in the dtor
this->addComponent(this->transform);
}
GameObject::~GameObject()
{
std::cout << "DELETING: " << this->getID() << "\n";
for (const auto& pair : this->components)
{
std::cout << "DELEETING COMPONENT: " << pair.second->componentType << "\n";
delete pair.second;
}
}
void GameObject::awake()
{
for (const auto& pair : this->components)
{
pair.second->awake();
}
}
void GameObject::start()
{
for (const auto& pair : this->components)
{
pair.second->start();
}
}
void GameObject::earlyUpdate()
{
for (const auto& pair : this->components)
{
pair.second->earlyUpdate();
}
}
void GameObject::update()
{
for (const auto& pair : this->components)
{
pair.second->update();
}
}
void GameObject::lateUpdate()
{
for (const auto& pair : this->components)
{
pair.second->lateUpdate();
}
}
void GameObject::render(sf::RenderWindow* window)
{
if (this->hasComponent(ComponentType::T_Sprite))
{
this->getComponent(ComponentType::T_Sprite)->render(window);
}
}
void GameObject::addComponent(Component* component)
{
this->components[component->componentType] = component;
}
void GameObject::removeComponent(ComponentType componentType)
{
this->components.erase(componentType);
}
Component* GameObject::getComponent(ComponentType componentType)
{
return this->components[componentType];
}
bool GameObject::hasComponent(ComponentType componentType)
{
return this->components.count(componentType) != 0;
}
void GameObject::queueForRemoval()
{
this->isQueuedForRemoval = true;
}