-
Notifications
You must be signed in to change notification settings - Fork 0
/
compositeentity.cpp
57 lines (49 loc) · 1.49 KB
/
compositeentity.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
54
55
56
57
#include "compositeentity.h"
CompositeEntity::CompositeEntity(Coordinate* position, std::string name)
: Entity(position, name) {}
void CompositeEntity::addChild(Entity* e) {
std::vector<Entity*>::iterator it;
for (it = children.begin(); it != children.end(); it++) {
if (*it == e) {
return;
}
}
children.push_back(e);
}
void CompositeEntity::removeChild(Entity* e) {
std::vector<Entity*>::iterator it;
for (it = children.begin(); it != children.end(); it++) {
if (*it == e) {
children.erase(it);
}
}
}
Entity* CompositeEntity::getChild(Entity* e) {
std::vector<Entity*>::iterator it;
for (it = children.begin(); it != children.end(); it++) {
if (*it == e) {
return *it;
}
}
return nullptr;
}
void CompositeEntity::renderChildren(QPainter& painter) {
std::vector<Entity*>::iterator it;
for (it = children.begin(); it != children.end(); it++) {
(*it)->render(painter);
}
}
void CompositeEntity::updateChildren(bool paused, double deltaTimeMilliseconds) {
std::vector<Entity*>::iterator it;
for (it = children.begin(); it != children.end(); it++) {
(*it)->update(paused, deltaTimeMilliseconds);
}
}
// stage 3
// iterate through obstacles and called its resetLevel method
void CompositeEntity::resetLevel() {
std::vector<Entity*>::iterator it;
for (it = children.begin(); it != children.end(); it++) {
(*it)->resetLevel();
}
}