/* * 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 "3DPacman.h" #include "core/CoreIncludes.h" #include "PacmanGelb.h" #include "PacmanGhost.h" #include "PacmanPointSphere.h" namespace orxonox { RegisterUnloadableClass(3DPacman); 3DPacman::3DPacman(Context* context) : Deathmatch(context) { RegisterObject(3DPacman); lives = 3; point = 0: level = 1; Vector3 startposplayer = Vector3(0,10,245); } void 3DPacman::levelUp() { this->end(); } PacmanGhost[4] ghosts; PacmanPointSphere[1] spheres; void 3DPacman::tick(float dt) { int i = 0; for(PacmanGhost* nextghost : ObjectList()){ ghosts[i] = nextghost; i++; } player = this->getPlayer(); if (player != nullptr) { currentPosition = player->getWorldPosition(); } bool bcolli = false; for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){ bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition) } if(collis){ this->catched(); } i = 0; for(PacmanPointSphere* nextsphere : ObjectList()){ if(collis(nextsphere.getPosition(), currentPosition)){ takePoint(nextsphere); } } SUPER(3DPacman, tick, dt); } bool 3DPacman::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 3DPacman::catched(){ if(!lives) this->end(); --lives; this->posreset(); } void 3DPacman::posreset(){ int i = 0; for(PacmanGhost* nextghost : ObjectList()){ nextghost.resetGhost(); i++; } player.setPosition(startposplayer); } void 3DPacman::takePoint(PacmanPointSphere* taken){ ++point; if(point == totallevelpoint) this->levelUp; Vector3 postaken = taken.getPosition(); postaken.y = -50; taken.setPosition(postaken); } PacmanGelb* 3DPacman::getPlayer() { for (PacmanGelb* ship : ObjectList()) { return ship; } return nullptr; } void 3DPacman::start() { orxout() << "start" << endl; Deathmatch::start(); } void 3DPacman::playerPreSpawn(PlayerInfo* player) { this->playerInfo_ = player; if(lives <= 0) { this->end(); } } void 3DPacman::end() { if (Highscore::exists()) { int score = this->getPoints(); Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_); } GSLevel::startMainMenu(); } }