[11898] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[11992] | 23 | * Marc Dreher |
---|
[11898] | 24 | * Co-authors: |
---|
[11992] | 25 | * .. |
---|
[11898] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "PacmanGhost.h" |
---|
| 30 | |
---|
| 31 | #include "core/CoreIncludes.h" |
---|
| 32 | #include "BulletDynamics/Dynamics/btRigidBody.h" |
---|
| 33 | |
---|
| 34 | namespace orxonox |
---|
| 35 | { |
---|
| 36 | RegisterClass(PacmanGhost); |
---|
| 37 | |
---|
| 38 | /** |
---|
| 39 | @brief |
---|
| 40 | Constructor. Registers the object and initializes some default values. |
---|
| 41 | @param creator |
---|
| 42 | The creator of this object. |
---|
| 43 | */ |
---|
| 44 | PacmanGhost::PacmanGhost(Context* context) : ControllableEntity(context) |
---|
| 45 | { |
---|
| 46 | RegisterObject(PacmanGhost); |
---|
| 47 | |
---|
[11927] | 48 | this->velocity = Vector3(0, 0, 0); |
---|
[11898] | 49 | |
---|
| 50 | this->setCollisionType(CollisionType::Dynamic); |
---|
| 51 | |
---|
| 52 | this->actuelposition = this->getPosition(); |
---|
[11945] | 53 | |
---|
| 54 | if(findpos(actuelposition, Vector3(0,-20,0))) |
---|
| 55 | dontmove = true; |
---|
[11898] | 56 | |
---|
| 57 | this->target_x = actuelposition.x; |
---|
[11927] | 58 | this->target_z = actuelposition.z; |
---|
[11898] | 59 | |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | /** |
---|
| 63 | @brief |
---|
[11992] | 64 | Destructor. Destroys ghost, if present. |
---|
[11898] | 65 | */ |
---|
| 66 | PacmanGhost::~PacmanGhost() |
---|
| 67 | { |
---|
| 68 | // Deletes the controller if the object was initialized and the pointer to the controller is not NULL. |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | @brief |
---|
[11992] | 73 | Method for creating a ghost through XML. |
---|
[11898] | 74 | */ |
---|
| 75 | void PacmanGhost::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 76 | { |
---|
| 77 | SUPER(PacmanGhost, XMLPort, xmlelement, mode); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
[11992] | 81 | //All positions in the map, see documentation |
---|
[11915] | 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 |
---|
| 83 | Vector3(185,10,150),Vector3(135,10,150),Vector3(215,10,150),Vector3(215,10,105),Vector3(135,10,105), //5-9 |
---|
| 84 | Vector3(135,10,15),Vector3(135,10,-85),Vector3(215,10,-85),Vector3(135,10,-135),Vector3(215,10,-135), //10-14 |
---|
| 85 | Vector3(215,10,-195),Vector3(135,10,-195),Vector3(20,10,195),Vector3(-20,10,195),Vector3(-20,10,245), //15-19 |
---|
| 86 | Vector3(-215,10,245),Vector3(-215,10,195),Vector3(-185,10,195),Vector3(-135,10,195),Vector3(-70,10,195), //20-24 |
---|
| 87 | Vector3(70,10,195),Vector3(70,10,150),Vector3(20,10,150),Vector3(-20,10,150),Vector3(-70,10,150), //25-29 |
---|
[11926] | 88 | Vector3(-135,10,150),Vector3(-185,10,150),Vector3(-215,10,150),Vector3(-215,10,105),Vector3(-135,10,105), //30-34 |
---|
[11917] | 89 | Vector3(-70,10,105),Vector3(-20,10,105),Vector3(20,10,105),Vector3(70,10,105),Vector3(70,10,60), //35-39 |
---|
| 90 | Vector3(0,10,60),Vector3(-70,10,60),Vector3(-135,10,15),Vector3(-70,10,60),Vector3(0,10,15), //40-44 |
---|
| 91 | Vector3(70,10,15),Vector3(-70,10,-35),Vector3(-20,10,-35),Vector3(20,10,-35),Vector3(70,10,-35), //45-49 |
---|
| 92 | Vector3(70,10,-85),Vector3(20,10,-85),Vector3(-20,10,-85),Vector3(-70,10,-85),Vector3(-135,10,-85), //50-54 |
---|
| 93 | Vector3(-215,10,-85),Vector3(-215,10,-135),Vector3(-135,10,-135),Vector3(-70,10,-135),Vector3(-20,10,-135), //55-59 |
---|
| 94 | Vector3(20,10,-135),Vector3(70,10,-135),Vector3(20,10,-195),Vector3(-20,10,-195),Vector3(-135,10,-195), //60-64 |
---|
[11925] | 95 | Vector3(-215,10,-195),Vector3(0,10,-35)}; //65-66 |
---|
[11924] | 96 | |
---|
[11898] | 97 | /** |
---|
| 98 | @brief |
---|
[11992] | 99 | Defines which actions the ghost has to take in each tick. |
---|
[11898] | 100 | @param dt |
---|
| 101 | The length of the tick. |
---|
| 102 | */ |
---|
| 103 | void PacmanGhost::tick(float dt) |
---|
| 104 | { |
---|
| 105 | SUPER(PacmanGhost, tick, dt); |
---|
| 106 | |
---|
| 107 | this->actuelposition = this->getPosition(); |
---|
| 108 | |
---|
| 109 | //Stop, if target arrived |
---|
[11915] | 110 | if((abs(this->actuelposition.x - this->target_x)<0.5) && (abs(this->actuelposition.z - this->target_z)<0.5)){ |
---|
[11898] | 111 | this->ismoving = false; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | //Move, if ghost hasn't arrived yet |
---|
| 115 | if(this->ismoving){ |
---|
[11915] | 116 | if(!(abs(this->actuelposition.z-target_z)<0.5)) { |
---|
[11979] | 117 | velocity = Vector3(0,0,-sgn(this->actuelposition.z-this->target_z)); |
---|
[11898] | 118 | move(dt, actuelposition, velocity); |
---|
| 119 | } |
---|
[11915] | 120 | if(!(abs(this->actuelposition.x-target_x)<0.5)){ |
---|
[11979] | 121 | velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,0); |
---|
[11898] | 122 | move(dt, actuelposition, velocity); |
---|
| 123 | } |
---|
| 124 | } |
---|
[12009] | 125 | //Check on which position the ghost has arrived and set new target |
---|
[11898] | 126 | else{ |
---|
[11952] | 127 | while(lockmove){}; |
---|
| 128 | lockmove = true; |
---|
| 129 | |
---|
[11900] | 130 | if(findpos(actuelposition,possibleposition[0])){ |
---|
[11915] | 131 | setnewTarget(1,17,19); |
---|
[11903] | 132 | } |
---|
| 133 | else if(findpos(actuelposition,possibleposition[1])){ |
---|
| 134 | setnewTarget(0,2); |
---|
| 135 | } |
---|
| 136 | else if(findpos(actuelposition,possibleposition[2])){ |
---|
| 137 | setnewTarget(1,3); |
---|
| 138 | } |
---|
| 139 | else if(findpos(actuelposition,possibleposition[3])){ |
---|
| 140 | setnewTarget(2,4,5); |
---|
| 141 | } |
---|
| 142 | else if(findpos(actuelposition,possibleposition[4])){ |
---|
| 143 | setnewTarget(3,6); |
---|
| 144 | } |
---|
| 145 | else if(findpos(actuelposition,possibleposition[5])){ |
---|
| 146 | setnewTarget(3,7); |
---|
| 147 | } |
---|
| 148 | else if(findpos(actuelposition,possibleposition[6])){ |
---|
[11915] | 149 | setnewTarget(4,9,26); |
---|
[11903] | 150 | } |
---|
| 151 | else if(findpos(actuelposition,possibleposition[7])){ |
---|
[11915] | 152 | setnewTarget(5,8); |
---|
[11903] | 153 | } |
---|
[11915] | 154 | else if(findpos(actuelposition,possibleposition[8])){ |
---|
| 155 | setnewTarget(7,9); |
---|
| 156 | } |
---|
| 157 | else if(findpos(actuelposition,possibleposition[9])){ |
---|
[11917] | 158 | setnewTarget(6,8,10,38); |
---|
[11915] | 159 | } |
---|
| 160 | else if(findpos(actuelposition,possibleposition[10])){ |
---|
[11917] | 161 | setnewTarget(9,11,45); |
---|
[11915] | 162 | } |
---|
| 163 | else if(findpos(actuelposition,possibleposition[11])){ |
---|
| 164 | setnewTarget(10,12,13); |
---|
| 165 | } |
---|
| 166 | else if(findpos(actuelposition,possibleposition[12])){ |
---|
| 167 | setnewTarget(11,14); |
---|
| 168 | } |
---|
| 169 | else if(findpos(actuelposition,possibleposition[13])){ |
---|
[11917] | 170 | setnewTarget(11,14,16,61); |
---|
[11915] | 171 | } |
---|
| 172 | else if(findpos(actuelposition,possibleposition[14])){ |
---|
| 173 | setnewTarget(12,13,15); |
---|
| 174 | } |
---|
| 175 | else if(findpos(actuelposition,possibleposition[15])){ |
---|
| 176 | setnewTarget(14,16); |
---|
| 177 | } |
---|
| 178 | else if(findpos(actuelposition,possibleposition[16])){ |
---|
[11917] | 179 | setnewTarget(13,15,62); |
---|
[11915] | 180 | } |
---|
| 181 | else if(findpos(actuelposition,possibleposition[17])){ |
---|
| 182 | setnewTarget(0,25); |
---|
| 183 | } |
---|
| 184 | else if(findpos(actuelposition,possibleposition[18])){ |
---|
| 185 | setnewTarget(19,24); |
---|
| 186 | } |
---|
| 187 | else if(findpos(actuelposition,possibleposition[19])){ |
---|
| 188 | setnewTarget(0,18,20); |
---|
| 189 | } |
---|
| 190 | else if(findpos(actuelposition,possibleposition[20])){ |
---|
| 191 | setnewTarget(19,21); |
---|
| 192 | } |
---|
| 193 | else if(findpos(actuelposition,possibleposition[21])){ |
---|
| 194 | setnewTarget(20,22); |
---|
| 195 | } |
---|
| 196 | else if(findpos(actuelposition,possibleposition[22])){ |
---|
| 197 | setnewTarget(21,23,31); |
---|
| 198 | } |
---|
| 199 | else if(findpos(actuelposition,possibleposition[23])){ |
---|
| 200 | setnewTarget(22,30); |
---|
| 201 | } |
---|
| 202 | else if(findpos(actuelposition,possibleposition[24])){ |
---|
| 203 | setnewTarget(18,29); |
---|
| 204 | } |
---|
| 205 | else if(findpos(actuelposition,possibleposition[25])){ |
---|
| 206 | setnewTarget(17,26); |
---|
| 207 | } |
---|
| 208 | else if(findpos(actuelposition,possibleposition[26])){ |
---|
| 209 | setnewTarget(6,25,27); |
---|
| 210 | } |
---|
| 211 | else if(findpos(actuelposition,possibleposition[27])){ |
---|
[11917] | 212 | setnewTarget(26,28,37); |
---|
[11915] | 213 | } |
---|
| 214 | else if(findpos(actuelposition,possibleposition[28])){ |
---|
[11917] | 215 | setnewTarget(27,29,36); |
---|
[11915] | 216 | } |
---|
| 217 | else if(findpos(actuelposition,possibleposition[29])){ |
---|
| 218 | setnewTarget(24,28,30); |
---|
| 219 | } |
---|
| 220 | else if(findpos(actuelposition,possibleposition[30])){ |
---|
| 221 | setnewTarget(23,29,34); |
---|
| 222 | } |
---|
| 223 | else if(findpos(actuelposition,possibleposition[31])){ |
---|
| 224 | setnewTarget(22,32); |
---|
| 225 | } |
---|
| 226 | else if(findpos(actuelposition,possibleposition[32])){ |
---|
| 227 | setnewTarget(31,33); |
---|
| 228 | } |
---|
| 229 | else if(findpos(actuelposition,possibleposition[33])){ |
---|
| 230 | setnewTarget(32,34); |
---|
| 231 | } |
---|
| 232 | else if(findpos(actuelposition,possibleposition[34])){ |
---|
[11917] | 233 | setnewTarget(30,33,35,42); |
---|
[11915] | 234 | } |
---|
[11917] | 235 | else if(findpos(actuelposition,possibleposition[35])){ |
---|
| 236 | setnewTarget(34,36,41); |
---|
| 237 | } |
---|
| 238 | else if(findpos(actuelposition,possibleposition[36])){ |
---|
| 239 | setnewTarget(28,35); |
---|
| 240 | } |
---|
| 241 | else if(findpos(actuelposition,possibleposition[37])){ |
---|
| 242 | setnewTarget(27,38); |
---|
| 243 | } |
---|
| 244 | else if(findpos(actuelposition,possibleposition[38])){ |
---|
| 245 | setnewTarget(9,37,39); |
---|
| 246 | } |
---|
| 247 | else if(findpos(actuelposition,possibleposition[39])){ |
---|
| 248 | setnewTarget(38,40,45); |
---|
| 249 | } |
---|
| 250 | else if(findpos(actuelposition,possibleposition[40])){ |
---|
| 251 | setnewTarget(39,41); //Shouldn't be able to return in center |
---|
| 252 | } |
---|
| 253 | else if(findpos(actuelposition,possibleposition[41])){ |
---|
| 254 | setnewTarget(35,43); |
---|
| 255 | } |
---|
| 256 | else if(findpos(actuelposition,possibleposition[42])){ |
---|
| 257 | setnewTarget(34,43,54); |
---|
| 258 | } |
---|
| 259 | else if(findpos(actuelposition,possibleposition[43])){ |
---|
| 260 | setnewTarget(41,46); |
---|
| 261 | } |
---|
| 262 | else if(findpos(actuelposition,possibleposition[44])){ |
---|
| 263 | setnewTarget(40,66); |
---|
| 264 | } |
---|
| 265 | else if(findpos(actuelposition,possibleposition[45])){ |
---|
| 266 | setnewTarget(10,39,49); |
---|
| 267 | } |
---|
| 268 | else if(findpos(actuelposition,possibleposition[46])){ |
---|
| 269 | setnewTarget(43,47); |
---|
| 270 | } |
---|
| 271 | else if(findpos(actuelposition,possibleposition[47])){ |
---|
| 272 | setnewTarget(46,52,66); |
---|
| 273 | } |
---|
| 274 | else if(findpos(actuelposition,possibleposition[48])){ |
---|
| 275 | setnewTarget(49,51,66); |
---|
| 276 | } |
---|
| 277 | else if(findpos(actuelposition,possibleposition[49])){ |
---|
| 278 | setnewTarget(45,48); |
---|
| 279 | } |
---|
| 280 | else if(findpos(actuelposition,possibleposition[50])){ |
---|
| 281 | setnewTarget(51,61); |
---|
| 282 | } |
---|
| 283 | else if(findpos(actuelposition,possibleposition[51])){ |
---|
| 284 | setnewTarget(48,50); |
---|
| 285 | } |
---|
| 286 | else if(findpos(actuelposition,possibleposition[52])){ |
---|
| 287 | setnewTarget(47,53); |
---|
| 288 | } |
---|
| 289 | else if(findpos(actuelposition,possibleposition[53])){ |
---|
| 290 | setnewTarget(52,58); |
---|
| 291 | } |
---|
| 292 | else if(findpos(actuelposition,possibleposition[54])){ |
---|
| 293 | setnewTarget(42,55,57); |
---|
| 294 | } |
---|
| 295 | else if(findpos(actuelposition,possibleposition[55])){ |
---|
| 296 | setnewTarget(54,56); |
---|
| 297 | } |
---|
| 298 | else if(findpos(actuelposition,possibleposition[56])){ |
---|
| 299 | setnewTarget(55,57,65); |
---|
| 300 | } |
---|
| 301 | else if(findpos(actuelposition,possibleposition[57])){ |
---|
| 302 | setnewTarget(54,56,58,64); |
---|
| 303 | } |
---|
| 304 | else if(findpos(actuelposition,possibleposition[58])){ |
---|
| 305 | setnewTarget(53,57,59); |
---|
| 306 | } |
---|
| 307 | else if(findpos(actuelposition,possibleposition[59])){ |
---|
| 308 | setnewTarget(58,59,63); |
---|
| 309 | } |
---|
| 310 | else if(findpos(actuelposition,possibleposition[60])){ |
---|
| 311 | setnewTarget(59,61,62); |
---|
| 312 | } |
---|
| 313 | else if(findpos(actuelposition,possibleposition[61])){ |
---|
| 314 | setnewTarget(13,50,60); |
---|
| 315 | } |
---|
| 316 | else if(findpos(actuelposition,possibleposition[62])){ |
---|
| 317 | setnewTarget(16,60); |
---|
| 318 | } |
---|
| 319 | else if(findpos(actuelposition,possibleposition[63])){ |
---|
| 320 | setnewTarget(59,64); |
---|
| 321 | } |
---|
| 322 | else if(findpos(actuelposition,possibleposition[64])){ |
---|
| 323 | setnewTarget(57,63,65); |
---|
| 324 | } |
---|
| 325 | else if(findpos(actuelposition,possibleposition[65])){ |
---|
| 326 | setnewTarget(56,64); |
---|
| 327 | } |
---|
[11931] | 328 | else if(findpos(actuelposition,possibleposition[66])){ |
---|
| 329 | setnewTarget(47,48); |
---|
| 330 | } |
---|
[11903] | 331 | |
---|
| 332 | else{ |
---|
[11917] | 333 | this->resetGhost(); //Shouldn't happen... |
---|
[11903] | 334 | } //End of Position table |
---|
[11952] | 335 | lockmove = false; |
---|
[11903] | 336 | } |
---|
[11952] | 337 | |
---|
[11903] | 338 | } |
---|
| 339 | |
---|
[11992] | 340 | //Random choice of new target (not used in game, but useful) |
---|
[11903] | 341 | void PacmanGhost::setnewTarget(int firstdec){ |
---|
[11923] | 342 | |
---|
[11903] | 343 | decision = rand()%1; |
---|
| 344 | switch(decision){ |
---|
| 345 | case 0: |
---|
| 346 | this->target_x = possibleposition[firstdec].x; |
---|
| 347 | this->target_z = possibleposition[firstdec].z; |
---|
| 348 | this->ismoving = true; |
---|
| 349 | break; |
---|
| 350 | } |
---|
| 351 | } |
---|
| 352 | |
---|
[11992] | 353 | //Random choice of new target |
---|
[11927] | 354 | void PacmanGhost::setnewTarget(int firstdec, int seconddec){ |
---|
[11903] | 355 | decision = rand()%2; |
---|
| 356 | switch(decision){ |
---|
| 357 | case 0: |
---|
| 358 | this->target_x = possibleposition[firstdec].x; |
---|
| 359 | this->target_z = possibleposition[firstdec].z; |
---|
| 360 | this->ismoving = true; |
---|
| 361 | break; |
---|
| 362 | case 1: |
---|
| 363 | this->target_x = possibleposition[seconddec].x; |
---|
| 364 | this->target_z = possibleposition[seconddec].z; |
---|
| 365 | this->ismoving = true; |
---|
| 366 | break; |
---|
| 367 | } |
---|
[11927] | 368 | |
---|
[11903] | 369 | } |
---|
| 370 | |
---|
[11992] | 371 | //Random choice of new target |
---|
[11903] | 372 | void PacmanGhost::setnewTarget(int firstdec, int seconddec, int thirddec){ |
---|
[11927] | 373 | |
---|
[11903] | 374 | decision = rand()%3; |
---|
| 375 | switch(decision){ |
---|
| 376 | case 0: |
---|
| 377 | this->target_x = possibleposition[firstdec].x; |
---|
| 378 | this->target_z = possibleposition[firstdec].z; |
---|
| 379 | this->ismoving = true; |
---|
| 380 | break; |
---|
| 381 | case 1: |
---|
| 382 | this->target_x = possibleposition[seconddec].x; |
---|
| 383 | this->target_z = possibleposition[seconddec].z; |
---|
| 384 | this->ismoving = true; |
---|
| 385 | break; |
---|
| 386 | case 2: |
---|
| 387 | this->target_x = possibleposition[thirddec].x; |
---|
| 388 | this->target_z = possibleposition[thirddec].z; |
---|
| 389 | this->ismoving = true; |
---|
| 390 | break; |
---|
| 391 | } |
---|
[11927] | 392 | |
---|
[11903] | 393 | } |
---|
| 394 | |
---|
[11992] | 395 | //Random choice of new target |
---|
[11903] | 396 | void PacmanGhost::setnewTarget(int firstdec, int seconddec, int thirddec, int fourthdec){ |
---|
[11927] | 397 | |
---|
[11903] | 398 | decision = rand()%4; |
---|
| 399 | switch(decision){ |
---|
| 400 | case 0: |
---|
| 401 | this->target_x = possibleposition[firstdec].x; |
---|
| 402 | this->target_z = possibleposition[firstdec].z; |
---|
| 403 | this->ismoving = true; |
---|
| 404 | break; |
---|
| 405 | case 1: |
---|
| 406 | this->target_x = possibleposition[seconddec].x; |
---|
| 407 | this->target_z = possibleposition[seconddec].z; |
---|
| 408 | this->ismoving = true; |
---|
| 409 | break; |
---|
| 410 | case 2: |
---|
| 411 | this->target_x = possibleposition[thirddec].x; |
---|
| 412 | this->target_z = possibleposition[thirddec].z; |
---|
| 413 | this->ismoving = true; |
---|
| 414 | break; |
---|
| 415 | case 3: |
---|
| 416 | this->target_x = possibleposition[fourthdec].x; |
---|
| 417 | this->target_z = possibleposition[fourthdec].z; |
---|
| 418 | this->ismoving = true; |
---|
| 419 | break; |
---|
| 420 | } |
---|
[11927] | 421 | |
---|
[11903] | 422 | } |
---|
| 423 | |
---|
[11992] | 424 | //Change this with other ghost |
---|
[11947] | 425 | void PacmanGhost::changewith(PacmanGhost* otherghost){ |
---|
[11949] | 426 | |
---|
[11950] | 427 | while(lockmove){}; |
---|
[11992] | 428 | lockmove = true; //Prevent change of target while ghost is changed |
---|
[11949] | 429 | |
---|
[11945] | 430 | otherghost->setPosition(this->getPosition()); |
---|
| 431 | this->setPosition(0,-20,0); |
---|
[11992] | 432 | otherghost->target_x = this->target_x; |
---|
[11948] | 433 | otherghost->target_z = this->target_z; |
---|
[11945] | 434 | otherghost->ismoving = this->ismoving; |
---|
[11903] | 435 | |
---|
[11945] | 436 | this->dontmove = true; |
---|
| 437 | otherghost->dontmove = false; |
---|
[11949] | 438 | |
---|
[11950] | 439 | lockmove = false; |
---|
[11945] | 440 | } |
---|
[11903] | 441 | |
---|
[11992] | 442 | //Move ghost with rotation |
---|
[11903] | 443 | void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){ |
---|
[11976] | 444 | if(!dontmove){ |
---|
[11979] | 445 | this->setPosition(Vector3(actuelposition.x+speed*velocity.x*dt,10,actuelposition.z+speed*velocity.z*dt)); |
---|
[11992] | 446 | |
---|
| 447 | //Rotate ghost in the direction of movement |
---|
[11979] | 448 | if((abs(abs(velocity.x)-1)<0.1) && (abs(velocity.z-0)<0.1)) |
---|
[11978] | 449 | if(velocity.x<0){ |
---|
| 450 | this->setOrientation(Quaternion(Radian(-1.57), Vector3(0, 1, 0))); |
---|
[11976] | 451 | } |
---|
[11978] | 452 | else{ |
---|
| 453 | this->setOrientation(Quaternion(Radian(1.57), Vector3(0, 1, 0))); |
---|
[11976] | 454 | } |
---|
[11979] | 455 | if((abs(abs(velocity.z)-1)<0.1) && (abs(velocity.x-0)<0.1)) |
---|
[11978] | 456 | if(velocity.z<0){ |
---|
| 457 | this->setOrientation(Quaternion(Radian(3.14), Vector3(0, 1, 0))); |
---|
[11976] | 458 | } |
---|
[11978] | 459 | else{ |
---|
| 460 | this->setOrientation(Quaternion(Radian(0), Vector3(0, 1, 0))); |
---|
| 461 | } |
---|
| 462 | |
---|
[11976] | 463 | } |
---|
[11903] | 464 | } |
---|
| 465 | |
---|
[11992] | 466 | //Check if there is a collision |
---|
[11903] | 467 | bool PacmanGhost::findpos(Vector3 one, Vector3 other){ |
---|
[11945] | 468 | if((abs(one.x - other.x)<0.5) && (abs(one.y - other.y)<0.5) && (abs(one.z - other.z)<0.5)) return true; |
---|
[11922] | 469 | return false; |
---|
[11903] | 470 | } |
---|
| 471 | |
---|
[11992] | 472 | //Change ability to move |
---|
[11944] | 473 | void PacmanGhost::changemovability(){ |
---|
[11933] | 474 | if(dontmove){ |
---|
| 475 | dontmove = false;} |
---|
| 476 | else{ |
---|
| 477 | dontmove = true; |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
[11992] | 481 | //ResetGhost |
---|
[11903] | 482 | void PacmanGhost::resetGhost(){ |
---|
[11927] | 483 | |
---|
[11915] | 484 | this->setPosition(this->resetposition); |
---|
| 485 | this->ismoving = false; |
---|
| 486 | this->actuelposition = this->getPosition(); |
---|
| 487 | |
---|
| 488 | this->target_x = actuelposition.x; |
---|
| 489 | this->target_z = actuelposition.z; |
---|
[11927] | 490 | |
---|
[11903] | 491 | } |
---|
[11958] | 492 | |
---|
[11992] | 493 | //Increase speed of ghosts |
---|
[11959] | 494 | void PacmanGhost::levelupvelo(){ |
---|
[11979] | 495 | speed ++; |
---|
[11958] | 496 | } |
---|
[11915] | 497 | } |
---|