4 void GravityManager::subscribe(Thing
* thing
) {
8 void GravityManager::addPlatform(Platform
* linha
) {
9 platforms
.insert(linha
);
12 void GravityManager::deleteThing(Thing
* thing
) {
13 things
.erase(things
.find(thing
));
16 void GravityManager::update() {
17 std::set
<Thing
*>::iterator it
;
18 std::set
<Platform
*>::iterator plat
;
19 for (it
= things
.begin(); it
!= things
.end(); it
++) {
20 (*it
)->addSpeed(0,(*it
)->gravityRate
);
21 if ((*it
)->getSpeedY() < 0.0) continue;
23 for (plat
= platforms
.begin(); !colisao
&& plat
!= platforms
.end(); plat
++) {
24 colisao
= checkGround(*it
, *plat
);
27 (*it
)->onGround
= true;
28 (*it
)->setSpeed((*it
)->getSpeedX(),0.0);
31 (*it
)->onGround
= false;
36 void GravityManager::removePlatforms() {
40 bool contido(double x1
,double y1
, double x2
, double y2
, Ponto
&ponto
) {
41 return x1
<= ponto
.x
&& ponto
.x
<= x2
&& y1
<= ponto
.y
&& ponto
.y
<= y2
;
44 bool GravityManager::checkGround(Thing
* thing
, Platform
*platform
) {
45 Linha baseLine
= thing
->getBaseLine();
47 Linha
l2(baseLine
.vertices
[0].x
+ thing
->getSpeedX(),
48 baseLine
.vertices
[0].y
+ thing
->getSpeedY(),
49 baseLine
.vertices
[1].x
+ thing
->getSpeedX(),
50 baseLine
.vertices
[1].y
+ thing
->getSpeedY());
51 Linha
l3(l1
.vertices
[0],l2
.vertices
[0]);
52 Linha
l4(l1
.vertices
[1],l2
.vertices
[1]);
53 return (!platform
->isPassable() || !thing
->bypass
) && (
54 linesIntersect(l1
,platform
->getLine()) ||
55 linesIntersect(l2
,platform
->getLine()) ||
56 linesIntersect(l3
,platform
->getLine()) ||
57 linesIntersect(l4
,platform
->getLine()));