- Timestamp:
- Mar 29, 2018, 12:15:19 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhostController.cc
r11832 r11834 43 43 The context of this object. 44 44 */ 45 PacmanGhost Red::PacmanGhostController(Context* context) : Controller(context)45 PacmanGhostController::PacmanGhostController(Context* context) : Controller(context) 46 46 { 47 47 RegisterObject(PacmanGhostController); 48 49 PacmanGhost* myGhost = nullptr; 50 this->actuelposition = myGhost.getPosition(); 51 48 52 bool ismoving = false; 49 float reltarget_x; 50 float reltarget_z; 51 Vector3& actuelposition; 53 this->target_x = actuelposition.x; 54 this->target_z = actuelposition.z; 55 } 56 57 void PacmanGhostController::setGhost(PacmanGhost ghost){ 58 this->myGhost = ghost; 52 59 } 53 60 … … 61 68 } 62 69 70 71 static Vector3[] possibleposition = [new Vector3(0,10,245), new Vector3(215,0,240)]; 63 72 /** 64 73 @brief … … 77 86 PacmanGhost* myDrone = *it; 78 87 79 if ( myGhost != nullptr)88 if (this->myGhost != nullptr) 80 89 { 81 90 82 actuelposition =myGhost.getPosition();91 this->actuelposition = this->myGhost.getPosition(); 83 92 84 if( actuelposition.x = reltarget_x && actuelposition.z = reltarget_z){85 ismoving = false;93 if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){ 94 this->ismoving = false; 86 95 } 87 96 88 89 90 if(ismoving){ 91 moveRightLeft(); 92 moveFrontBack(); 97 if(this->ismoving){ 98 if(!((this->actuelposition.z-target_z)<0.1)) 99 moveFrontBack(sgn(this->actuelposition.z-this->target_z)*dt*100); 100 if(!((this->actuelposition.x-target_x)<0.1)) 101 moveRightLeft(sgn(this->actuelposition.x-this->target_x)*dt*100); //Assume dt is quite small 102 } 103 104 else{ //Check on which position ghost is 105 if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[1].z)<0.1)){ 106 this->target_x = possibleposition[1].x; 107 this->target_z = possibleposition[1].z; 108 this->ismoving = true; 93 109 } 94 110 else if(((actuelposition.x - possibleposition[0].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){ 111 this->target_x = 0 112 this->target_z = 113 this->ismoving = true; 114 } 95 115 else{ 96 97 //hashtable 98 99 int random = rand(); 100 101 switch(actuelposition) { 102 case 1: if(random % 4 == 0){ 103 reltarget_x = 250; 104 reltarget_z = 0; 105 } 106 else if(random % 4 == 1){ 107 reltarget_x = 0; 108 reltarget_z = 250; 109 } 110 else if(random % 4 == 2){ 111 reltarget_x = 0; 112 reltarget_z = -250; 113 } 114 else if(random % 4 == 3){ 115 reltarget_x = -250; 116 reltarget_z = 0; 117 } 118 moving = true; 119 case 2: 120 } 121 } 122 116 } 117 } //End of Position table 123 118 124 119 } 125 120 } 121 126 122 }
Note: See TracChangeset
for help on using the changeset viewer.