#include "PacmanPink.h" #include "core/CoreIncludes.h" #include "BulletDynamics/Dynamics/btRigidBody.h" namespace orxonox{ RegisterClass(PacmanPink); PacmanPink::PacmanPink(Context* context) : PacmanGhost(context){ RegisterObject(PacmanPink); this->target_x=0; this->target_z=15; this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135); } /** @brief Method for creating a ghost through XML. */ void PacmanPink::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(PacmanPink, XMLPort, xmlelement, mode); } void PacmanPink::tick(float dt) { SUPER(PacmanGhost, tick, dt); this->actuelposition = this->getPosition(); for(int u=0; u < 67; u++){//always check if player passed a point if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ this->lastPlayerPassedPoint=possibleposition[u]; } } //Stop, if target arrived if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ this->ismoving = false; } //Move, if ghost hasn't arrived yet if(this->ismoving){ if(!(abs(this->actuelposition.z-target_z)<0.5)) { velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); move(dt, actuelposition, velocity); } if(!(abs(this->actuelposition.x-target_x)<0.5)){ velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); move(dt, actuelposition, velocity); } } else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ //as long as the player has not started the game, //i.e. lastPlayerPastPoint is (0,0,0), pink pacman //cannot possibly move, because it needs the position //of the player to move accordingly this->ismoving=false; } //Check on which position the ghost has arrived and set new target else{ while(lockmove){}; lockmove = true; Vector3 pinkPos=Vector3(this->target_x, 10, this->target_z); std::cout<lastPlayerPassedPoint<getPlayerPos()); this->pointInFrontOfPlayer=getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); std::cout<pointInFrontOfPlayer<actuelposition, player.lastPassedPoint); setNewTargetPink(nextMove); } else{ //if player is not on a point either go to next neighboor, or if no //neighboor in player direction available, go to last point passed by player. int dir=findPlayerTravDir(player.lastPassedPoint, player.getPos()); //not in other sense! Vector3[] neighboors; findNeighboor(player.lastPassedPoint, neighboors); //we need to create function that finds neighboors of player last point //We can use and even should use the part of the tick random function // that determines the neighboors. But array neighboor should be in form // south-west-north-east respectively to array index. for(int s=0; s < 4; s++){ //find next neighboor between player and player.lastPassedPoint if((neighboors[s]!=NULL)&&(s==dir)){ if(dir==0){ Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } else if(dir==1){ Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } else if(dir==2){ Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } else{//last is default Vector3 nextMove=getShortestPath(this->actuelposition, neighboors[s]); setNewTargetPink(nextMove); } } else{//if no further point after last player point possible //then simply go to this last point. Vector3 nextMove=getShortestPath(this->actuelposition, player.lastPassedPoint); setNewTargetPink(nextMove); } } }*/ lockmove=false; } } void PacmanPink::nextMove( Vector3 pinkPosP, Vector3 playerPos, Vector3 pointToAvoidP11){ Vector3 nextTarget; nextTarget = getShortestPath(pinkPosP, playerPos, pointToAvoidP11); setNewTargetGhost(nextTarget); } }