[12320] | 1 | #include "PacmanCyan.h" |
---|
| 2 | //#include "Pacman.h" |
---|
| 3 | |
---|
| 4 | #include "core/CoreIncludes.h" |
---|
| 5 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | namespace orxonox{ |
---|
| 10 | |
---|
| 11 | RegisterClass(PacmanCyan); |
---|
| 12 | |
---|
| 13 | PacmanCyan::PacmanCyan(Context* context) : PacmanGhost(context){ |
---|
| 14 | |
---|
| 15 | RegisterObject(PacmanCyan); |
---|
| 16 | this->target_x=0; |
---|
| 17 | this->target_z=15; |
---|
| 18 | this->lastPlayerPassedPoint=Vector3(70,10,-135); |
---|
[12321] | 19 | |
---|
| 20 | this->isPatrolling = false; |
---|
[12320] | 21 | |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | /** |
---|
| 26 | @brief |
---|
| 27 | Method for creating a ghost through XML. |
---|
| 28 | */ |
---|
| 29 | void PacmanCyan::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 30 | { |
---|
| 31 | SUPER(PacmanCyan, XMLPort, xmlelement, mode); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | void PacmanCyan::tick(float dt) |
---|
| 37 | { |
---|
| 38 | |
---|
| 39 | SUPER(PacmanGhost, tick, dt); |
---|
| 40 | |
---|
| 41 | this->actuelposition = this->getPosition(); |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | //Stop, if target arrived |
---|
| 46 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
| 47 | |
---|
| 48 | this->ismoving = false; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | //Move, if ghost hasn't arrived yet |
---|
| 52 | if(this->ismoving){ |
---|
| 53 | |
---|
| 54 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
| 55 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
| 56 | move(dt, actuelposition, velocity); |
---|
| 57 | } |
---|
| 58 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
| 59 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
| 60 | move(dt, actuelposition, velocity); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | //Check on which position the ghost has arrived and set new target |
---|
| 66 | else{ |
---|
| 67 | |
---|
| 68 | while(lockmove){}; |
---|
| 69 | lockmove = true; |
---|
| 70 | |
---|
[12321] | 71 | Vector3 cyanPos=Vector3(this->target_x, 10, this->target_z); |
---|
[12320] | 72 | |
---|
[12321] | 73 | if(this->isPatrolling==false){ |
---|
| 74 | //we are not patrolling anymore, choose new patrol |
---|
[12320] | 75 | |
---|
[12321] | 76 | |
---|
| 77 | this->nextPatrol(); |
---|
| 78 | |
---|
| 79 | } |
---|
| 80 | else if((this->isPatrolling==true)&&(cyanPos!=this->goalPatrol)){ |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | } |
---|
| 85 | else if(cyanPos==this->goalPatrol){ |
---|
| 86 | |
---|
| 87 | } |
---|
| 88 | else if(cyanPos==this->startPatrol){ |
---|
| 89 | |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
[12320] | 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | lockmove=false; //NEVER FORGET THIS ONE !!!!!!! |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | } |
---|
| 100 | |
---|
[12321] | 101 | void PacmanCyan::nextPatrol(){ |
---|
[12320] | 102 | |
---|
[12321] | 103 | |
---|
| 104 | int indexRand1=rand()%67; |
---|
| 105 | while(indexRand1==44){ |
---|
| 106 | //new try if index is that of the position in the middle |
---|
| 107 | indexRand1=rand()%67; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | int indexRand2=rand()%67; |
---|
| 111 | while((indexRand2==44)||(indexRand2==indexRand1)){ |
---|
| 112 | //new try if 2nd index is same as first one or is index |
---|
| 113 | // of position in the middle |
---|
| 114 | |
---|
| 115 | indexRand2=rand()%67; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | this->startPatrol = possibleposition[indexRand1]; |
---|
| 122 | this->goalPatrol = possibleposition[indexRand2]; |
---|
| 123 | |
---|
| 124 | Vector3 nextMovement = getShortestPath(startPatrol, goalPatrol); |
---|
| 125 | |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
[12320] | 131 | void PacmanCyan::nextMove( Vector3 cyanPosP, Vector3 playerPos){ |
---|
| 132 | |
---|
| 133 | Vector3 nextTarget; |
---|
| 134 | |
---|
| 135 | nextTarget = getShortestPath(cyanPosP, playerPos); |
---|
| 136 | |
---|
| 137 | setNewTargetGhost(nextTarget); |
---|
| 138 | } |
---|
| 139 | |
---|
[12321] | 140 | struct PacmanCyan::PatrolPosition{ |
---|
| 141 | //we need to check if PacmanCyan already passed the goal resp. start patrol point |
---|
[12320] | 142 | |
---|
[12321] | 143 | public: |
---|
| 144 | |
---|
| 145 | Vector3 position; |
---|
| 146 | bool visitedPoint; |
---|
| 147 | |
---|
| 148 | PatrolPosition(Vector3 positionP){ |
---|
| 149 | this->position=positionP; |
---|
| 150 | visitedPoint=false; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | }; |
---|
| 154 | |
---|
| 155 | |
---|
[12320] | 156 | } |
---|