[12304] | 1 | #include "PacmanRed.h" |
---|
| 2 | //#include "Pacman.h" |
---|
| 3 | |
---|
| 4 | #include "core/CoreIncludes.h" |
---|
| 5 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 6 | |
---|
[12316] | 7 | |
---|
| 8 | |
---|
[12304] | 9 | namespace orxonox{ |
---|
| 10 | |
---|
| 11 | RegisterClass(PacmanRed); |
---|
| 12 | |
---|
| 13 | PacmanRed::PacmanRed(Context* context) : PacmanGhost(context){ |
---|
| 14 | |
---|
| 15 | RegisterObject(PacmanRed); |
---|
[12316] | 16 | this->target_x=0; |
---|
| 17 | this->target_z=15; |
---|
[12322] | 18 | this->lastPlayerPassedPoint=Vector3(0,0,0); //Vector3(70,10,-135); |
---|
[12318] | 19 | this->isNearPlayer=false; |
---|
[12304] | 20 | |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | /** |
---|
| 25 | @brief |
---|
| 26 | Method for creating a ghost through XML. |
---|
| 27 | */ |
---|
| 28 | void PacmanRed::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 29 | { |
---|
| 30 | SUPER(PacmanRed, XMLPort, xmlelement, mode); |
---|
| 31 | } |
---|
| 32 | |
---|
[12316] | 33 | /*void PacmanRed::setPlayerPos(Vector3 _playerPos) |
---|
| 34 | { |
---|
| 35 | this->playerPos = _playerPos; |
---|
| 36 | }*/ |
---|
| 37 | |
---|
| 38 | |
---|
[12304] | 39 | void PacmanRed::tick(float dt) |
---|
| 40 | { |
---|
[12319] | 41 | //std::cout<<"LemanExpress5"<<endl; |
---|
[12304] | 42 | SUPER(PacmanGhost, tick, dt); |
---|
| 43 | |
---|
| 44 | this->actuelposition = this->getPosition(); |
---|
[12316] | 45 | |
---|
| 46 | for(int u=0; u < 67; u++){//always check if player passed a point |
---|
[12323] | 47 | //if(possibleposition[u]!=Vector3(0,10,15)){ |
---|
| 48 | if(jeanfindpos(this->getPlayerPos(), possibleposition[u])){ |
---|
| 49 | //if(!findpos(possibleposition[u],Vector3(0,10,15))){ |
---|
| 50 | this->lastPlayerPassedPoint=possibleposition[u]; |
---|
| 51 | } |
---|
| 52 | //} |
---|
| 53 | //} |
---|
[12316] | 54 | } |
---|
| 55 | |
---|
[12318] | 56 | |
---|
| 57 | /*if((playerFindPos(this->actuelposition, this->getPlayerPos()))&&(isNearPlayer==false)){ |
---|
| 58 | isNearPlayer=true; |
---|
| 59 | setNewTargetRed(this->getPlayerPos()); |
---|
| 60 | } |
---|
| 61 | else if (!(playerFindPos(this->actuelposition, this->getPlayerPos())&&(isNearPlayer==true))){ |
---|
| 62 | isNearPlayer=false; |
---|
| 63 | setNewTargetRed(this->pointInFrontOfPlayer); |
---|
| 64 | }*/ |
---|
| 65 | |
---|
[12325] | 66 | std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
| 67 | std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
[12318] | 68 | |
---|
| 69 | |
---|
| 70 | |
---|
[12304] | 71 | //Stop, if target arrived |
---|
| 72 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
[12319] | 73 | //std::cout<<"LemanExpress1"<<endl; |
---|
[12304] | 74 | this->ismoving = false; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | //Move, if ghost hasn't arrived yet |
---|
| 78 | if(this->ismoving){ |
---|
[12319] | 79 | //std::cout<<"LemanExpress2"<<endl; |
---|
[12304] | 80 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
| 81 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
| 82 | move(dt, actuelposition, velocity); |
---|
| 83 | } |
---|
| 84 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
| 85 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
| 86 | move(dt, actuelposition, velocity); |
---|
| 87 | } |
---|
[12319] | 88 | //std::cout<<"LemanExpress4"<<endl; |
---|
[12304] | 89 | } |
---|
[12322] | 90 | else if(this->lastPlayerPassedPoint==Vector3(0,0,0)){ |
---|
| 91 | //as long as the player has not started the game, |
---|
| 92 | //i.e. lastPlayerPastPoint is (0,0,0), red pacman |
---|
| 93 | //cannot possibly move, because it needs the position |
---|
| 94 | //of the player to move accordingly |
---|
[12318] | 95 | |
---|
[12322] | 96 | this->ismoving=false; |
---|
| 97 | } |
---|
| 98 | |
---|
[12304] | 99 | //Check on which position the ghost has arrived and set new target |
---|
| 100 | else{ |
---|
[12318] | 101 | std::cout<<"LemanExpress3"<<endl; |
---|
[12304] | 102 | |
---|
| 103 | while(lockmove){}; |
---|
| 104 | lockmove = true; |
---|
| 105 | |
---|
| 106 | //do red behavior |
---|
[12316] | 107 | //Use target_x and target_z for position of red pacman |
---|
[12304] | 108 | |
---|
[12316] | 109 | Vector3 redPos=Vector3(this->target_x, 10, this->target_z); |
---|
| 110 | //nextMove(this->getPlayerPos(), redPos); |
---|
[12304] | 111 | |
---|
[12317] | 112 | int directionV = findPlayerTravDir (lastPlayerPassedPoint, this->getPlayerPos()); |
---|
[12325] | 113 | this->pointInFrontOfPlayer=frontPosition(); //getPointInFrontOfPacman(lastPlayerPassedPoint, directionV); |
---|
[12304] | 114 | |
---|
[12317] | 115 | |
---|
[12318] | 116 | if(!findpos(this->actuelposition, lastPlayerPassedPoint)){ |
---|
[12317] | 117 | |
---|
[12319] | 118 | /*std::cout<<this->getPlayerPos()<<endl; |
---|
[12316] | 119 | std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
[12318] | 120 | std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
[12319] | 121 | std::cout<<this->actuelposition<<endl;*/ |
---|
[12316] | 122 | nextMove(redPos, lastPlayerPassedPoint); |
---|
[12318] | 123 | std::cout<<"hiuddi"<<endl; |
---|
[12317] | 124 | } |
---|
[12318] | 125 | else if(findpos(this->actuelposition, lastPlayerPassedPoint)){// red pacman is at lastPlayerPassedPoint |
---|
[12316] | 126 | |
---|
[12319] | 127 | /*std::cout<<"dhdidjop"<<endl; |
---|
[12318] | 128 | std::cout<<this->getPlayerPos()<<endl; |
---|
| 129 | std::cout<<this->lastPlayerPassedPoint<<endl; |
---|
| 130 | std::cout<<this->pointInFrontOfPlayer<<endl; |
---|
[12319] | 131 | std::cout<<this->actuelposition<<endl;*/ |
---|
[12316] | 132 | |
---|
[12323] | 133 | //if(!findpos(pointInFrontOfPlayer, Vector3(0,10,15))){ |
---|
[12318] | 134 | nextMove(lastPlayerPassedPoint, pointInFrontOfPlayer); |
---|
[12323] | 135 | //} |
---|
[12318] | 136 | std::cout<<"ogslodm"<<endl; |
---|
[12317] | 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[12316] | 140 | lockmove=false; //NEVER FORGET THIS ONE !!!!!!! |
---|
[12304] | 141 | } |
---|
| 142 | |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
[12316] | 146 | void PacmanRed::nextMove( Vector3 redPosP, Vector3 playerPos){ |
---|
| 147 | |
---|
| 148 | Vector3 nextTarget; |
---|
[12304] | 149 | |
---|
[12325] | 150 | if(redPosP!=playerPos){ |
---|
[12316] | 151 | nextTarget = getShortestPath(redPosP, playerPos); |
---|
[12325] | 152 | setNewTargetGhost(nextTarget); |
---|
| 153 | } |
---|
[12304] | 154 | } |
---|
| 155 | |
---|
| 156 | } |
---|