From e48c081655fa10f1827b4b5e9ccf3541b0344675 Mon Sep 17 00:00:00 2001 From: El Saico Date: Fri, 4 Dec 2009 00:56:48 -0200 Subject: [PATCH] =?utf8?q?Pegar=20itens=20com=20Enter=20(n=C3=A3o-testado)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Makefile | 41 ----------------------------------------- collision.cpp | 7 ++++--- collision.h | 2 +- controle.cpp | 9 +++++---- controle.h | 1 + controlewii.cpp | 11 +++++++++-- weaponitem.h | 1 + 7 files changed, 21 insertions(+), 51 deletions(-) delete mode 100755 Makefile diff --git a/Makefile b/Makefile deleted file mode 100755 index 50107ce..0000000 --- a/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -OBJS = \ - main.o \ - geometry.o \ - luaenv.o \ - shooter.o \ - player.o \ - game.o \ - timer.o \ - controle.o \ - thing.o \ - gravity.o \ - mapa.o \ - platform.o \ - controleteclado.o \ - weapon.o \ - maploader.o \ - weaponmanager.o \ - configmanager.o \ - shot.o \ - shotmanager.o \ - controlewii.o \ - collision.o \ - enemy.o \ - weaponitem.o \ - - -SRCS = $(OBJS,.o=.cpp) - -all: a.out - -a.out: $(OBJS) - g++ -lSDL -lGL -lcwiid $(OBJS) liblua.a - -.cpp.o: - g++ -c $< - -clean: - rm -f a.out *.o - -ubuntu: $(OBJS) - g++ -lSDL -lGL -llua5.1 -lcwiid $(OBJS) diff --git a/collision.cpp b/collision.cpp index f413ccb..a988dff 100644 --- a/collision.cpp +++ b/collision.cpp @@ -34,7 +34,7 @@ bool pointInsidePolygon(Ponto ponto, Polygon p) { return false; } -void CollisionManager::checkCollision(Thing* a, Thing* b){ +bool CollisionManager::checkCollision(Thing* a, Thing* b){ Polygon pa,pb; pa = a->getCollision(); pb = b->getCollision(); @@ -44,7 +44,7 @@ void CollisionManager::checkCollision(Thing* a, Thing* b){ if (pointInsidePolygon(pb.linhas[0].vertices[0],pa)) { a->collide(b); b->collide(a); - return; + return true; } for (ita = pa.linhas.begin(); ita != pa.linhas.end(); ita++) { for (itb = pb.linhas.begin(); itb != pb.linhas.end(); itb++) { @@ -55,8 +55,9 @@ void CollisionManager::checkCollision(Thing* a, Thing* b){ if (linesIntersect(*ita,*itb)) { a->collide(b); b->collide(a); - return; + return true; } } } + return false; } diff --git a/collision.h b/collision.h index 8998e18..71bff16 100644 --- a/collision.h +++ b/collision.h @@ -7,8 +7,8 @@ class CollisionManager { private: std::set things; - void checkCollision(Thing* a, Thing* b); public: + bool checkCollision(Thing* a, Thing* b); void subscribe(Thing* thing); void remove(Thing* thing); void update(); diff --git a/controle.cpp b/controle.cpp index e39c248..f7e05de 100644 --- a/controle.cpp +++ b/controle.cpp @@ -4,6 +4,7 @@ Controle::Controle(Player &p) : jogador( p ) { quit = false; game = jogador.game; + map = game->mapa; } void Controle::handleEvents() { @@ -27,16 +28,16 @@ void Controle::handleEvents() { case SDL_KEYDOWN: switch (e.key.keysym.sym) { case SDLK_F3: - jogador.equip(jogador.game->weaponManager->getWeapon("Shotgun")); + jogador.equip(game->weaponManager->getWeapon("Shotgun")); break; case SDLK_F4: - jogador.equip(jogador.game->weaponManager->getWeapon("Flamethrower")); + jogador.equip(game->weaponManager->getWeapon("Flamethrower")); break; case SDLK_F5: - jogador.game->reloadLua(); + game->reloadLua(); break; case SDLK_F6: - jogador.setPosition(jogador.game->getSpawn().x,jogador.game->getSpawn().y); + jogador.setPosition(game->getSpawn().x, game->getSpawn().y); break; default: handleEvent(e);break; } diff --git a/controle.h b/controle.h index 30d3de1..64110b7 100644 --- a/controle.h +++ b/controle.h @@ -8,6 +8,7 @@ class Controle { Player &jogador; bool quit; Game* game; + Mapa* map; public: Controle(Player &p); void handleEvents(); diff --git a/controlewii.cpp b/controlewii.cpp index 7aa0d41..bf8b80f 100644 --- a/controlewii.cpp +++ b/controlewii.cpp @@ -1,7 +1,7 @@ #include "controlewii.h" #include "usereventtype.h" -#include - +#include "weaponitem.h" +#include ControleWii::ControleWii(Player &p) : Controle(p) { connected = false; @@ -15,6 +15,7 @@ ControleWii::ControleWii(Player &p) : Controle(p) { } void ControleWii::handleOther() { + std::list::iterator it; Uint8 *keystates = SDL_GetKeyState( NULL ); if (keystates[SDLK_DOWN]) { jogador.onGround = false; @@ -166,6 +167,12 @@ void ControleWii::handleEvent(SDL_Event &e) { case SDLK_RIGHT: jogador.addSpeed( 3, 0); break; + case SDLK_RETURN: + for (it = map->items.begin(); it != map->items.end(); ++it) + if (game->collisionManager->checkCollision(&jogador, (Thing*) *it)) { + jogador.equip((*it)->getWeapon()); + map->items.erase(it); + } default: break; } break; diff --git a/weaponitem.h b/weaponitem.h index b3a447c..f2499f0 100644 --- a/weaponitem.h +++ b/weaponitem.h @@ -16,6 +16,7 @@ class WeaponItem: public Thing { virtual Polygon getCollision(); virtual void collide(Thing* b); void desenha(); + Weapon* getWeapon() {return arma;} }; #endif -- 2.11.4.GIT