/* * 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: * Marc Dreher * Co-authors: * .. * */ #include "PacmanGhost.h" #include "core/CoreIncludes.h" #include "BulletDynamics/Dynamics/btRigidBody.h" namespace orxonox { //Check if there is a collision bool findpos(Vector3 one, Vector3 other){ if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true; return false; } //All positions in the map, see documentation Vector3 possibleposition[67] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4 Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9 Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14 Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19 Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24 Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29 Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34 Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39 Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44 Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49 Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54 Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59 Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64 Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66 RegisterClass(PacmanGhost); /** @brief Constructor. Registers the object and initializes some default values. @param creator The creator of this object. */ PacmanGhost::PacmanGhost(Context* context) : ControllableEntity(context) { RegisterObject(PacmanGhost); this->velocity = Vector3(0, 0, 0); this->setCollisionType(CollisionType::Dynamic); this->actuelposition = this->getPosition(); if(findpos(actuelposition, Vector3(0,-20,0))) dontmove = true; this->target_x = actuelposition.x; this->target_z = actuelposition.z; } /** @brief Destructor. Destroys ghost, if present. */ PacmanGhost::~PacmanGhost() { // Deletes the controller if the object was initialized and the pointer to the controller is not NULL. } /** @brief Method for creating a ghost through XML. */ void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(PacmanGhost, XMLPort, xmlelement, mode); } //Change this with other ghost void PacmanGhost::changewith(PacmanGhost* otherghost){ while(lockmove){}; lockmove = true; //Prevent change of target while ghost is changed otherghost->setPosition(this->getPosition()); this->setPosition(0,-20,0); otherghost->target_x = this->target_x; otherghost->target_z = this->target_z; otherghost->ismoving = this->ismoving; this->dontmove = true; otherghost->dontmove = false; lockmove = false; } //Move ghost with rotation void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){ if(!dontmove){ this->setPosition(Vector3(actuelposition.x+speed*velocity.x*dt,10,actuelposition.z+speed*velocity.z*dt)); //Rotate ghost in the direction of movement if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1)){ if(velocity.x<0){ this->setOrientation(Quaternion(Radian(-1.57), Vector3(0, 1, 0))); } else{ this->setOrientation(Quaternion(Radian(1.57), Vector3(0, 1, 0))); } } if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1)){ if(velocity.z<0){ this->setOrientation(Quaternion(Radian(3.14), Vector3(0, 1, 0))); } else{ this->setOrientation(Quaternion(Radian(0), Vector3(0, 1, 0))); } } } } //Change ability to move void PacmanGhost::changemovability(){ if(dontmove){ dontmove = false;} else{ dontmove = true; } } //ResetGhost void PacmanGhost::resetGhost(){ this->setPosition(this->resetposition); this->ismoving = false; this->actuelposition = this->getPosition(); this->target_x = actuelposition.x; this->target_z = actuelposition.z; } //Increase speed of ghosts void PacmanGhost::levelupvelo(){ speed ++; } Vector3 PacmanGhost::setPureArrayPos(Vector3 &posToSet){ //given that the position of a pacman is generally not "neat", //we need to set it to the nearest point on the map // if the pacman is not moving anymore, i.e. has reached a point int i=0; while(!(findpos(possibleposition[i], posToSet))){ i++; } return possibleposition[i]; } }