Changeset 11900 for code/branches/3DPacman_FS18/src/modules/pacman
- Timestamp:
- Apr 24, 2018, 1:10:36 PM (7 years ago)
- Location:
- code/branches/3DPacman_FS18/src/modules/pacman
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.cc
r11898 r11900 81 81 82 82 83 Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,10,245),Vector3(215,10,210)}; 83 Vector3 possibleposition[] = {Vector3(175,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), 84 Vector3(185,10,150),Vector3(135,10,145),Vector3(215,10,150)}; 84 85 85 86 /** … … 105 106 if(this->ismoving){ 106 107 if(!(abs(this->actuelposition.z-target_z)<0.1)) { 107 velocity = Vector3( -sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z));108 velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); 108 109 move(dt, actuelposition, velocity); 109 110 } 110 111 if(!(abs(this->actuelposition.x-target_x)<0.1)){ 111 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0, -sgn(this->actuelposition.z-this->target_z));112 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); 112 113 move(dt, actuelposition, velocity); 113 114 } … … 116 117 //Check on which position ghost has arrived and set new target 117 118 else{ 118 if( (abs(this->actuelposition.x - possibleposition[0].x)<0.1) && (abs(this->actuelposition.z - possibleposition[0].z)<0.1)){119 if(findpos(actuelposition,possibleposition[0])){ 119 120 decision = rand()%1; 120 121 switch(decision){ … … 123 124 this->target_z = possibleposition[1].z; 124 125 this->ismoving = true; 126 break; 125 127 } 126 128 127 129 } 128 else if( (abs(actuelposition.x - possibleposition[1].x)<0.1) && (abs(actuelposition.z - possibleposition[1].z)<0.1)){130 else if(findpos(actuelposition,possibleposition[1])){ 129 131 decision = rand()%2; 130 132 switch(decision){ … … 137 139 this->target_x = possibleposition[2].x; 138 140 this->target_z = possibleposition[2].z; 139 this->ismoving = true; 140 } 141 142 } 143 if((abs(this->actuelposition.x - possibleposition[2].x)<0.1) && (abs(this->actuelposition.z - possibleposition[2].z)<0.1)){ 144 decision = rand()%1; 141 this->ismoving = true; 142 break; 143 } 144 145 } 146 else if(findpos(actuelposition,possibleposition[2])){ 147 decision = rand()%2; 145 148 switch(decision){ 146 149 case 0: … … 148 151 this->target_z = possibleposition[1].z; 149 152 this->ismoving = true; 153 break; 154 case 1: 155 this->target_x = possibleposition[3].x; 156 this->target_z = possibleposition[3].z; 157 this->ismoving = true; 158 break; 150 159 } 151 160 152 161 } 162 163 else if(findpos(actuelposition,possibleposition[3])){ 164 decision = rand()%3; 165 switch(decision){ 166 case 0: 167 this->target_x = possibleposition[2].x; 168 this->target_z = possibleposition[2].z; 169 this->ismoving = true; 170 break; 171 case 1: 172 this->target_x = possibleposition[4].x; 173 this->target_z = possibleposition[4].z; 174 this->ismoving = true; 175 break; 176 case 2: 177 this->target_x = possibleposition[5].x; 178 this->target_z = possibleposition[5].z; 179 this->ismoving = true; 180 break; 181 } 182 } 183 184 else if(findpos(actuelposition,possibleposition[4])){ 185 decision = rand()%2; 186 switch(decision){ 187 case 0: 188 this->target_x = possibleposition[3].x; 189 this->target_z = possibleposition[3].z; 190 this->ismoving = true; 191 break; 192 case 1: 193 this->target_x = possibleposition[6].x; 194 this->target_z = possibleposition[6].z; 195 this->ismoving = true; 196 break; 197 } 198 } 199 200 else if(findpos(actuelposition,possibleposition[5])){ 201 decision = rand()%2; 202 switch(decision){ 203 case 0: 204 this->target_x = possibleposition[3].x; 205 this->target_z = possibleposition[3].z; 206 this->ismoving = true; 207 break; 208 case 1: 209 this->target_x = possibleposition[7].x; 210 this->target_z = possibleposition[7].z; 211 this->ismoving = true; 212 break; 213 } 214 } 215 216 else if(findpos(actuelposition,possibleposition[6])){ 217 decision = rand()%1; 218 switch(decision){ 219 case 0: 220 this->target_x = possibleposition[4].x; 221 this->target_z = possibleposition[4].z; 222 this->ismoving = true; 223 break; 224 } 225 } 226 227 else if(findpos(actuelposition,possibleposition[7])){ 228 decision = rand()%1; 229 switch(decision){ 230 case 0: 231 this->target_x = possibleposition[5].x; 232 this->target_z = possibleposition[5].z; 233 this->ismoving = true; 234 break; 235 } 236 } 237 153 238 154 239 else{ … … 163 248 } 164 249 250 bool PacmanGhost::findpos(Vector3 one, Vector3 other){ 251 if((abs(one.x - other.x)<0.1) && (abs(one.z - other.z)<0.1)) return true; 252 return false; 253 } 254 165 255 void PacmanGhost::resetGhost(){ 166 256 this->setPosition(resetposition); -
code/branches/3DPacman_FS18/src/modules/pacman/PacmanGhost.h
r11898 r11900 51 51 void resetGhost(); 52 52 53 bool findpos(Vector3 one, Vector3 other); 54 53 55 inline void setResetPosition(Vector3 rpos) 54 56 { this->resetposition = rpos; }
Note: See TracChangeset
for help on using the changeset viewer.