/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Florian Zinggeler * Co-authors: * ... * */ /** @file 3DPacman.cc @brief Implementation of the 3DPacman class. */ #include "Pacman.h" #include "core/CoreIncludes.h" namespace orxonox { RegisterClass(Pacman); Pacman::Pacman(Context* context) : Deathmatch(context) { RegisterObject(Pacman); // firstGame = true; //needed for the HUD lives = 10; point = 0; level = 1; // setHUDTemplate("PacmanOrxHUD"); // scoreboardTemplate_ = ""; } void Pacman::levelUp() { this->end(); } PacmanGhost* ghosts[4]; void Pacman::tick(float dt) { SUPER(Pacman, tick, dt); if(!timer){ timer = timer - dt; if(timer<=0){ afraid = false; this->setNormal(); } } int i = 0; for(PacmanGhost* nextghost : ObjectList()){ ghosts[i] = nextghost; i++; } player = this->getPlayer(); if (player != nullptr) { currentPosition = player->getWorldPosition(); } bcolli = false; for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){ bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); //orxout() << "GHOST" << nrghost << ghosts[nrghost]->getPosition() << endl; } if(bcolli){ this->catched(); } i = 0; for(PacmanPointSphere* nextsphere : ObjectList()){ if(collis(nextsphere->getPosition(), currentPosition)){ takePoint(nextsphere); } } for(PacmanPointAfraid* next : ObjectList()){ if(collis(next->getPosition(), currentPosition)){ setAfraid(); } } } bool Pacman::collis(Vector3 one, Vector3 other){ if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10)) return true; return false; } void Pacman::catched(){ if(!afraid) { if(!lives) this->end(); --lives; this->posreset(); } else{ for(int nrghost = 0; nrghost<8; ++nrghost){ bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition); if(bcolli) ghosts[nrghost]->resetGhost(); bcolli = false; } } } void Pacman::setAfraid(){ timer = 10; //Set timer to 10 seconds //Change normal Ghosts with afraid ones if(!afraid){ ghosts[0]->changewith(ghosts[4]); ghosts[1]->changewith(ghosts[5]); ghosts[2]->changewith(ghosts[6]); ghosts[3]->changewith(ghosts[7]); } afraid = true; } void Pacman::setNormal(){ timer = 0; //Change normal Ghosts with afraid ones if(afraid){ ghosts[4]->changewith(ghosts[0]); ghosts[5]->changewith(ghosts[1]); ghosts[6]->changewith(ghosts[2]); ghosts[7]->changewith(ghosts[3]); } afraid = false; } void Pacman::posreset(){ for(PacmanGhost* nextghost : ObjectList()){ nextghost->resetGhost(); } player->setPosition(startposplayer); } void Pacman::takePoint(PacmanPointSphere* taken){ ++point; if(point == totallevelpoint) this->levelUp(); Vector3 postaken = taken->getPosition(); postaken.y = -50; taken->setPosition(postaken); } PacmanGelb* Pacman::getPlayer() { for (PacmanGelb* ship : ObjectList()) { return ship; } return nullptr; } int Pacman::getPoints(){ return point; } void Pacman::start() { Deathmatch::start(); } void Pacman::end() { /* firstGame = false; //Set randomized deathmessages if(point<7) sDeathMessage = DeathMessage7[rand()%(DeathMessage7.size())]; else if(point<20) sDeathMessage = DeathMessage20[rand()%(DeathMessage20.size())]; else if(point<30) sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())]; else sDeathMessage = DeathMessageover30[rand()%(DeathMessageover30.size())]; //Update Highscore if (Highscore::exists()) { int score = this->getPoints(); Highscore::getInstance().storeScore("Pacman", score, this->getPlayer()->getPlayer()); } if (Highscore::exists()) { //int score = this->getPoints(); //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); } */ GSLevel::startMainMenu(); } }