-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDarkHoles.cpp
More file actions
107 lines (87 loc) · 2.12 KB
/
DarkHoles.cpp
File metadata and controls
107 lines (87 loc) · 2.12 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
99
100
101
102
103
104
105
106
107
#include "DarkHoles.h"
#include "Messages_defs.h"
#include "ServiceLocator.h"
#include "Logger.h"
#include <sstream>
DarkHoles::DarkHoles(SDLGame* game) : GameObjectPool(game), rotating_(5),
blackHoleImage_(game->getServiceLocator()->getTextures()->getTexture(Resources::DarkHole)) {
numHoles_ = initHoles_;
for (auto o : getAllObjects()) {
o->addC(&rotating_);
o->addC(&blackHoleImage_);
}
setId(msg::DarkHoles);
}
DarkHoles::~DarkHoles() {}
void DarkHoles::InitHoles() {
for (int i = 0; i < numHoles_; i++) {
if (getUnusedObject() != nullptr) {
VeryDarkHole *a = getUnusedObject();
a->setActive(true);
a->setPosition(randPos());
a->setHeight(50);
a->setWidth(50);
//Logger
callLogger(a->getPosition());
}
}
setId(msg::DarkHoles);
setActive(false);
}
void DarkHoles::DuplicateHoles() {
numHoles_ *= 2;
if (numHoles_ > 8) numHoles_ = initHoles_;
}
void DarkHoles::receive(const void * senderObj, const msg::Message & m) {
Container::receive(senderObj, m);
switch (m.type_) {
case msg::GAME_START:
this->getGame()->send(this, msg::DarkHoleInfo(getId(), msg::Broadcast, &getAllObjects()));
break;
case msg::ROUND_START:
InitHoles();
setActive(true);
break;
case msg::ROUND_OVER:
this->deactiveAllObjects();
DuplicateHoles();
setActive(false);
break;
default:
break;
}
}
//Info del Logger
void DarkHoles::callLogger(Vector2D p) {
Logger::instance()->log([p]() {
stringstream s;
s << "New Hole: " << p;
return s.str();
});
}
//Arreglar las posiciones
Vector2D DarkHoles::randPos() {
Vector2D p = Vector2D(0, 0);
int aux = rand() % 4;
switch (aux) {
//Arriba
case 0:
p = Vector2D(rand() % this->getGame()->getWindowWidth(), rand() % 50);
break;
//Abajo
case 1:
p = Vector2D(rand() % this->getGame()->getWindowWidth(), rand() % 50 + (this->getGame()->getWindowHeight() - 150));
break;
//Izq
case 2:
p = Vector2D(rand() % 50, rand() % this->getGame()->getWindowHeight());
break;
//Der
case 3:
p = Vector2D(rand() % 50 + (this->getGame()->getWindowWidth() - 150), rand() % this->getGame()->getWindowHeight());
break;
default:
break;
}
return p;
}