/* * 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 { RegisterUnloadableClass(Pacman); Pacman::Pacman(Context* context) : Deathmatch(context) { RegisterObject(Pacman); lives = 3; point = 0; level = 1; } void Pacman::levelUp() { this->end(); } PacmanGhost[4] ghosts; PacmanPointSphere[1] spheres; void Pacman::tick(float dt) { 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<3) && (!bcolli); ++nrghost){ bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition) } if(bcolli){ this->catched(); } i = 0; for(PacmanPointSphere* nextsphere : ObjectList()){ if(collis(nextsphere->getPosition(), currentPosition)){ takePoint(nextsphere); } } SUPER(Pacman, tick, dt); } bool Pacman::collis(Vector3 one, Vector3 other){ if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1)) return true; return false; } void Pacman::catched(){ if(!lives) this->end(); --lives; this->posreset(); } void Pacman::posreset(){ int i = 0; for(PacmanGhost* nextghost : ObjectList()){ nextghost->resetGhost(); i++; } 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() { orxout() << "start" << endl; Deathmatch::start(); } void Pacman::playerPreSpawn(PlayerInfo* player) { //PlayerInfo* playerInfo_; //this->playerInfo_ = player; if(lives <= 0) { this->end(); } } void Pacman::end() { if (Highscore::exists()) { int score = this->getPoints(); //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); } GSLevel::startMainMenu(); } }