Changeset 12303
- Timestamp:
- Apr 11, 2019, 4:57:22 PM (6 years ago)
- Location:
- code/branches/3DPacman_FS19/src/modules/pacman
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS19/src/modules/pacman/CMakeLists.txt
r12293 r12303 7 7 PacmanHUDinfo.cc 8 8 getShortestPath.cc 9 PacmanRandom.cc 9 10 ) 10 11 -
code/branches/3DPacman_FS19/src/modules/pacman/Pacman.cc
r12003 r12303 94 94 i++; 95 95 } 96 97 96 //Switch ghost to not-catchable, if timer is zero 98 97 if(afraid){ -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.cc
r12272 r12303 47 47 48 48 this->velocity = Vector3(0, 0, 0); 49 this->colour = 1;50 49 this->setCollisionType(CollisionType::Dynamic); 51 50 … … 77 76 SUPER(PacmanGhost, XMLPort, xmlelement, mode); 78 77 79 XMLPortParam(PacmanGhost, "colour", setColour, getColour, xmlelement, mode); 80 81 } 82 83 84 //All positions in the map, see documentation 78 } 79 80 81 /* //All positions in the map, see documentation 85 82 Vector3 possibleposition[] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4 86 83 Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9 … … 96 93 Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59 97 94 Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64 98 Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66 95 Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66*/ 99 96 100 97 /** … … 119 116 if(!(abs(this->actuelposition.z-target_z)<0.5)) { 120 117 velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); 121 move(dt, actuelposition, newGoal,velocity);118 move(dt, actuelposition, velocity); 122 119 } 123 120 if(!(abs(this->actuelposition.x-target_x)<0.5)){ … … 127 124 } 128 125 129 else{ 130 while (lockmove){}; 131 lockmove=true; 132 int goal_x = 0; // faraway goal to dertmine the direction of the target 133 int goal_z =0; 134 135 if(this.colour=1){//follow pacman 136 Vector3 newTar = getShortestPath(actuelposition, currentPosition) //acutuelPosition: ghost, currentPosition: Pacman 137 setnewTarget(newTar) 138 139 } 140 //die uebrigen charakteren verhalten sich noch random 141 /*else if(this.colour=2){ 142 } 143 144 else if(this.colour=3){ 145 146 } 147 148 else if(this.colour=4){ 149 150 }*/ 151 152 153 154 //Check on which position the ghost has arrived and set new target 155 else if{(this.colour=2) || (this.colour=3) || (this.colour=4)} 156 while(lockmove){}; 157 lockmove = true; 158 159 if(findpos(actuelposition,possibleposition[0])){ 160 setnewTarget(1,17,19); 161 } 162 else if(findpos(actuelposition,possibleposition[1])){ 163 setnewTarget(0,2); 164 } 165 else if(findpos(actuelposition,possibleposition[2])){ 166 setnewTarget(1,3); 167 } 168 else if(findpos(actuelposition,possibleposition[3])){ 169 setnewTarget(2,4,5); 170 } 171 else if(findpos(actuelposition,possibleposition[4])){ 172 setnewTarget(3,6); 173 } 174 else if(findpos(actuelposition,possibleposition[5])){ 175 setnewTarget(3,7); 176 } 177 else if(findpos(actuelposition,possibleposition[6])){ 178 setnewTarget(4,9,26); 179 } 180 else if(findpos(actuelposition,possibleposition[7])){ 181 setnewTarget(5,8); 182 } 183 else if(findpos(actuelposition,possibleposition[8])){ 184 setnewTarget(7,9); 185 } 186 else if(findpos(actuelposition,possibleposition[9])){ 187 setnewTarget(6,8,10,38); 188 } 189 else if(findpos(actuelposition,possibleposition[10])){ 190 setnewTarget(9,11,45); 191 } 192 else if(findpos(actuelposition,possibleposition[11])){ 193 setnewTarget(10,12,13); 194 } 195 else if(findpos(actuelposition,possibleposition[12])){ 196 setnewTarget(11,14); 197 } 198 else if(findpos(actuelposition,possibleposition[13])){ 199 setnewTarget(11,14,16,61); 200 } 201 else if(findpos(actuelposition,possibleposition[14])){ 202 setnewTarget(12,13,15); 203 } 204 else if(findpos(actuelposition,possibleposition[15])){ 205 setnewTarget(14,16); 206 } 207 else if(findpos(actuelposition,possibleposition[16])){ 208 setnewTarget(13,15,62); 209 } 210 else if(findpos(actuelposition,possibleposition[17])){ 211 setnewTarget(0,25); 212 } 213 else if(findpos(actuelposition,possibleposition[18])){ 214 setnewTarget(19,24); 215 } 216 else if(findpos(actuelposition,possibleposition[19])){ 217 setnewTarget(0,18,20); 218 } 219 else if(findpos(actuelposition,possibleposition[20])){ 220 setnewTarget(19,21); 221 } 222 else if(findpos(actuelposition,possibleposition[21])){ 223 setnewTarget(20,22); 224 } 225 else if(findpos(actuelposition,possibleposition[22])){ 226 setnewTarget(21,23,31); 227 } 228 else if(findpos(actuelposition,possibleposition[23])){ 229 setnewTarget(22,30); 230 } 231 else if(findpos(actuelposition,possibleposition[24])){ 232 setnewTarget(18,29); 233 } 234 else if(findpos(actuelposition,possibleposition[25])){ 235 setnewTarget(17,26); 236 } 237 else if(findpos(actuelposition,possibleposition[26])){ 238 setnewTarget(6,25,27); 239 } 240 else if(findpos(actuelposition,possibleposition[27])){ 241 setnewTarget(26,28,37); 242 } 243 else if(findpos(actuelposition,possibleposition[28])){ 244 setnewTarget(27,29,36); 245 } 246 else if(findpos(actuelposition,possibleposition[29])){ 247 setnewTarget(24,28,30); 248 } 249 else if(findpos(actuelposition,possibleposition[30])){ 250 setnewTarget(23,29,34); 251 } 252 else if(findpos(actuelposition,possibleposition[31])){ 253 setnewTarget(22,32); 254 } 255 else if(findpos(actuelposition,possibleposition[32])){ 256 setnewTarget(31,33); 257 } 258 else if(findpos(actuelposition,possibleposition[33])){ 259 setnewTarget(32,34); 260 } 261 else if(findpos(actuelposition,possibleposition[34])){ 262 setnewTarget(30,33,35,42); 263 } 264 else if(findpos(actuelposition,possibleposition[35])){ 265 setnewTarget(34,36,41); 266 } 267 else if(findpos(actuelposition,possibleposition[36])){ 268 setnewTarget(28,35); 269 } 270 else if(findpos(actuelposition,possibleposition[37])){ 271 setnewTarget(27,38); 272 } 273 else if(findpos(actuelposition,possibleposition[38])){ 274 setnewTarget(9,37,39); 275 } 276 else if(findpos(actuelposition,possibleposition[39])){ 277 setnewTarget(38,40,45); 278 } 279 else if(findpos(actuelposition,possibleposition[40])){ 280 setnewTarget(39,41); //Shouldn't be able to return in center 281 } 282 else if(findpos(actuelposition,possibleposition[41])){ 283 setnewTarget(35,43); 284 } 285 else if(findpos(actuelposition,possibleposition[42])){ 286 setnewTarget(34,43,54); 287 } 288 else if(findpos(actuelposition,possibleposition[43])){ 289 setnewTarget(41,46); 290 } 291 else if(findpos(actuelposition,possibleposition[44])){ 292 setnewTarget(40,66); 293 } 294 else if(findpos(actuelposition,possibleposition[45])){ 295 setnewTarget(10,39,49); 296 } 297 else if(findpos(actuelposition,possibleposition[46])){ 298 setnewTarget(43,47); 299 } 300 else if(findpos(actuelposition,possibleposition[47])){ 301 setnewTarget(46,52,66); 302 } 303 else if(findpos(actuelposition,possibleposition[48])){ 304 setnewTarget(49,51,66); 305 } 306 else if(findpos(actuelposition,possibleposition[49])){ 307 setnewTarget(45,48); 308 } 309 else if(findpos(actuelposition,possibleposition[50])){ 310 setnewTarget(51,61); 311 } 312 else if(findpos(actuelposition,possibleposition[51])){ 313 setnewTarget(48,50); 314 } 315 else if(findpos(actuelposition,possibleposition[52])){ 316 setnewTarget(47,53); 317 } 318 else if(findpos(actuelposition,possibleposition[53])){ 319 setnewTarget(52,58); 320 } 321 else if(findpos(actuelposition,possibleposition[54])){ 322 setnewTarget(42,55,57); 323 } 324 else if(findpos(actuelposition,possibleposition[55])){ 325 setnewTarget(54,56); 326 } 327 else if(findpos(actuelposition,possibleposition[56])){ 328 setnewTarget(55,57,65); 329 } 330 else if(findpos(actuelposition,possibleposition[57])){ 331 setnewTarget(54,56,58,64); 332 } 333 else if(findpos(actuelposition,possibleposition[58])){ 334 setnewTarget(53,57,59); 335 } 336 else if(findpos(actuelposition,possibleposition[59])){ 337 setnewTarget(58,59,63); 338 } 339 else if(findpos(actuelposition,possibleposition[60])){ 340 setnewTarget(59,61,62); 341 } 342 else if(findpos(actuelposition,possibleposition[61])){ 343 setnewTarget(13,50,60); 344 } 345 else if(findpos(actuelposition,possibleposition[62])){ 346 setnewTarget(16,60); 347 } 348 else if(findpos(actuelposition,possibleposition[63])){ 349 setnewTarget(59,64); 350 } 351 else if(findpos(actuelposition,possibleposition[64])){ 352 setnewTarget(57,63,65); 353 } 354 else if(findpos(actuelposition,possibleposition[65])){ 355 setnewTarget(56,64); 356 } 357 else if(findpos(actuelposition,possibleposition[66])){ 358 setnewTarget(47,48); 359 } 360 361 else{ 362 this->resetGhost(); //Shouldn't happen... 363 } //End of Position table 364 lockmove = false; 365 } 366 } 367 } 368 //set a specific newTarget 369 void PacmanGhost::setnewTarget(Vector3 newTarget){ 370 371 this->target_x = newTarget.x; 372 this->target_z = newTarget.; 373 this->ismoving = true; 374 } 126 } 127 375 128 376 129 //Random choice of new target (not used in game, but useful) … … 387 140 } 388 141 389 //Random choice of new target390 void PacmanGhost::setnewTarget(int firstdec, int seconddec){391 decision = rand()%2;392 switch(decision){393 case 0:394 this->target_x = possibleposition[firstdec].x;395 this->target_z = possibleposition[firstdec].z;396 this->ismoving = true;397 break;398 case 1:399 this->target_x = possibleposition[seconddec].x;400 this->target_z = possibleposition[seconddec].z;401 this->ismoving = true;402 break;403 }404 405 }406 407 //Random choice of new target408 void PacmanGhost::setnewTarget(int firstdec, int seconddec, int thirddec){409 410 decision = rand()%3;411 switch(decision){412 case 0:413 this->target_x = possibleposition[firstdec].x;414 this->target_z = possibleposition[firstdec].z;415 this->ismoving = true;416 break;417 case 1:418 this->target_x = possibleposition[seconddec].x;419 this->target_z = possibleposition[seconddec].z;420 this->ismoving = true;421 break;422 case 2:423 this->target_x = possibleposition[thirddec].x;424 this->target_z = possibleposition[thirddec].z;425 this->ismoving = true;426 break;427 }428 429 }430 431 //Random choice of new target432 void PacmanGhost::setnewTarget(int firstdec, int seconddec, int thirddec, int fourthdec){433 434 decision = rand()%4;435 switch(decision){436 case 0:437 this->target_x = possibleposition[firstdec].x;438 this->target_z = possibleposition[firstdec].z;439 this->ismoving = true;440 break;441 case 1:442 this->target_x = possibleposition[seconddec].x;443 this->target_z = possibleposition[seconddec].z;444 this->ismoving = true;445 break;446 case 2:447 this->target_x = possibleposition[thirddec].x;448 this->target_z = possibleposition[thirddec].z;449 this->ismoving = true;450 break;451 case 3:452 this->target_x = possibleposition[fourthdec].x;453 this->target_z = possibleposition[fourthdec].z;454 this->ismoving = true;455 break;456 }457 458 }459 460 142 //Change this with other ghost 461 143 void PacmanGhost::changewith(PacmanGhost* otherghost){ -
code/branches/3DPacman_FS19/src/modules/pacman/PacmanGhost.h
r12272 r12303 58 58 bool dontmove = false; 59 59 60 //analog AutonomousDrone.h61 inline void setColour( int newColour )62 { this->coulour = newColour; }63 60 64 inline int getColour()65 { return this->coulour;}66 67 private:68 61 int decision = 0; 69 62 Vector3 resetposition = Vector3(0,10,15); … … 73 66 Vector3 actuelposition; 74 67 bool ismoving = false; 75 int target_x = 0; // one step 76 int target_z = 0; 68 int target_x = 0; 69 int target_z = 0; 70 bool lockmove = false; 77 71 78 bool lockmove = false; 79 int colour=0; 80 /* 81 colour= 82 1: red: follow 83 2: pink: get infront of him 84 3: blue: patrol an area 85 4: orange: get away of Pacman 86 */ 72 //All positions in the map, see documentation 73 Vector3 possibleposition[67] = {Vector3(20,10,245),Vector3(215,10,245),Vector3(215,10,195),Vector3(185,10,195),Vector3(135,10,195), //0-4 74 Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9 75 Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14 76 Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19 77 Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24 78 Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29 79 Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34 80 Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39 81 Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44 82 Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49 83 Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54 84 Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59 85 Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64 86 Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66 87 88 private: 87 89 void setnewTarget(int firstdec); 88 90 void setnewTarget(int firstdec, int seconddec);
Note: See TracChangeset
for help on using the changeset viewer.