/* * 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: * Oli Scheuss * Co-authors: * Damian 'Mozork' Frick * */ #include "PacmanGhostController.h" #include "PacmanGhost.h" #include "util/Math.h" namespace orxonox { // Create the factory for the drone controller. RegisterClass(PacmanGhostController); /** @brief Constructor. @param context The context of this object. */ PacmanGhostController::PacmanGhostController(Context* context) : Controller(context) { RegisterObject(PacmanGhostController); PacmanGhost* myGhost = nullptr; this->actuelposition = myGhost.getPosition(); bool ismoving = false; this->target_x = actuelposition.x; this->target_z = actuelposition.z; } void PacmanGhostController::setGhost(PacmanGhost ghost){ this->myGhost = ghost; } /** @brief Destructor. */ PacmanGhostController::~PacmanGhostController() { } static Vector3[] possibleposition = [new Vector3(0,10,245), new Vector3(215,0,240)]; /** @brief The controlling happens here. This method defines what the controller has to do each tick. @param dt The duration of the tick. */ void PacmanGhostController::tick(float dt) { /* NOTE: Ugly hack by Sandro to make the tutorial work for the moment. * This will be reverted once the framework update is complete */ //AutonomousDrone *myDrone = static_cast(this->getControllableEntity()); ObjectList objectList; ObjectList::iterator it = objectList.begin(); PacmanGhost* myDrone = *it; if (this->myGhost != nullptr) { this->actuelposition = this->myGhost.getPosition(); if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){ this->ismoving = false; } if(this->ismoving){ if(!((this->actuelposition.z-target_z)<0.1)) moveFrontBack(sgn(this->actuelposition.z-this->target_z)*dt*100); if(!((this->actuelposition.x-target_x)<0.1)) moveRightLeft(sgn(this->actuelposition.x-this->target_x)*dt*100); //Assume dt is quite small } else{ //Check on which position ghost is if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[1].z)<0.1)){ this->target_x = possibleposition[1].x; this->target_z = possibleposition[1].z; this->ismoving = true; } else if(((actuelposition.x - possibleposition[0].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){ this->target_x = 0 this->target_z = this->ismoving = true; } else{ } } //End of Position table } } }