[12304] | 1 | #include "PacmanRed.h" |
---|
| 2 | //#include "Pacman.h" |
---|
| 3 | |
---|
| 4 | #include "core/CoreIncludes.h" |
---|
| 5 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 6 | |
---|
| 7 | namespace orxonox{ |
---|
| 8 | |
---|
| 9 | RegisterClass(PacmanRed); |
---|
| 10 | |
---|
| 11 | PacmanRed::PacmanRed(Context* context) : PacmanGhost(context){ |
---|
| 12 | |
---|
| 13 | RegisterObject(PacmanRed); |
---|
| 14 | |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | /** |
---|
| 19 | @brief |
---|
| 20 | Method for creating a ghost through XML. |
---|
| 21 | */ |
---|
| 22 | void PacmanRed::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 23 | { |
---|
| 24 | SUPER(PacmanRed, XMLPort, xmlelement, mode); |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | void PacmanRed::tick(float dt) |
---|
| 28 | { |
---|
| 29 | SUPER(PacmanGhost, tick, dt); |
---|
| 30 | |
---|
| 31 | this->actuelposition = this->getPosition(); |
---|
| 32 | |
---|
| 33 | //Stop, if target arrived |
---|
| 34 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
| 35 | this->ismoving = false; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | //Move, if ghost hasn't arrived yet |
---|
| 39 | if(this->ismoving){ |
---|
| 40 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
| 41 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
| 42 | move(dt, actuelposition, velocity); |
---|
| 43 | } |
---|
| 44 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
| 45 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
| 46 | move(dt, actuelposition, velocity); |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | //Check on which position the ghost has arrived and set new target |
---|
| 51 | else{ |
---|
| 52 | |
---|
| 53 | while(lockmove){}; |
---|
| 54 | lockmove = true; |
---|
| 55 | |
---|
| 56 | //do red behavior |
---|
| 57 | |
---|
| 58 | Vector3 purePos = setPureArrayPos(this->actuelposition); |
---|
| 59 | //find nearest position on the map to red pos if pacman does not move, |
---|
| 60 | //i.e. reached a point on the map |
---|
| 61 | //Why not simply use target_x and target_z ?????? |
---|
| 62 | |
---|
| 63 | nextMove(purePos, player.actuelposition); |
---|
| 64 | //how do we access the PLAYER variable ?????? |
---|
| 65 | |
---|
| 66 | //also, player.lastPassedPoint is maybe better |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | void PacmanRed::setNewTargetRed(Vector3 goalToGo){ |
---|
| 73 | |
---|
| 74 | this->target_x = goalToGo.x; |
---|
| 75 | this->target_z = goalToGo.z; |
---|
| 76 | this->ismoving = true; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | void PacmanRed::nextMove(Vector3 playerPos, Vector3 redPos){ |
---|
| 81 | Vector3 nextTarget; |
---|
| 82 | |
---|
| 83 | nextTarget = getShortestPath(playerPos, redPos); |
---|
| 84 | |
---|
| 85 | setNewTargetRed(nextTarget); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | //save last checkpoint crossed by player |
---|
| 91 | /* |
---|
| 92 | void PacmanGelb::tick(float dt){ //last passed point of player |
---|
| 93 | for(int u=0; u < 67; u++){ |
---|
| 94 | if(findpos(this->getPosition(), possibleposition[u])){ |
---|
| 95 | this->lastPassedPoint=possibleposition[u]; |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | */ |
---|
| 100 | |
---|
| 101 | } |
---|