Consertando sumiço misterioso do Makefile
[Projeto-PCG.git] / gravity.cpp
blob905f399661631f4b93c3b6be09d296e0ee61c208
1 #include "gravity.h"
2 #include <iostream>
4 void GravityManager::subscribe(Thing* thing) {
5 things.insert(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;
22 bool colisao = false;
23 for (plat = platforms.begin(); !colisao && plat != platforms.end(); plat++) {
24 colisao = checkGround(*it, *plat);
26 if (colisao) {
27 (*it)->onGround = true;
28 (*it)->setSpeed((*it)->getSpeedX(),0.0);
30 else {
31 (*it)->onGround = false;
36 void GravityManager::removePlatforms() {
37 platforms.clear();
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 l1 = thing->getBaseLine();
46 l1.translate(thing->getPosition());
47 Linha l2 = l1;
48 l2.translate(thing->getSpeed());
49 Linha l3(l1.vertices[0],l2.vertices[0]);
50 Linha l4(l1.vertices[1],l2.vertices[1]);
51 return (!platform->isPassable() || !thing->bypass) && (
52 linesIntersect(l1,platform->getLine()) ||
53 linesIntersect(l2,platform->getLine()) ||
54 linesIntersect(l3,platform->getLine()) ||
55 linesIntersect(l4,platform->getLine()));