Changeset 10074 for code/branches/pickupsFS14/src/modules
- Timestamp:
- May 22, 2014, 3:05:46 PM (11 years ago)
- Location:
- code/branches/pickupsFS14/src/modules
- Files:
-
- 10 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickupsFS14/src/modules/invader/InvaderWeapon.cc
r9961 r10074 57 57 } 58 58 59 InvaderWeapon::~InvaderWeapon(){} 59 InvaderWeapon::~InvaderWeapon() 60 { 61 62 } 60 63 61 64 void InvaderWeapon::shot() -
code/branches/pickupsFS14/src/modules/jump/CMakeLists.txt
r10050 r10074 13 13 JumpFigure.cc 14 14 JumpItem.cc 15 JumpSpring.cc 16 JumpRocket.cc 17 JumpShield.cc 18 JumpPropeller.cc 19 JumpBoots.cc 15 20 JumpCenterpoint.cc 16 21 JumpScore.cc … … 24 29 orxonox 25 30 overlays 31 weapons 26 32 SOURCE_FILES ${JUMP_SRC_FILES} 27 33 ) -
code/branches/pickupsFS14/src/modules/jump/Jump.cc
r10050 r10074 53 53 #include "JumpEnemy.h" 54 54 #include "JumpFigure.h" 55 #include "JumpItem.h" 56 #include "JumpSpring.h" 57 #include "JumpRocket.h" 58 #include "JumpPropeller.h" 59 #include "JumpBoots.h" 60 #include "JumpShield.h" 55 61 56 62 #include "infos/PlayerInfo.h" … … 72 78 RegisterObject(Jump); 73 79 74 this->center_ = 0; 75 this->figure_ = 0; 76 this->camera = 0; 77 this->fakeAdded_ = false; 78 79 this->setHUDTemplate("JumpHUD"); 80 81 // Pre-set the timer, but don't start it yet. 82 this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Jump::startBall, this))); 83 this->starttimer_.stopTimer(); 84 85 this->scoreLimit_ = 10; 86 this->setConfigValues(); 80 center_ = 0; 81 figure_ = 0; 82 camera = 0; 83 84 setHUDTemplate("JumpHUD"); 85 86 scoreLimit_ = 10; 87 setConfigValues(); 87 88 } 88 89 … … 93 94 Jump::~Jump() 94 95 { 95 if ( this->isInitialized())96 if (isInitialized()) 96 97 { 97 this->cleanup();98 cleanup(); 98 99 } 99 100 } … … 102 103 { 103 104 SUPER(Jump, tick, dt); 104 105 105 if (figure_ != NULL) 106 106 { … … 108 108 Vector3 figureVelocity = figure_->getVelocity(); 109 109 110 if (figurePosition.z > totalScreenShift) 110 float boundary = totalScreenShift+center_->getCameraOffset(); 111 112 if (figurePosition.z > boundary) 111 113 { 112 screenShiftSinceLastUpdate += figurePosition.z - totalScreenShift;113 totalScreenShift = figurePosition.z ;114 screenShiftSinceLastUpdate += figurePosition.z - boundary; 115 totalScreenShift = figurePosition.z - center_->getCameraOffset(); 114 116 115 117 // Falls noetig neue Platformen im neuen Bereich einfuegen … … 117 119 { 118 120 screenShiftSinceLastUpdate -= center_->getSectionLength(); 119 addSection(); 121 if (sectionNumber_ > 2 && sectionNumber_%4 == 0 && rand()%2 == 0) 122 { 123 if (addAdventure(adventureNumber_) == false) 124 { 125 addSection(); 126 } 127 else 128 { 129 ++ adventureNumber_; 130 } 131 } 132 else 133 { 134 addSection(); 135 } 120 136 } 121 137 } 122 138 123 139 // Spiel verloren wegen Ansturz? 124 if (figurePosition.z < totalScreenShift - center_->getFieldDimension().y && figureVelocity.z < 0)140 if (figurePosition.z < totalScreenShift - center_->getFieldDimension().y + platformHeight_ && figureVelocity.z < 0) 125 141 { 126 142 end(); … … 128 144 129 145 // Schiessen 146 130 147 if (figure_->fireSignal) 131 148 { 132 149 figure_->fireSignal = false; 133 addProjectile(figurePosition.x, figurePosition.z , 0.0, 150.0);150 addProjectile(figurePosition.x, figurePosition.z + figure_->getPropellerPos()); 134 151 } 135 152 136 153 137 if ( this->camera != NULL)154 if (camera != NULL) 138 155 { 139 156 Vector3 cameraPosition = Vector3(0, totalScreenShift, 0); … … 248 265 } 249 266 250 251 267 // Gegner, die zu weit unten oder abgeschossen sind entfernen 268 ObjectList<JumpEnemy>::iterator beginEnemy = ObjectList<JumpEnemy>::begin(); 269 ObjectList<JumpEnemy>::iterator endEnemy = ObjectList<JumpEnemy>::end(); 270 ObjectList<JumpEnemy>::iterator itEnemy = beginEnemy; 271 Vector3 enemyPosition; 272 273 while (itEnemy != endEnemy) 274 { 275 enemyPosition = itEnemy->getPosition(); 276 if (enemyPosition.z < totalScreenShift - center_->getFieldDimension().y || itEnemy->dead_ == true) 277 { 278 ObjectList<JumpEnemy>::iterator temp = itEnemy; 279 ++ itEnemy; 280 center_->detach(*temp); 281 temp->destroy(); 282 } 283 else 284 { 285 ++ itEnemy; 286 } 287 } 288 289 // Items, die zu weit unten sind entfernen 290 ObjectList<JumpItem>::iterator beginItem = ObjectList<JumpItem>::begin(); 291 ObjectList<JumpItem>::iterator endItem = ObjectList<JumpItem>::end(); 292 ObjectList<JumpItem>::iterator itItem = beginItem; 293 Vector3 itemPosition; 294 295 while (itItem != endItem) 296 { 297 itemPosition = itItem->getPosition(); 298 299 WorldEntity* parent = itItem->getParent(); 300 301 if (itItem->attachedToFigure_ == false && itemPosition.z < totalScreenShift - center_->getFieldDimension().y && parent == center_) 302 { 303 ObjectList<JumpItem>::iterator temp = itItem; 304 ++ itItem; 305 center_->detach(*temp); 306 temp->destroy(); 307 } 308 else 309 { 310 ++ itItem; 311 } 312 } 252 313 } 253 314 … … 263 324 void Jump::cleanup() 264 325 { 265 if ( this->figure_ != NULL)326 if (figure_ != NULL) 266 327 { 267 328 //this->figure_->destroy(); 268 329 //this->figure_ = 0; 269 330 } 270 this->camera = 0; 271 } 272 273 /** 274 @brief 275 Starts the Jump minigame. 276 */ 331 camera = 0; 332 } 333 277 334 void Jump::start() 278 335 { 279 if ( this->center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place.336 if (center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place. 280 337 { 281 282 283 // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. 284 /*this->center_->attach(this->ball_); 285 this->ball_->setPosition(0, 0, 0); 286 this->ball_->setFieldDimension(this->center_->getFieldDimension()); 287 288 // Set the bats for the ball. 289 this->ball_->setFigure(this->figure_); 290 */ 291 292 // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint. 293 if (this->figure_ == NULL) 294 { 295 this->figure_ = new JumpFigure(this->center_->getContext()); 296 this->figure_->addTemplate(this->center_->getFigureTemplate()); 297 } 298 299 // Attach the bats to the centerpoint and set the parameters as specified in the centerpoint, the bats are attached to. 300 this->center_->attach(this->figure_); 301 this->figure_->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); 302 this->figure_->setFieldDimension(this->center_->getFieldDimension()); 338 if (figure_ == NULL) 339 { 340 figure_ = new JumpFigure(center_->getContext()); 341 figure_->addTemplate(center_->getFigureTemplate()); 342 figure_->InitializeAnimation(center_->getContext()); 343 } 344 345 center_->attach(figure_); 346 figure_->setPosition(0, 0, 0); 347 figure_->setFieldDimension(center_->getFieldDimension()); 303 348 } 304 349 else // If no centerpoint was specified, an error is thrown and the level is exited. … … 309 354 } 310 355 311 // Start the timer. After it has expired the ball is started.312 this->starttimer_.startTimer();313 314 356 // Set variable to temporarily force the player to spawn. 315 bool temp = this->bForceSpawn_;316 this->bForceSpawn_ = true;357 bool temp = bForceSpawn_; 358 bForceSpawn_ = true; 317 359 318 360 // Call start for the parent class. … … 320 362 321 363 // Reset the variable. 322 this->bForceSpawn_ = temp;323 324 if ( this->figure_ != NULL)364 bForceSpawn_ = temp; 365 366 if (figure_ != NULL) 325 367 { 326 this->camera = this->figure_->getCamera();368 camera = figure_->getCamera(); 327 369 } 328 370 329 371 totalScreenShift = 0.0; 330 372 screenShiftSinceLastUpdate = 0.0; 331 sectionNumber = 0; 373 sectionNumber_ = 0; 374 adventureNumber_ = 0; 332 375 333 376 addStartSection(); … … 347 390 // Call end for the parent class. 348 391 Deathmatch::end(); 349 }350 351 /**352 @brief353 Spawns players, and fills the rest up with bots.354 */355 void Jump::spawnPlayersIfRequested()356 {357 358 // first spawn human players to assign always the left bat to the player in singleplayer359 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)360 if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))361 this->spawnPlayer(it->first);362 // now spawn bots363 /*364 for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)365 if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_))366 this->spawnPlayer(it->first);367 */368 392 } 369 393 … … 384 408 this->players_[player].state_ = PlayerState::Alive; 385 409 } 386 // If both bats are taken.387 else388 {389 return;390 }391 392 410 } 393 411 … … 398 416 void Jump::playerScored(PlayerInfo* player, int score) 399 417 { 400 /* 401 Deathmatch::playerScored(player, score); 402 if (this->center_ != NULL) // If there is a centerpoint. 403 { 404 // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks. 405 if (player == this->getRightPlayer()) 406 this->center_->fireEvent(FireEventName(JumpCenterpoint, right)); 407 else if (player == this->getLeftPlayer()) 408 this->center_->fireEvent(FireEventName(JumpCenterpoint, left)); 409 410 // Also announce, that the player has scored. 411 if (player != NULL) 412 this->gtinfo_->sendAnnounceMessage(player->getName() + " scored"); 413 } 414 415 // If there is a ball present, reset its position, velocity and acceleration. 416 if (this->ball_ != NULL) 417 { 418 this->ball_->setPosition(Vector3::ZERO); 419 this->ball_->setVelocity(Vector3::ZERO); 420 this->ball_->setAcceleration(Vector3::ZERO); 421 this->ball_->setSpeed(0); 422 } 423 424 // If there are bats reset them to the middle position. 425 if (this->figure_[0] != NULL && this->figure_[1] != NULL) 426 { 427 this->figure_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); 428 this->figure_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0); 429 } 430 431 // If a player gets enough points, he won the game -> end of game 432 PlayerInfo* winningPlayer = NULL; 433 if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_) 434 winningPlayer = this->getLeftPlayer(); 435 else if (this->getRightPlayer() && this->getScore(this->getRightPlayer()) >= scoreLimit_) 436 winningPlayer = getLeftPlayerthis->getRightPlayer(); 437 438 if (winningPlayer) 439 { 440 ChatManager::message(winningPlayer->getName() + " has won!"); 441 this->end(); 442 } 443 444 // Restart the timer to start the ball. 445 this->starttimer_.startTimer(); 446 447 */ 418 448 419 } 449 420 … … 481 452 newPlatform->addTemplate(platformTemplate); 482 453 newPlatform->setPosition(Vector3(xPosition, 0.0, zPosition)); 483 newPlatform->setFieldDimension(center_->getFieldDimension());484 454 newPlatform->setFigure(this->figure_); 485 455 center_->attach(newPlatform); … … 487 457 } 488 458 489 void Jump::addPlatformStatic(float xPosition, float zPosition) 490 { 491 if (fakeAdded_ == false && rand()%5 == 0) 492 { 493 addPlatformFake(xPosition, zPosition); 494 } 495 else 496 { 497 JumpPlatformStatic* newPlatform = new JumpPlatformStatic(center_->getContext()); 498 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, zPosition); 499 } 500 } 501 502 void Jump::addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed) 459 JumpPlatformStatic* Jump::addPlatformStatic(float xPosition, float zPosition) 460 { 461 JumpPlatformStatic* newPlatform = new JumpPlatformStatic(center_->getContext()); 462 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, zPosition); 463 464 return newPlatform; 465 } 466 467 JumpPlatformHMove* Jump::addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed) 503 468 { 504 469 JumpPlatformHMove* newPlatform = new JumpPlatformHMove(center_->getContext()); 505 470 newPlatform->setProperties(leftBoundary, rightBoundary, speed); 506 471 addPlatform(newPlatform, center_->getPlatformHMoveTemplate(), xPosition, zPosition); 507 } 508 509 void Jump::addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed) 472 473 return newPlatform; 474 } 475 476 JumpPlatformVMove* Jump::addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed) 510 477 { 511 478 JumpPlatformVMove* newPlatform = new JumpPlatformVMove(center_->getContext()); 512 479 newPlatform->setProperties(lowerBoundary, upperBoundary, speed); 513 480 addPlatform(newPlatform, center_->getPlatformVMoveTemplate(), xPosition, zPosition); 514 } 515 516 void Jump::addPlatformDisappear(float xPosition, float zPosition) 481 482 return newPlatform; 483 } 484 485 JumpPlatformDisappear* Jump::addPlatformDisappear(float xPosition, float zPosition) 517 486 { 518 487 JumpPlatformDisappear* newPlatform = new JumpPlatformDisappear(center_->getContext()); 519 488 newPlatform->setProperties(true); 520 489 addPlatform(newPlatform, center_->getPlatformDisappearTemplate(), xPosition, zPosition); 521 } 522 523 void Jump::addPlatformTimer(float xPosition, float zPosition, float time, float variance) 490 491 return newPlatform; 492 } 493 494 JumpPlatformTimer* Jump::addPlatformTimer(float xPosition, float zPosition, float time, float variance) 524 495 { 525 496 float additionalTime = (float)(rand()%100)/(100*variance) - variance/2; … … 528 499 newPlatform->setProperties(time + additionalTime); 529 500 addPlatform(newPlatform, center_->getPlatformTimerTemplate(), xPosition, zPosition); 530 } 531 532 void Jump::addPlatformFake(float xPosition, float zPosition)533 { 534 fakeAdded_ = true;535 501 502 return newPlatform; 503 } 504 505 JumpPlatformFake* Jump::addPlatformFake(float xPosition, float zPosition) 506 { 536 507 JumpPlatformFake* newPlatform = new JumpPlatformFake(center_->getContext()); 537 508 addPlatform(newPlatform, center_->getPlatformFakeTemplate(), xPosition, zPosition); 538 509 newPlatform->setAngularVelocity(Vector3(0, 0, 2.0)); 539 } 540 541 542 void Jump::addProjectile(float xPosition, float zPosition, float xVelocity, float zVelocity) 510 511 return newPlatform; 512 } 513 514 515 void Jump::addProjectile(float xPosition, float zPosition) 543 516 { 544 517 JumpProjectile* newProjectile = new JumpProjectile(center_->getContext()); … … 547 520 newProjectile->addTemplate(center_->getProjectileTemplate()); 548 521 newProjectile->setPosition(Vector3(xPosition, 0.0, zPosition)); 549 newProjectile->setVelocity(Vector3(xVelocity, 0.0, zVelocity));550 522 newProjectile->setFieldDimension(center_->getFieldDimension()); 551 523 newProjectile->setFigure(this->figure_); … … 554 526 } 555 527 556 void Jump::addEnemy1(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 528 void Jump::addSpring(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 529 { 530 JumpSpring* newSpring = new JumpSpring(center_->getContext()); 531 if (newSpring != NULL && center_ != NULL) 532 { 533 newSpring->addTemplate(center_->getSpringTemplate()); 534 newSpring->setPosition(Vector3(xPosition, 0.0, zPosition)); 535 newSpring->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 536 newSpring->setFigure(figure_); 537 center_->attach(newSpring); 538 } 539 } 540 541 void Jump::addSpring(JumpPlatform* platform) 542 { 543 JumpSpring* newSpring = new JumpSpring(center_->getContext()); 544 if (newSpring != NULL && center_ != NULL) 545 { 546 newSpring->addTemplate(center_->getSpringTemplate()); 547 newSpring->setPosition(Vector3(0.0, 0.0, 0.0)); 548 newSpring->setProperties(-10.0, 10.0, -10.0, 10.0, 0.0, 0.0); 549 newSpring->setFigure(figure_); 550 platform->attach(newSpring); 551 } 552 } 553 554 void Jump::addRocket(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 555 { 556 JumpRocket* newRocket = new JumpRocket(center_->getContext()); 557 if (newRocket != NULL && center_ != NULL) 558 { 559 newRocket->addTemplate(center_->getRocketTemplate()); 560 newRocket->setPosition(Vector3(xPosition, 0.0, zPosition)); 561 newRocket->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 562 newRocket->setFigure(figure_); 563 center_->attach(newRocket); 564 } 565 } 566 567 void Jump::addRocket(JumpPlatform* platform) 568 { 569 JumpRocket* newRocket = new JumpRocket(center_->getContext()); 570 if (newRocket != NULL && center_ != NULL) 571 { 572 newRocket->addTemplate(center_->getRocketTemplate()); 573 newRocket->setPosition(Vector3(0.0, 0.0, 0.0)); 574 newRocket->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 575 newRocket->setFigure(figure_); 576 platform->attach(newRocket); 577 } 578 } 579 580 void Jump::addPropeller(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 581 { 582 JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); 583 if (newPropeller != NULL && center_ != NULL) 584 { 585 newPropeller->addTemplate(center_->getPropellerTemplate()); 586 newPropeller->setPosition(Vector3(xPosition, 0.0, zPosition)); 587 newPropeller->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 588 newPropeller->setFigure(figure_); 589 center_->attach(newPropeller); 590 } 591 } 592 593 void Jump::addPropeller(JumpPlatform* platform) 594 { 595 JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); 596 if (newPropeller != NULL && center_ != NULL) 597 { 598 newPropeller->addTemplate(center_->getPropellerTemplate()); 599 newPropeller->setPosition(Vector3(0.0, 0.0, 0.0)); 600 newPropeller->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 601 newPropeller->setFigure(figure_); 602 platform->attach(newPropeller); 603 } 604 } 605 606 void Jump::addBoots(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 607 { 608 JumpBoots* newBoots = new JumpBoots(center_->getContext()); 609 if (newBoots != NULL && center_ != NULL) 610 { 611 newBoots->addTemplate(center_->getBootsTemplate()); 612 newBoots->setPosition(Vector3(xPosition, 0.0, zPosition)); 613 newBoots->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 614 newBoots->setFigure(figure_); 615 center_->attach(newBoots); 616 } 617 } 618 619 void Jump::addBoots(JumpPlatform* platform) 620 { 621 JumpBoots* newBoots = new JumpBoots(center_->getContext()); 622 if (newBoots != NULL && center_ != NULL) 623 { 624 newBoots->addTemplate(center_->getBootsTemplate()); 625 newBoots->setPosition(Vector3(0.0, 0.0, 0.0)); 626 newBoots->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 627 newBoots->setFigure(figure_); 628 platform->attach(newBoots); 629 } 630 } 631 632 void Jump::addShield(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 633 { 634 JumpShield* newShield = new JumpShield(center_->getContext()); 635 if (newShield != NULL && center_ != NULL) 636 { 637 newShield->addTemplate(center_->getShieldTemplate()); 638 newShield->setPosition(Vector3(xPosition, 0.0, zPosition)); 639 newShield->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 640 newShield->setFigure(figure_); 641 center_->attach(newShield); 642 } 643 } 644 645 void Jump::addShield(JumpPlatform* platform) 646 { 647 JumpShield* newShield = new JumpShield(center_->getContext()); 648 if (newShield != NULL && center_ != NULL) 649 { 650 newShield->addTemplate(center_->getShieldTemplate()); 651 newShield->setPosition(Vector3(0.0, 0.0, 0.0)); 652 newShield->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 653 newShield->setFigure(figure_); 654 platform->attach(newShield); 655 } 656 } 657 658 void Jump::addEnemy(int type, float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 557 659 { 558 660 JumpEnemy* newEnemy = new JumpEnemy(center_->getContext()); 559 661 if (newEnemy != NULL && center_ != NULL) 560 662 { 561 newEnemy->addTemplate(center_->getEnemy1Template()); 663 switch (type) 664 { 665 case 1: 666 newEnemy->addTemplate(center_->getEnemy1Template()); 667 break; 668 case 2: 669 newEnemy->addTemplate(center_->getEnemy2Template()); 670 break; 671 case 3: 672 newEnemy->addTemplate(center_->getEnemy3Template()); 673 break; 674 case 4: 675 newEnemy->addTemplate(center_->getEnemy4Template()); 676 break; 677 default: 678 return; 679 } 680 562 681 newEnemy->setPosition(Vector3(xPosition, 0.0, zPosition)); 563 682 newEnemy->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); … … 573 692 574 693 float sectionLength = center_->getSectionLength(); 575 float platformLength = center_->getPlatformLength(); 576 577 for (float xPosition = -center_->getFieldDimension().x; xPosition <= center_->getFieldDimension().x; xPosition += platformLength) 694 695 newPlatform = new JumpPlatformStatic(center_->getContext()); 696 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), 0.0, -0.05*sectionLength); 697 698 platformWidth_ = newPlatform->getWidth(); 699 platformHeight_ = newPlatform->getHeight(); 700 701 for (float xPosition = platformWidth_; xPosition <= center_->getFieldDimension().x; xPosition += platformWidth_) 578 702 { 579 703 newPlatform = new JumpPlatformStatic(center_->getContext()); 580 704 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, -0.05*sectionLength); 705 newPlatform = new JumpPlatformStatic(center_->getContext()); 706 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), -xPosition, -0.05*sectionLength); 581 707 } 582 708 } … … 586 712 float fieldWidth = center_->getFieldDimension().x; 587 713 float sectionLength = center_->getSectionLength(); 588 float platformLength = center_->getPlatformLength(); 589 590 float sectionBegin = sectionNumber * sectionLength; 591 float sectionEnd = (1.0 + sectionNumber) * sectionLength; 592 593 int randPos1 = rand()%10; 594 int randPos2 = rand()%10; 595 int randPos3 = rand()%10; 596 int randPos4 = rand()%10; 597 598 if (rand()%5 == 0) 599 { 600 addEnemy1(randomXPosition(), sectionBegin + sectionLength/10, -fieldWidth, fieldWidth, sectionBegin + sectionLength/10, sectionBegin + sectionLength/10, 5.0, 0.0); 601 } 602 603 switch (rand()%12) 714 float sectionBegin = sectionNumber_ * sectionLength; 715 float sectionEnd = (1 + sectionNumber_) * sectionLength; 716 717 int numI = 6; 718 int numJ = 4; 719 720 enum PlatformType 721 { 722 PLATFORM_EMPTY, PLATFORM_STATIC, PLATFORM_HMOVE, PLATFORM_VMOVE, PLATFORM_DISAPPEAR, PLATFORM_TIMER, PLATFORM_FAKE 723 }; 724 725 enum ItemType 726 { 727 ITEM_NOTHING, ITEM_SPRING, ITEM_PROPELLER, ITEM_ROCKET, ITEM_BOOTS, ITEM_SHIELD 728 }; 729 730 struct PlatformMatrix 731 { 732 PlatformType type; 733 bool done; 734 } matrix[numI][numJ]; 735 736 737 for (int i = 0; i < numI; ++i) 738 { 739 for (int j = 0; j < numJ; ++j) 740 { 741 matrix[i][j].type = PLATFORM_EMPTY; 742 matrix[i][j].done = false; 743 } 744 } 745 PlatformType platformtype1; 746 PlatformType platformtype2; 747 ItemType itemType = ITEM_NOTHING; 748 749 if (rand()%2 == 0) 750 { 751 itemType = ITEM_SPRING; 752 } 753 else if (rand()%2 == 0 && sectionNumber_ > 3) 754 switch(rand()%4) 604 755 { 605 756 case 0: 606 // Doppelt statisch 607 for (int i = 0; i < 10; ++i) 608 { 609 for (int j = 0; j < 2; ++j) 610 { 611 addPlatformStatic(randomXPosition(2, j), sectionBegin + i*sectionLength/10); 612 } 613 } 757 itemType = ITEM_PROPELLER; 614 758 break; 615 759 case 1: 616 // Dreifach statisch 617 for (int i = 0; i < 10; ++i) 618 { 619 for (int j = 0; j < 3; ++j) 620 { 621 addPlatformStatic(randomXPosition(3, j), sectionBegin + i*sectionLength/10); 622 } 623 } 760 itemType = ITEM_ROCKET; 624 761 break; 625 762 case 2: 626 // statisch mit 1 horizontal 627 for (int i = 0; i < 10; ++i) 628 { 629 if (i == randPos1) 630 { 631 addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); 632 } 633 else 634 { 635 addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10); 636 } 637 } 763 itemType = ITEM_BOOTS; 638 764 break; 639 765 case 3: 640 // statisch mit 2 horizontal 641 for (int i = 0; i < 10; ++i) 642 { 643 if (i == randPos1 || i == randPos2) 766 itemType = ITEM_SHIELD; 767 break; 768 default: 769 break; 770 } 771 772 switch((sectionNumber_ > 28) ? rand()%29 : rand()%(sectionNumber_+1)) 773 { 774 case 0: 775 platformtype1 = PLATFORM_STATIC; 776 platformtype2 = PLATFORM_STATIC; 777 break; 778 case 1: 779 platformtype1 = PLATFORM_STATIC; 780 platformtype2 = PLATFORM_STATIC; 781 break; 782 case 2: 783 platformtype1 = PLATFORM_STATIC; 784 platformtype2 = PLATFORM_HMOVE; 785 break; 786 case 3: 787 platformtype1 = PLATFORM_STATIC; 788 platformtype2 = PLATFORM_DISAPPEAR; 789 break; 790 case 4: 791 platformtype1 = PLATFORM_STATIC; 792 platformtype2 = PLATFORM_VMOVE; 793 break; 794 case 5: 795 platformtype1 = PLATFORM_STATIC; 796 platformtype2 = PLATFORM_TIMER; 797 break; 798 case 6: 799 platformtype1 = PLATFORM_HMOVE; 800 platformtype2 = PLATFORM_STATIC; 801 break; 802 case 7: 803 platformtype1 = PLATFORM_HMOVE; 804 platformtype2 = PLATFORM_HMOVE; 805 break; 806 case 8: 807 platformtype1 = PLATFORM_HMOVE; 808 platformtype2 = PLATFORM_HMOVE; 809 break; 810 case 9: 811 platformtype1 = PLATFORM_HMOVE; 812 platformtype2 = PLATFORM_DISAPPEAR; 813 break; 814 case 10: 815 platformtype1 = PLATFORM_HMOVE; 816 platformtype2 = PLATFORM_VMOVE; 817 break; 818 case 11: 819 platformtype1 = PLATFORM_HMOVE; 820 platformtype2 = PLATFORM_TIMER; 821 break; 822 case 12: 823 platformtype1 = PLATFORM_DISAPPEAR; 824 platformtype2 = PLATFORM_STATIC; 825 break; 826 case 13: 827 platformtype1 = PLATFORM_DISAPPEAR; 828 platformtype2 = PLATFORM_HMOVE; 829 break; 830 case 14: 831 platformtype1 = PLATFORM_DISAPPEAR; 832 platformtype2 = PLATFORM_DISAPPEAR; 833 break; 834 case 15: 835 platformtype1 = PLATFORM_DISAPPEAR; 836 platformtype2 = PLATFORM_DISAPPEAR; 837 break; 838 case 16: 839 platformtype1 = PLATFORM_DISAPPEAR; 840 platformtype2 = PLATFORM_VMOVE; 841 break; 842 case 17: 843 platformtype1 = PLATFORM_DISAPPEAR; 844 platformtype2 = PLATFORM_TIMER; 845 break; 846 case 18: 847 platformtype1 = PLATFORM_VMOVE; 848 platformtype2 = PLATFORM_STATIC; 849 break; 850 case 19: 851 platformtype1 = PLATFORM_VMOVE; 852 platformtype2 = PLATFORM_HMOVE; 853 break; 854 case 20: 855 platformtype1 = PLATFORM_VMOVE; 856 platformtype2 = PLATFORM_DISAPPEAR; 857 break; 858 case 21: 859 platformtype1 = PLATFORM_VMOVE; 860 platformtype2 = PLATFORM_VMOVE; 861 break; 862 case 22: 863 platformtype1 = PLATFORM_VMOVE; 864 platformtype2 = PLATFORM_VMOVE; 865 break; 866 case 23: 867 platformtype1 = PLATFORM_VMOVE; 868 platformtype2 = PLATFORM_TIMER; 869 break; 870 case 24: 871 platformtype1 = PLATFORM_TIMER; 872 platformtype2 = PLATFORM_STATIC; 873 break; 874 case 25: 875 platformtype1 = PLATFORM_TIMER; 876 platformtype2 = PLATFORM_HMOVE; 877 break; 878 case 26: 879 platformtype1 = PLATFORM_TIMER; 880 platformtype2 = PLATFORM_DISAPPEAR; 881 break; 882 case 27: 883 platformtype1 = PLATFORM_TIMER; 884 platformtype2 = PLATFORM_VMOVE; 885 break; 886 case 28: 887 platformtype1 = PLATFORM_TIMER; 888 platformtype2 = PLATFORM_TIMER; 889 break; 890 default: 891 platformtype1 = PLATFORM_TIMER; 892 platformtype2 = PLATFORM_TIMER; 893 break; 894 } 895 896 // Fill Matrix with selected platform types 897 for (int i = 0; i < numI; ++ i) 898 { 899 for (int j = 0; j < numJ; ++ j) 900 { 901 if (rand()%(sectionNumber_+1) == 0) 902 { 903 matrix[i][j].type = platformtype1; 904 } 905 else 906 { 907 matrix[i][j].type = platformtype2; 908 } 909 matrix[i][j].done = false; 910 } 911 } 912 913 // Delete some platforms or replace them with fake platforms 914 if (platformtype1 == platformtype2 && sectionNumber_ > 10) 915 { 916 int j = rand()%numJ; 917 if (rand()%2 == 0) 918 { 919 for (int i = 0; i <= j; ++ i) 644 920 { 645 addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0);921 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 646 922 } 647 else 923 } 924 else 925 { 926 for (int i = 0; i <= j; ++ i) 648 927 { 649 addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10);928 matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; 650 929 } 651 930 } 931 } 932 933 std::vector<JumpPlatform*> platformList; 934 935 for (int i = 0; i < numI; ++ i) 936 { 937 for (int j = 0; j < numJ; ++ j) 938 { 939 if (matrix[i][j].done == false) 940 { 941 float xPosition = 0.0; 942 float zPosition = 0.0; 943 float leftBoundary = 0.0; 944 float rightBoundary = 0.0; 945 float lowerBoundary = 0.0; 946 float upperBoundary = 0.0; 947 float xVelocity = 0.0; 948 float zVelocity = 0.0; 949 950 switch(matrix[i][j].type) 951 { 952 case PLATFORM_EMPTY: 953 matrix[i][j].done = true; 954 break; 955 case PLATFORM_STATIC: 956 xPosition = randomXPosition(numJ, j); 957 zPosition = sectionBegin + i*sectionLength/numI; 958 platformList.push_back(addPlatformStatic(xPosition, zPosition)); 959 matrix[i][j].done = true; 960 break; 961 case PLATFORM_FAKE: 962 xPosition = randomXPosition(numJ, j); 963 zPosition = sectionBegin + i*sectionLength/numI; 964 platformList.push_back(addPlatformFake(xPosition, zPosition)); 965 matrix[i][j].done = true; 966 break; 967 case PLATFORM_TIMER: 968 xPosition = randomXPosition(numJ, j); 969 zPosition = sectionBegin + i*sectionLength/numI; 970 platformList.push_back(addPlatformTimer(xPosition, zPosition, 10.0, 1.5)); 971 matrix[i][j].done = true; 972 break; 973 case PLATFORM_DISAPPEAR: 974 xPosition = randomXPosition(numJ, j); 975 zPosition = sectionBegin + i*sectionLength/numI; 976 platformList.push_back(addPlatformDisappear(xPosition, zPosition)); 977 matrix[i][j].done = true; 978 break; 979 case PLATFORM_HMOVE: 980 xVelocity = randomSpeed(); 981 if (j <= numJ-3 && matrix[i][j+1].type == PLATFORM_HMOVE && matrix[i][j+2].type == PLATFORM_HMOVE && rand()%2 == 0) 982 { 983 leftBoundary = randomXPositionLeft(numJ, j); 984 rightBoundary = randomXPositionRight(numJ, j+2); 985 xPosition = randomPosition(leftBoundary, rightBoundary); 986 zPosition = sectionBegin + i*sectionLength/numI; 987 platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); 988 matrix[i][j].done = true; 989 matrix[i][j+1].done = true; 990 matrix[i][j+2].done = true; 991 } 992 else if (j <= numJ-2 && matrix[i][j+1].type == PLATFORM_HMOVE && rand()%2 == 0) 993 { 994 leftBoundary = randomXPositionLeft(numJ, j); 995 rightBoundary = randomXPositionRight(numJ, j+1); 996 xPosition = randomPosition(leftBoundary, rightBoundary); 997 zPosition = sectionBegin + i*sectionLength/numI; 998 platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); 999 matrix[i][j].done = true; 1000 matrix[i][j+1].done = true; 1001 } 1002 else 1003 { 1004 leftBoundary = randomXPositionLeft(numJ, j); 1005 rightBoundary = randomXPositionRight(numJ, j); 1006 xPosition = randomPosition(leftBoundary, rightBoundary); 1007 zPosition = sectionBegin + i*sectionLength/numI; 1008 platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); 1009 matrix[i][j].done = true; 1010 } 1011 break; 1012 case PLATFORM_VMOVE: 1013 zVelocity = randomSpeed(); 1014 if (i <= numI-3 && matrix[i+1][j].type == PLATFORM_VMOVE && matrix[i+2][j].type == PLATFORM_VMOVE && rand()%2 == 0) 1015 { 1016 lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); 1017 upperBoundary = randomZPositionUpper(numI, i+2, sectionBegin, sectionEnd); 1018 zPosition = randomPosition(lowerBoundary, upperBoundary); 1019 xPosition = randomXPosition(numJ, j); 1020 platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); 1021 matrix[i][j].done = true; 1022 matrix[i+1][j].done = true; 1023 matrix[i+2][j].done = true; 1024 } 1025 else if (i <= numI-2 && matrix[i+1][j].type == PLATFORM_VMOVE && rand()%2 == 0) 1026 { 1027 lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); 1028 upperBoundary = randomZPositionUpper(numI, i+1, sectionBegin, sectionEnd); 1029 zPosition = randomPosition(lowerBoundary, upperBoundary); 1030 xPosition = randomXPosition(numJ, j); 1031 platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); 1032 matrix[i][j].done = true; 1033 matrix[i+1][j].done = true; 1034 } 1035 else 1036 { 1037 lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); 1038 upperBoundary = randomZPositionUpper(numI, i, sectionBegin, sectionEnd); 1039 zPosition = randomPosition(lowerBoundary, upperBoundary); 1040 xPosition = randomXPosition(numJ, j); 1041 platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); 1042 matrix[i][j].done = true; 1043 } 1044 break; 1045 default: 1046 // ERROR 1047 break; 1048 1049 } 1050 1051 /*if (platformtype1 != PLATFORM_TIMER && platformtype2 != PLATFORM_TIMER) 1052 { 1053 switch (itemType) 1054 { 1055 case ITEM_SPRING: 1056 addSpring(xPosition, zPosition, leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 1057 itemType = ITEM_NOTHING; 1058 break; 1059 case ITEM_ROCKET: 1060 addRocket(xPosition, zPosition, leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 1061 itemType = ITEM_NOTHING; 1062 break; 1063 case ITEM_PROPELLER: 1064 addPropeller(xPosition, zPosition, leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 1065 itemType = ITEM_NOTHING; 1066 break; 1067 case ITEM_BOOTS: 1068 addBoots(xPosition, zPosition, leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 1069 itemType = ITEM_NOTHING; 1070 break; 1071 case ITEM_SHIELD: 1072 addShield(xPosition, zPosition, leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 1073 itemType = ITEM_NOTHING; 1074 break; 1075 default: 1076 // ERROR 1077 break; 1078 } 1079 }*/ 1080 } 1081 } 1082 } 1083 1084 //Add items 1085 int numNewPlatforms = platformList.size(); 1086 1087 if (numNewPlatforms > 0) 1088 { 1089 JumpPlatform* itemPlatform = platformList[rand()%numNewPlatforms]; 1090 1091 switch (ITEM_BOOTS) 1092 { 1093 case ITEM_SPRING: 1094 addSpring(itemPlatform); 1095 break; 1096 case ITEM_ROCKET: 1097 addRocket(itemPlatform); 1098 break; 1099 case ITEM_PROPELLER: 1100 addPropeller(itemPlatform); 1101 break; 1102 case ITEM_BOOTS: 1103 addBoots(itemPlatform); 1104 break; 1105 case ITEM_SHIELD: 1106 addShield(itemPlatform); 1107 break; 1108 default: 1109 break; 1110 } 1111 } 1112 1113 if (sectionNumber_ >= 5 && rand()%3 == 0) 1114 { 1115 // BEWEGUNG Verbessern, Grenzen anpassen !!!!!!!! Auch Vertikale Bewegung zulassen 1116 1117 1118 switch(rand()%4) 1119 { 1120 case 0: 1121 addEnemy(1, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 5.0, 0.0); 1122 break; 1123 case 1: 1124 addEnemy(2, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 5.0, 0.0); 1125 break; 1126 case 2: 1127 addEnemy(3, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 5.0, 0.0); 1128 break; 1129 case 3: 1130 addEnemy(4, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 5.0, 0.0); 1131 break; 1132 } 1133 } 1134 ++ sectionNumber_; 1135 } 1136 1137 bool Jump::addAdventure(int number) 1138 { 1139 float fieldWidth = center_->getFieldDimension().x; 1140 float sectionLength = center_->getSectionLength(); 1141 float sectionBegin = sectionNumber_ * sectionLength; 1142 sectionLength *= 2; 1143 1144 switch(number) 1145 { 1146 case 0: 1147 { 1148 int numI = 10; 1149 for (int i = 0; i < numI; ++ i) 1150 { 1151 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+i*sectionLength/numI); 1152 } 1153 break; 1154 } 1155 case 1: 1156 { 1157 int numI = 7; 1158 1159 addPlatformStatic(0.0, sectionBegin); 1160 for (int i = 1; i < numI; ++ i) 1161 { 1162 addPlatformStatic((fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); 1163 addPlatformStatic(-(fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); 1164 } 652 1165 break; 653 case 4:654 // statisch mit 3 horizontal 655 for (int i = 0; i < 10; ++i)656 {657 if (i == randPos1 || i == randPos2 || i == randPos3)1166 } 1167 case 2: 1168 { 1169 int numI = 5; 1170 for (int i = 0; i < numI; ++ i) 658 1171 { 659 addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); 1172 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin); 1173 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength/5); 1174 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength*2/5); 1175 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength*3/5); 1176 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength*4/5); 1177 addEnemy(4, (2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength/2, -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 0.0, 0.0); 660 1178 } 661 else 662 { 663 addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10); 664 } 665 } 666 break; 667 case 5: 668 // statisch mit 4 horizontal 669 for (int i = 0; i < 10; ++i) 670 { 671 if (i == randPos1 || i == randPos2 || i == randPos3 || i == randPos4) 672 { 673 addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); 674 } 675 else 676 { 677 addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10); 678 } 679 } 680 break; 681 // Einfach horizontal 682 case 6: 683 for (int i = 0; i < 10; ++i) 684 { 685 addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); 686 } 687 break; 688 // Doppelt horizontal 689 case 7: 690 for (int i = 0; i < 10; ++i) 691 { 692 float mediumPos = randomXPosition(3, 1); 693 addPlatformHMove(randomXPosition(3, 0), sectionBegin + i*sectionLength/10, -fieldWidth, mediumPos - platformLength/2, 30.0); 694 addPlatformHMove(randomXPosition(3, 2), sectionBegin + i*sectionLength/10, mediumPos+platformLength/2, fieldWidth, 30.0); 695 } 696 break; 697 // Einfach vertikal 698 case 8: 699 for (int i = 0; i < 7; ++i) 700 { 701 addPlatformVMove(-fieldWidth + i*fieldWidth*2/10, randomYPosition(sectionBegin, sectionEnd), sectionBegin, sectionEnd, 20.0); 702 } 703 break; 704 // Doppelt vertikal 705 case 9: 706 for (int i = 0; i < 14; ++i) 707 { 708 addPlatformVMove(-fieldWidth + i*fieldWidth*2/10, randomYPosition(sectionBegin, sectionEnd), sectionBegin, sectionEnd, 20.0); 709 } 710 break; 711 // Doppelt verschwindend 712 case 10: 713 for (int i = 0; i < 10; ++i) 714 { 715 for (int j = 0; j < 2; ++j) 716 { 717 addPlatformDisappear(randomXPosition(2, j), randomYPosition(sectionBegin, sectionEnd)); 718 } 719 } 720 break; 721 // Doppelt Timer 722 case 11: 723 for (int i = 0; i < 10; ++i) 724 { 725 for (int j = 0; j < 2; ++j) 726 { 727 addPlatformTimer(randomXPosition(2, j), randomYPosition(sectionBegin, sectionEnd), 6.0, 1.5); 728 } 729 } 730 break; 731 } 732 orxout() << "new section added with number "<< sectionNumber << endl; 733 734 fakeAdded_ = false; 735 736 ++ sectionNumber; 1179 break; 1180 } 1181 default: 1182 return false; 1183 } 1184 sectionNumber_ +=2; 1185 return true; 737 1186 } 738 1187 … … 746 1195 float Jump::randomXPosition(int totalColumns, int culomn) 747 1196 { 748 float fieldWidth = center_->getFieldDimension().x; 749 750 float width = 2*fieldWidth/totalColumns; 751 float leftBound = culomn*width-fieldWidth; 752 float platformLength = center_->getPlatformLength(); 753 754 return (float)(rand()%(int)(width-platformLength)) + leftBound + platformLength/2; 755 } 756 757 float Jump::randomYPosition(float lowerBoundary, float upperBoundary) 758 { 1197 float fieldWidth = center_->getFieldDimension().x; //Width of the half field 1198 1199 float halfWidth = fieldWidth/totalColumns; //Width of a half column 1200 float leftBound = culomn*halfWidth*2-fieldWidth; //Left beginning of the column 1201 float rightBound = leftBound + 2*halfWidth; 1202 1203 return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); 1204 } 1205 1206 float Jump::randomXPositionLeft(int totalColumns, int culomn) 1207 { 1208 float fieldWidth = center_->getFieldDimension().x; //Width of the half field 1209 1210 float halfWidth = fieldWidth/totalColumns; //Width of a half column 1211 float leftBound = culomn*halfWidth*2-fieldWidth; //LeftBeginning of the column 1212 float rightBound = leftBound + 2*halfWidth/3; 1213 1214 return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); 1215 } 1216 1217 float Jump::randomXPositionRight(int totalColumns, int culomn) 1218 { 1219 float fieldWidth = center_->getFieldDimension().x; //Width of the half field 1220 1221 float halfWidth = fieldWidth/totalColumns; //Width of a half column 1222 float rightBound = (culomn+1)*halfWidth*2-fieldWidth; 1223 float leftBound = rightBound - 2*halfWidth/3; 1224 return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); 1225 } 1226 1227 float Jump::randomZPosition(int totalRows, int row, float sectionBegin, float SectionEnd) 1228 { 1229 float fieldHeight = SectionEnd - sectionBegin; //Heigt of the half field 1230 float halfHeight = fieldHeight/totalRows; //Height of a half row 1231 float lowerBound = row*halfHeight*2+sectionBegin; //Lower beginning of the row 1232 float upperBound = lowerBound + 2*halfHeight; 1233 1234 return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); 1235 } 1236 1237 float Jump::randomZPositionLower(int totalRows, int row, float sectionBegin, float SectionEnd) 1238 { 1239 float fieldHeight = SectionEnd - sectionBegin; //Heigt of the half field 1240 float rowHeight = fieldHeight/totalRows; //Height of a row 1241 float lowerBound = row*rowHeight+sectionBegin; //Lower beginning of the row 1242 float upperBound = lowerBound + rowHeight/3; 1243 1244 return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); 1245 } 1246 1247 float Jump::randomZPositionUpper(int totalRows, int row, float sectionBegin, float SectionEnd) 1248 { 1249 float fieldHeight = SectionEnd - sectionBegin; //Heigt of the half field 1250 float rowHeight = fieldHeight/totalRows; //Height of a row 1251 float lowerBound = (row+1)*rowHeight+sectionBegin; //Upper end of the row 1252 float upperBound = lowerBound - rowHeight/3; 1253 1254 return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); 1255 } 1256 1257 float Jump::randomPosition(float lowerBoundary, float upperBoundary) 1258 { 1259 if (lowerBoundary >= upperBoundary) 1260 { 1261 return (lowerBoundary + upperBoundary)/2; 1262 } 1263 759 1264 return (float)(rand()%(int)(100*(upperBoundary - lowerBoundary)))/100 + lowerBoundary; 760 1265 } 761 1266 1267 float Jump::randomSpeed() 1268 { 1269 float platformSpeed = center_->getPlatformSpeed(); 1270 return randomPosition(0.5*platformSpeed, 1.5*platformSpeed); 1271 } 1272 762 1273 int Jump::getScore(PlayerInfo* player) const 763 1274 { 764 return sectionNumber - 2; 765 } 766 1275 return sectionNumber_ - 2; 1276 } 1277 1278 bool Jump::getDead(PlayerInfo* player) const 1279 { 1280 return figure_->dead_; 1281 } 767 1282 } -
code/branches/pickupsFS14/src/modules/jump/Jump.h
r10050 r10074 81 81 82 82 int getScore(PlayerInfo* player) const; 83 bool getDead(PlayerInfo* player) const; 83 84 84 85 /** … … 87 88 */ 88 89 void setCenterpoint(JumpCenterpoint* center) 89 { this->center_ = center; }90 { center_ = center; } 90 91 void setConfigValues(); //!< Makes scoreLimit configurable. 91 92 … … 93 94 94 95 protected: 95 virtual void spawnPlayersIfRequested(); //!< Spawns players, and fills the rest up with bots.96 97 96 void startBall(); //!< Starts the ball with some default speed. 98 97 void cleanup(); //!< Cleans up the Gametype by destroying the ball and the bats. … … 100 99 virtual void addPlatform(JumpPlatform* newPlatform, std::string platformTemplate, float xPosition, float zPosition); 101 100 102 virtual void addPlatformStatic(float xPosition, float zPosition); 103 virtual void addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed); 104 virtual void addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed); 105 virtual void addPlatformDisappear(float xPosition, float zPosition); 106 virtual void addPlatformTimer(float xPosition, float zPosition, float time, float variance); 107 virtual void addPlatformFake(float xPosition, float zPosition); 108 virtual void addProjectile(float xPosition, float zPosition, float xVelocity, float zVelocity); 109 virtual void addEnemy1(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity); 101 virtual JumpPlatformStatic* addPlatformStatic(float xPosition, float zPosition); 102 virtual JumpPlatformHMove* addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed); 103 virtual JumpPlatformVMove* addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed); 104 virtual JumpPlatformDisappear* addPlatformDisappear(float xPosition, float zPosition); 105 virtual JumpPlatformTimer* addPlatformTimer(float xPosition, float zPosition, float time, float variance); 106 virtual JumpPlatformFake* addPlatformFake(float xPosition, float zPosition); 107 virtual void addProjectile(float xPosition, float zPosition); 108 virtual void addEnemy(int type, float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity); 109 virtual void addSpring(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity); 110 virtual void addSpring(JumpPlatform* platform); 111 virtual void addRocket(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity); 112 virtual void addRocket(JumpPlatform* platform); 113 virtual void addPropeller(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity); 114 virtual void addPropeller(JumpPlatform* platform); 115 virtual void addBoots(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity); 116 virtual void addBoots(JumpPlatform* platform); 117 virtual void addShield(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity); 118 virtual void addShield(JumpPlatform* platform); 110 119 111 120 virtual void addStartSection(); 112 121 virtual void addSection(); 122 virtual bool addAdventure(int number); 113 123 114 124 virtual float randomXPosition(); 115 125 virtual float randomXPosition(int totalColumns, int culomn); 116 virtual float randomYPosition(float lowerBoundary, float upperBoundary); 126 virtual float randomXPositionLeft(int totalColumns, int culomn); 127 virtual float randomXPositionRight(int totalColumns, int culomn); 128 virtual float randomZPosition(int totalRows, int row, float sectionBegin, float SectionEnd); 129 virtual float randomZPositionLower(int totalRows, int row, float sectionBegin, float SectionEnd); 130 virtual float randomZPositionUpper(int totalRows, int row, float sectionBegin, float SectionEnd); 131 132 virtual float randomPosition(float lowerBoundary, float upperBoundary); 133 virtual float randomSpeed(); 117 134 118 135 WeakPtr<JumpCenterpoint> center_; //!< The playing field. 119 136 WeakPtr<JumpFigure> figure_; //!< The two bats. 120 137 WeakPtr<Camera> camera; 121 Timer starttimer_; //!< A timer to delay the start of the game.122 138 int scoreLimit_; //!< If a player scored that much points, the game is ended. 123 139 124 140 float totalScreenShift; 125 141 float screenShiftSinceLastUpdate; 126 int sectionNumber; 127 128 bool fakeAdded_; 142 int sectionNumber_; 143 int adventureNumber_; 144 float platformWidth_; 145 float platformHeight_; 129 146 }; 130 147 } -
code/branches/pickupsFS14/src/modules/jump/JumpCenterpoint.cc
r10050 r10074 55 55 height_ = 120; 56 56 sectionLength_ = 120; 57 platformSpeed_ = 20.0; 57 58 58 this->checkGametype();59 checkGametype(); 59 60 } 60 61 … … 69 70 XMLPortParam(JumpCenterpoint, "dimension", setFieldDimension, getFieldDimension, xmlelement, mode); 70 71 XMLPortParam(JumpCenterpoint, "sectionLength", setSectionLength, getSectionLength, xmlelement, mode); 71 XMLPortParam(JumpCenterpoint, "platformLength", setPlatformLength, getPlatformLength, xmlelement, mode); 72 XMLPortParam(JumpCenterpoint, "platformSpeed", setPlatformSpeed, getPlatformSpeed, xmlelement, mode); 73 XMLPortParam(JumpCenterpoint, "cameraOffset", setCameraOffset, getCameraOffset, xmlelement, mode); 72 74 XMLPortParam(JumpCenterpoint, "platformStaticTemplate", setPlatformStaticTemplate, getPlatformStaticTemplate, xmlelement, mode); 73 75 XMLPortParam(JumpCenterpoint, "platformHMoveTemplate", setPlatformHMoveTemplate, getPlatformHMoveTemplate, xmlelement, mode); … … 78 80 XMLPortParam(JumpCenterpoint, "figureTemplate", setFigureTemplate, getFigureTemplate, xmlelement, mode); 79 81 XMLPortParam(JumpCenterpoint, "projectileTemplate", setProjectileTemplate, getProjectileTemplate, xmlelement, mode); 82 XMLPortParam(JumpCenterpoint, "springTemplate", setSpringTemplate, getSpringTemplate, xmlelement, mode); 83 XMLPortParam(JumpCenterpoint, "rocketTemplate", setRocketTemplate, getRocketTemplate, xmlelement, mode); 84 XMLPortParam(JumpCenterpoint, "propellerTemplate", setPropellerTemplate, getPropellerTemplate, xmlelement, mode); 85 XMLPortParam(JumpCenterpoint, "bootsTemplate", setBootsTemplate, getBootsTemplate, xmlelement, mode); 86 XMLPortParam(JumpCenterpoint, "shieldTemplate", setShieldTemplate, getShieldTemplate, xmlelement, mode); 80 87 XMLPortParam(JumpCenterpoint, "enemy1Template", setEnemy1Template, getEnemy1Template, xmlelement, mode); 88 XMLPortParam(JumpCenterpoint, "enemy2Template", setEnemy2Template, getEnemy2Template, xmlelement, mode); 89 XMLPortParam(JumpCenterpoint, "enemy3Template", setEnemy3Template, getEnemy3Template, xmlelement, mode); 90 XMLPortParam(JumpCenterpoint, "enemy4Template", setEnemy4Template, getEnemy4Template, xmlelement, mode); 81 91 } 82 92 … … 90 100 91 101 // Check, whether it's still Jump. 92 this->checkGametype();102 checkGametype(); 93 103 } 94 104 -
code/branches/pickupsFS14/src/modules/jump/JumpCenterpoint.h
r10050 r10074 99 99 @endcode 100 100 As can be seen, there are actually two templates. The first template is needed to set the camera for the @ref orxonox::JumpFigure "JumpFigure". The second template ist the actual template for the @ref orxonox::JumpFigure "JumpFigure", the template for the camera position is added and a @ref orxonox::Model "Model" for the @ref orxonox::JumpFigure "JumpFigure" is attached. 101 101 propellerTemplate_ 102 102 Finally the JumpCenterpoint is created. 103 103 @code … … 171 171 { return this->projectileTemplate_; } 172 172 173 void setSpringTemplate(const std::string& newTemplate) 174 { this->springTemplate_ = newTemplate; } 175 176 const std::string& getSpringTemplate() const 177 { return this->springTemplate_; } 178 179 void setRocketTemplate(const std::string& newTemplate) 180 { this->rocketTemplate_ = newTemplate; } 181 182 const std::string& getRocketTemplate() const 183 { return this->rocketTemplate_; } 184 185 void setPropellerTemplate(const std::string& newTemplate) 186 { this->propellerTemplate_ = newTemplate; } 187 188 const std::string& getPropellerTemplate() const 189 { return this->propellerTemplate_; } 190 191 void setBootsTemplate(const std::string& newTemplate) 192 { this->bootsTemplate_ = newTemplate; } 193 194 const std::string& getBootsTemplate() const 195 { return this->bootsTemplate_; } 196 197 void setShieldTemplate(const std::string& newTemplate) 198 { this->shieldTemplate_ = newTemplate; } 199 200 const std::string& getShieldTemplate() const 201 { return this->shieldTemplate_; } 202 173 203 void setFigureTemplate(const std::string& newTemplate) 174 204 { this->figureTemplate_ = newTemplate; } … … 182 212 const std::string& getEnemy1Template() const 183 213 { return this->enemy1Template_; } 214 215 void setEnemy2Template(const std::string& newTemplate) 216 { this->enemy2Template_ = newTemplate; } 217 218 const std::string& getEnemy2Template() const 219 { return this->enemy2Template_; } 220 221 void setEnemy3Template(const std::string& newTemplate) 222 { this->enemy3Template_ = newTemplate; } 223 224 const std::string& getEnemy3Template() const 225 { return this->enemy3Template_; } 226 227 void setEnemy4Template(const std::string& newTemplate) 228 { this->enemy4Template_ = newTemplate; } 229 230 const std::string& getEnemy4Template() const 231 { return this->enemy4Template_; } 184 232 185 233 … … 210 258 { return sectionLength_; } 211 259 212 /**213 @brief Set the dimensions of the playing field.214 @param dimension A vector with the width of the playing field as first component and the height as second. 215 */216 void setPlatformLength(const float platformLength)217 { this->platformLength_ = platformLength; } 218 /**219 @brief Get the dimensions of the playing field.220 @return Returns a vector with the width of the playing field as first component and the height as second. 221 */222 float getPlatformLength() const223 { return platformLength_; } 260 void setPlatformSpeed(const float platformSpeed) 261 { this->platformSpeed_ = platformSpeed; } 262 263 float getPlatformSpeed() const 264 { return platformSpeed_; } 265 266 void setCameraOffset(const float cameraOffset) 267 { this->cameraOffset_ = cameraOffset; } 268 269 float getCameraOffset() const 270 { return cameraOffset_; } 271 224 272 225 273 private: … … 233 281 std::string platformFakeTemplate_; //!< The template for the ball. 234 282 std::string projectileTemplate_; //!< The template for the ball. 283 std::string springTemplate_; //!< The template for the ball. 284 std::string rocketTemplate_; //!< The template for the ball. 285 std::string propellerTemplate_; //!< The template for the ball. 286 std::string bootsTemplate_; //!< The template for the ball. 287 std::string shieldTemplate_; //!< The template for the ball. 235 288 std::string figureTemplate_; //!< The template for the bats. 236 289 std::string enemy1Template_; //!< The template for the bats. 290 std::string enemy2Template_; //!< The template for the bats. 291 std::string enemy3Template_; //!< The template for the bats. 292 std::string enemy4Template_; //!< The template for the bats. 237 293 238 294 float width_; //!< The height of the playing field. 239 295 float height_; //!< The width of the playing field. 240 296 float sectionLength_; //!< Height of one section 241 float platformLength_; // Avoids intersecting platforms 297 float platformSpeed_; //!< Height of one section 298 float cameraOffset_; //!< Height of one section 242 299 }; 243 300 } -
code/branches/pickupsFS14/src/modules/jump/JumpEnemy.cc
r10050 r10074 56 56 RegisterObject(JumpEnemy); 57 57 58 this->figure_ = 0; 58 dead_ = false; 59 figure_ = 0; 60 width_ = 0.0; 61 height_ = 0.0; 62 setPosition(Vector3(0,0,0)); 63 setVelocity(Vector3(0,0,0)); 64 setAcceleration(Vector3(0,0,0)); 59 65 setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 60 this->setPosition(Vector3(0,0,0));61 this->setVelocity(Vector3(0,0,0));62 this->setAcceleration(Vector3(0,0,0));63 66 } 64 67 … … 82 85 { 83 86 SUPER(JumpEnemy, XMLPort, xmlelement, mode); 87 88 XMLPortParam(JumpEnemy, "height", setHeight, getHeight, xmlelement, mode); 89 XMLPortParam(JumpEnemy, "width", setWidth, getWidth, xmlelement, mode); 84 90 } 85 91 … … 116 122 117 123 124 // Interact with Figure 125 Vector3 enemyPosition = getPosition(); 126 127 if (figure_ != NULL) 128 { 129 Vector3 figurePosition = figure_->getPosition(); 130 if(figurePosition.x > enemyPosition.x-width_ && figurePosition.x < enemyPosition.x+width_ && figurePosition.z > enemyPosition.z-height_ && figurePosition.z < enemyPosition.z+height_) 131 { 132 touchFigure(); 133 } 134 } 118 135 } 119 136 … … 141 158 void JumpEnemy::touchFigure() 142 159 { 143 160 if (dead_ == false) 161 { 162 figure_->CollisionWithEnemy(this); 163 } 144 164 } 145 165 } -
code/branches/pickupsFS14/src/modules/jump/JumpEnemy.h
r10050 r10074 87 87 { return Vector2(this->fieldWidth_, this->fieldHeight_); } 88 88 89 void setWidth(const float width) 90 { this->width_ = width; } 91 float getWidth() const 92 { return width_; } 93 void setHeight(const float height) 94 { this->height_ = height; } 95 float getHeight() const 96 { return height_; } 97 89 98 virtual void setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed); 90 99 91 100 void setFigure(WeakPtr<JumpFigure> bats); //!< Set the bats for the ball. 101 virtual void touchFigure(); 102 bool dead_; 103 protected: 92 104 93 virtual void touchFigure(); 105 float width_; 106 float height_; 94 107 95 protected:96 108 float fieldWidth_; //!< The width of the playing field. 97 109 float fieldHeight_; //!< The height of the playing field. -
code/branches/pickupsFS14/src/modules/jump/JumpFigure.cc
r10050 r10074 49 49 RegisterObject(JumpFigure); 50 50 51 this->movement_ = 0; 52 this->bMoveLocal_ = false; 53 this->length_ = 0.25; 54 this->fieldWidth_ = 180; 55 this->bSteadiedPosition_ = false; 51 leftHand_ = NULL; 52 rightHand_ = NULL; 53 54 fieldHeight_ = 0; 55 fieldWidth_ = 0; 56 57 jumpSpeed_ = 0.0; 58 handSpeed_ = 0.0; 59 handMaxAngle_ = 0.0; 60 handMinAngle_ = 0.0; 61 rocketPos_ = 0.0; 62 propellerPos_ = 0.0; 63 bootsPos_ = 0.0; 56 64 57 65 moveUpPressed = false; … … 66 74 mouseFactor_ = 75.0; 67 75 maxFireRate = 0.3; 76 77 handAngle_ = 0.0; 78 animateHands_ = false; 79 turnUp_ = false; 80 81 rocketActive_ = false; 82 propellerActive_ = false; 83 bootsActive_ = false; 84 shieldActive_ = false; 85 rocketSpeed_ = 0.0; 86 propellerSpeed_ = 0.0; 87 88 dead_ = false; 68 89 } 69 90 … … 76 97 SUPER(JumpFigure, XMLPort, xmlelement, mode); 77 98 XMLPortParam(JumpFigure, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode); 99 XMLPortParam(JumpFigure, "modelLefthand", setModelLeftHand, getModelLeftHand, xmlelement, mode); 100 XMLPortParam(JumpFigure, "modelRighthand", setModelRightHand, getModelRightHand, xmlelement, mode); 101 XMLPortParam(JumpFigure, "rocketPos", setRocketPos, getRocketPos, xmlelement, mode); 102 XMLPortParam(JumpFigure, "propellerPos", setPropellerPos, getPropellerPos, xmlelement, mode); 103 XMLPortParam(JumpFigure, "bootsPos", setBootsPos, getBootsPos, xmlelement, mode); 104 XMLPortParam(JumpFigure, "jumpSpeed", setJumpSpeed, getJumpSpeed, xmlelement, mode); 105 XMLPortParam(JumpFigure, "rocketSpeed", setRocketSpeed, getRocketSpeed, xmlelement, mode); 106 XMLPortParam(JumpFigure, "propellerSpeed", setPropellerSpeed, getPropellerSpeed, xmlelement, mode); 107 XMLPortParam(JumpFigure, "handMinAngle", setHandMinAngle, getHandMinAngle, xmlelement, mode); 108 XMLPortParam(JumpFigure, "handMaxAngle", setHandMaxAngle, getHandMaxAngle, xmlelement, mode); 109 XMLPortParam(JumpFigure, "handSpeed", setHandSpeed, getHandSpeed, xmlelement, mode); 78 110 } 79 111 … … 90 122 91 123 // If the bat is controlled (but not over the network). 92 if ( this->hasLocalController())124 if (hasLocalController()) 93 125 { 94 126 timeSinceLastFire += dt; 95 127 96 /*if (this->movement_ != 0) 97 { 98 // The absolute value of the movement is restricted to be lesser or equal than the speed of the bat. 99 this->movement_ = clamp(this->movement_, -1.0f, 1.0f) * this->speed_; 100 101 // If moveRightLeft() is used the movement is dependento on wehther it is the right or the left bat, so, it is i.e. dependent on the orientation of the bat. 102 if (this->bMoveLocal_) 103 this->setVelocity(this->getOrientation() * Vector3(this->movement_, 0, 0)); 104 else 105 this->setVelocity(0, 0, this->movement_); 106 107 this->movement_ = 0; 108 this->bSteadiedPosition_ = false; 109 } 110 // If there is no movement but the position has not been steadied, the velocity is set to zero and the position is reaffirmed. 111 else if (!this->bSteadiedPosition_) 112 { 113 // To ensure network synchronicity 114 this->setVelocity(0, 0, 0); 115 this->setPosition(this->getPosition()); 116 this->bSteadiedPosition_ = true; 117 }*/ 118 119 128 // Move up/down 120 129 Vector3 velocity = getVelocity(); 121 122 velocity.z -= gravityAcceleration; 123 124 /*if (moveLeftPressed == true) 125 { 126 velocity.x = -accelerationFactor; 127 moveLeftPressed = false; 128 } 129 if (moveRightPressed == true) 130 { 131 velocity.x = accelerationFactor; 132 moveRightPressed = false; 133 }*/ 134 135 velocity.x = -mouseFactor_*horizontalSpeed; 136 130 if (rocketActive_ == true) 131 { 132 velocity.z = rocketSpeed_; 133 } 134 else if (propellerActive_ == true) 135 { 136 velocity.z = propellerSpeed_; 137 } 138 else 139 { 140 velocity.z -= gravityAcceleration; 141 } 142 143 // Animate Hands 144 if (animateHands_ == true) 145 { 146 if (turnUp_ == true) 147 { 148 handAngle_ += handSpeed_ * dt; 149 } 150 else 151 { 152 handAngle_ -= handSpeed_ * dt; 153 } 154 if (handAngle_ > handMaxAngle_) 155 { 156 turnUp_ = false; 157 } 158 if (handAngle_ <= handMinAngle_) 159 { 160 animateHands_ = false; 161 } 162 163 if (leftHand_ != NULL) 164 { 165 leftHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(-handAngle_)); 166 } 167 if (rightHand_ != NULL) 168 { 169 rightHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(handAngle_)); 170 } 171 } 172 173 // Move left/right 174 if (dead_ == false) 175 { 176 velocity.x = -mouseFactor_*horizontalSpeed; 177 } 178 else 179 { 180 velocity.x = 0.0; 181 } 182 183 // Cheats 137 184 if (moveUpPressed == true) 138 185 { 139 186 velocity.z = 200.0f; 140 187 moveUpPressed = false; 188 dead_ = false; 141 189 } 142 190 if (moveDownPressed == true) … … 146 194 147 195 setVelocity(velocity); 196 148 197 149 198 if (firePressed && timeSinceLastFire >= maxFireRate) … … 156 205 } 157 206 158 Vector3 position = this->getPosition();159 207 // Move through the left and right screen boundaries 208 Vector3 position = getPosition(); 160 209 if (position.x < -fieldWidth_*1.1) 161 210 { … … 166 215 position.x = -fieldWidth_*1.1; 167 216 } 168 169 this->setPosition(position); 170 217 setPosition(position); 218 219 // Reset key variables 171 220 moveUpPressed = false; 172 221 moveDownPressed = false; … … 178 227 void JumpFigure::JumpFromPlatform(JumpPlatform* platform) 179 228 { 180 Vector3 velocity = getVelocity(); 181 velocity.z = 200.0f; 182 setVelocity(velocity); 183 } 184 229 if (dead_ == false) 230 { 231 Vector3 velocity = getVelocity(); 232 velocity.z = (bootsActive_ ? 1.2*jumpSpeed_ : jumpSpeed_); 233 setVelocity(velocity); 234 235 animateHands_ = true; 236 handAngle_ = 0.0; 237 turnUp_ = true; 238 } 239 } 240 241 void JumpFigure::JumpFromSpring(JumpSpring* spring) 242 { 243 if (dead_ == false) 244 { 245 Vector3 velocity = getVelocity(); 246 velocity.z = 1.2*jumpSpeed_; 247 setVelocity(velocity); 248 } 249 } 250 251 void JumpFigure::CollisionWithEnemy(JumpEnemy* enemy) 252 { 253 if (rocketActive_ == false && propellerActive_ == false && shieldActive_ == false) 254 { 255 dead_ = true; 256 } 257 } 258 259 bool JumpFigure::StartRocket(JumpRocket* rocket) 260 { 261 if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) 262 { 263 attach(rocket); 264 rocket->setPosition(0.0, rocketPos_, 0.0); 265 rocket->setVelocity(0.0, 0.0, 0.0); 266 rocketActive_ = true; 267 268 return true; 269 } 270 271 return false; 272 } 273 274 void JumpFigure::StopRocket(JumpRocket* rocket) 275 { 276 rocket->setPosition(0.0, 0.0, -1000.0); 277 rocket->setVelocity(0.0, 0.0, 0.0); 278 detach(rocket); 279 rocket->destroy(); 280 rocketActive_ = false; 281 } 282 283 bool JumpFigure::StartPropeller(JumpPropeller* propeller) 284 { 285 if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) 286 { 287 attach(propeller); 288 propeller->setPosition(0.0, 0.0, propellerPos_); 289 propeller->setVelocity(0.0, 0.0, 0.0); 290 propellerActive_ = true; 291 292 return true; 293 } 294 295 return false; 296 } 297 298 void JumpFigure::StopPropeller(JumpPropeller* propeller) 299 { 300 propeller->setPosition(0.0, 0.0, -1000.0); 301 propeller->setVelocity(0.0, 0.0, 0.0); 302 detach(propeller); 303 propeller->destroy(); 304 propellerActive_ = false; 305 } 306 307 bool JumpFigure::StartBoots(JumpBoots* boots) 308 { 309 if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) 310 { 311 attach(boots); 312 boots->setPosition(0.0, 0.0, bootsPos_); 313 boots->setVelocity(0.0, 0.0, 0.0); 314 bootsActive_ = true; 315 316 return true; 317 } 318 319 return false; 320 } 321 322 void JumpFigure::StopBoots(JumpBoots* boots) 323 { 324 boots->setPosition(0.0, 0.0, -1000.0); 325 boots->setVelocity(0.0, 0.0, 0.0); 326 detach(boots); 327 boots->destroy(); 328 bootsActive_ = false; 329 } 330 331 bool JumpFigure::StartShield(JumpShield* shield) 332 { 333 if (shieldActive_ == false) 334 { 335 attach(shield); 336 shield->setPosition(0.0, 0.0, propellerPos_); 337 shield->setVelocity(0.0, 0.0, 0.0); 338 shieldActive_ = true; 339 340 return true; 341 } 342 343 return false; 344 } 345 346 void JumpFigure::StopShield(JumpShield* shield) 347 { 348 shield->setPosition(0.0, 0.0, -1000.0); 349 shield->setVelocity(0.0, 0.0, 0.0); 350 detach(shield); 351 shield->destroy(); 352 shieldActive_ = false; 353 } 354 355 void JumpFigure::InitializeAnimation(Context* context) 356 { 357 leftHand_ = new Model(context); 358 rightHand_ = new Model(context); 359 360 leftHand_->addTemplate(modelLeftHand_); 361 rightHand_->addTemplate(modelRightHand_); 362 363 attach(leftHand_); 364 attach(rightHand_); 365 } 185 366 186 367 /** 187 @brief 368 @briefhandPosition_ 188 369 Overloaded the function to steer the bat up and down. 189 370 @param value … … 216 397 if (value.x > 0) 217 398 { 218 //orxout() << "right pressed" << endl;219 399 moveLeftPressed = false; 220 400 moveRightPressed = true; … … 222 402 else 223 403 { 224 //orxout() << "left pressed" << endl;225 404 moveLeftPressed = true; 226 405 moveRightPressed = false; 227 406 } 228 /*this->bMoveLocal_ = true;229 this->movement_ = value.x;*/230 407 } 231 408 … … 233 410 { 234 411 horizontalSpeed = value.x; 235 236 412 } 237 413 … … 248 424 } 249 425 426 void JumpFigure::fire(unsigned int firemode) 427 { 428 //SUPER(JumpFigure, fire, firemode); 429 } 430 250 431 void JumpFigure::fired(unsigned int firemode) 251 432 { 252 orxout() << "fire pressed" << endl;433 //SUPER(JumpFigure, fired, firemode); 253 434 firePressed = true; 254 435 } -
code/branches/pickupsFS14/src/modules/jump/JumpFigure.h
r10050 r10074 71 71 virtual void rotateRoll(const Vector2& value); 72 72 73 void fire(unsigned int firemode); 73 74 virtual void fired(unsigned int firemode); 74 75 75 76 virtual void JumpFromPlatform(JumpPlatform* platform); 76 77 /** 78 @brief Set the height of the playing field. 79 @param height The height of the playing field. 80 */ 77 virtual void JumpFromSpring(JumpSpring* spring); 78 virtual void CollisionWithEnemy(JumpEnemy* enemy); 79 virtual bool StartRocket(JumpRocket* rocket); 80 virtual void StopRocket(JumpRocket* rocket); 81 virtual bool StartPropeller(JumpPropeller* propeller); 82 virtual void StopPropeller(JumpPropeller* propeller); 83 virtual bool StartBoots(JumpBoots* boots); 84 virtual void StopBoots(JumpBoots* boots); 85 virtual bool StartShield(JumpShield* shield); 86 virtual void StopShield(JumpShield* shield); 87 88 virtual void InitializeAnimation(Context* context); 89 81 90 void setFieldDimension(float width, float height) 82 { this->fieldWidth_ = width; this->fieldHeight_ = height; }91 { fieldWidth_ = width; fieldHeight_ = height; } 83 92 84 93 void setFieldDimension(const Vector2& dimension) 85 { this->setFieldDimension(dimension.x, dimension.y); } 94 { setFieldDimension(dimension.x, dimension.y); } 95 96 Vector2 getFieldDimension() const 97 { return Vector2(fieldWidth_, fieldHeight_); } 86 98 87 99 void setMouseFactor(const float mouseFactor) 88 { this->mouseFactor_ = mouseFactor; }100 { mouseFactor_ = mouseFactor; } 89 101 90 102 const float getMouseFactor() const 91 { return this->mouseFactor_; } 92 93 /** 94 @brief Get the height of the playing field. 95 @return Returns the height of the playing field. 96 */ 97 Vector2 getFieldDimension() const 98 { return Vector2(this->fieldWidth_, this->fieldHeight_); } 99 100 /** 101 @brief Set the length of the bat. 102 @param length The length of the bat (in z-direction) as percentage of the height of the playing field. 103 */ 104 void setLength(float length) 105 { this->length_ = length; } 106 /** 107 @brief Get the length of the bat. 108 @return Returns the length of the bat (in z-direction) as percentage of the height of the playing field. 109 */ 110 float getLength() const 111 { return this->length_; } 103 { return mouseFactor_; } 104 105 void setModelLeftHand(const std::string& modelLeftHand) 106 { modelLeftHand_ = modelLeftHand; } 107 108 const std::string& getModelLeftHand() const 109 { return modelLeftHand_; } 110 111 void setModelRightHand(const std::string& modelRightHand) 112 { modelRightHand_ = modelRightHand; } 113 114 const std::string& getModelRightHand() const 115 { return modelRightHand_; } 116 117 void setRocketPos(const float rocketPos) 118 { rocketPos_ = rocketPos; } 119 120 const float getRocketPos() const 121 { return rocketPos_; } 122 123 void setPropellerPos(const float propellerPos) 124 { propellerPos_ = propellerPos; } 125 126 const float getPropellerPos() const 127 { return propellerPos_; } 128 129 void setBootsPos(const float bootsPos) 130 { bootsPos_ = bootsPos; } 131 132 const float getBootsPos() const 133 { return bootsPos_; } 134 135 void setJumpSpeed(const float jumpSpeed) 136 { jumpSpeed_ = jumpSpeed; } 137 138 const float getJumpSpeed() const 139 { return jumpSpeed_; } 140 141 void setRocketSpeed(const float rocketSpeed) 142 { rocketSpeed_ = rocketSpeed; } 143 144 const float getRocketSpeed() const 145 { return rocketSpeed_; } 146 147 void setPropellerSpeed(const float propellerSpeed) 148 { propellerSpeed_ = propellerSpeed; } 149 150 const float getPropellerSpeed() const 151 { return propellerSpeed_; } 152 153 void setHandMinAngle(const float handMinAngle) 154 { handMinAngle_ = handMinAngle; } 155 156 const float getHandMinAngle() const 157 { return handMinAngle_; } 158 159 void setHandMaxAngle(const float handMaxAngle) 160 { handMaxAngle_ = handMaxAngle; } 161 162 const float getHandMaxAngle() const 163 { return handMaxAngle_; } 164 165 void setHandSpeed(const float handSpeed) 166 { handSpeed_ = handSpeed; } 167 168 const float getHandSpeed() const 169 { return handSpeed_; } 112 170 113 171 bool fireSignal; 172 bool dead_; 173 114 174 private: 115 float movement_; //!< The amount (and direction), in z-direction, of movement of the bat. 116 bool bMoveLocal_; //!< Helper to know whether the movement is caused by moveFrontBack() or moveRightLeft(). 117 float length_; //!< The length of the bat (in z-direction) as percentage of the height of the playing field. 118 float fieldWidth_; //!< The height of the playing field. 175 std::string modelLeftHand_; 176 std::string modelRightHand_; 177 178 Model* leftHand_; 179 Model* rightHand_; 180 181 float fieldWidth_; 119 182 float fieldHeight_; 120 bool bSteadiedPosition_; //!< Helper boolean, to keep track of when to steady the position, to ensure network synchronicity.121 183 float timeSinceLastFire; 122 184 … … 129 191 float gravityAcceleration; 130 192 float mouseFactor_; 193 194 float jumpSpeed_; 195 float handSpeed_; 196 float handMaxAngle_; 197 float handMinAngle_; 198 float rocketPos_; 199 float propellerPos_; 200 float bootsPos_; 131 201 float maxFireRate; 132 202 133 203 float horizontalSpeed; 204 205 float handAngle_; 206 bool animateHands_; 207 bool turnUp_; 208 209 bool rocketActive_; 210 bool propellerActive_; 211 bool bootsActive_; 212 bool shieldActive_; 213 float rocketSpeed_; 214 float propellerSpeed_; 134 215 }; 135 216 } -
code/branches/pickupsFS14/src/modules/jump/JumpItem.cc
r10050 r10074 56 56 RegisterObject(JumpItem); 57 57 58 this->figure_ = 0; 59 setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 60 this->setPosition(Vector3(0,0,0)); 61 this->setVelocity(Vector3(0,0,0)); 62 this->setAcceleration(Vector3(0,0,0)); 58 attachedToFigure_ = false; 59 60 figure_ = 0; 61 height_ = 0.0; 62 width_ = 0.0; 63 setPosition(Vector3(0,0,0)); 64 setVelocity(Vector3(0,0,0)); 65 setAcceleration(Vector3(0,0,0)); 63 66 } 64 67 … … 69 72 JumpItem::~JumpItem() 70 73 { 71 /*if (this->isInitialized())72 {73 if (this->bDeleteBats_)74 delete this->figure_;75 74 76 delete[] this->batID_;77 }*/78 75 } 79 76 … … 82 79 { 83 80 SUPER(JumpItem, XMLPort, xmlelement, mode); 81 82 XMLPortParam(JumpItem, "height", setHeight, getHeight, xmlelement, mode); 83 XMLPortParam(JumpItem, "width", setWidth, getWidth, xmlelement, mode); 84 84 } 85 85 … … 94 94 { 95 95 SUPER(JumpItem, tick, dt); 96 97 // Get the current position, velocity and acceleration of the enemy. 98 Vector3 position = getPosition(); 96 // Get the current position, velocity and acceleration of the item. 97 Vector3 position = getWorldPosition(); 99 98 Vector3 velocity = getVelocity(); 100 99 … … 109 108 } 110 109 111 // Set the position, velocity and acceleration of the enemy, if they have changed.110 // Set the position, velocity and acceleration of the item, if they have changed. 112 111 if (velocity != getVelocity()) 112 { 113 113 setVelocity(velocity); 114 if (position != getPosition()) 115 setPosition(position); 116 117 114 } 118 115 } 119 116 … … 125 122 upperBoundary_ = newUpperBoundary; 126 123 127 this->setVelocity(Vector3(newHSpeed,0,newVSpeed));124 setVelocity(Vector3(newHSpeed,0,newVSpeed)); 128 125 } 129 126 -
code/branches/pickupsFS14/src/modules/jump/JumpItem.h
r10050 r10074 62 62 JumpItem(Context* context); 63 63 virtual ~JumpItem(); 64 virtual void tick(float dt); 65 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 66 virtual void setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed); 67 virtual void setFigure(WeakPtr<JumpFigure> bats); //!< Set the bats for the ball. 68 virtual void touchFigure(); 64 69 65 virtual void tick(float dt);66 67 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);68 69 /**70 @brief Set the dimensions of the playing field.71 @param width The width of the playing field.72 @param height The height of the playing field.73 */74 70 void setFieldDimension(float width, float height) 75 71 { this->fieldWidth_ = width; this->fieldHeight_ = height; } 76 /**77 @brief Get the dimensions of the playing field.78 @param dimension A vector with the width as the first and height as the second component.79 */80 72 void setFieldDimension(const Vector2& dimension) 81 73 { this->setFieldDimension(dimension.x, dimension.y); } 82 /**83 @brief Get the dimensions of the playing field.84 @return Returns a vector with the width as the first and height as the second component.85 */86 74 Vector2 getFieldDimension() const 87 75 { return Vector2(this->fieldWidth_, this->fieldHeight_); } 88 76 89 virtual void setProperties(float newLeftBoundary, float newRightBoundary, float newLowerBoundary, float newUpperBoundary, float newHSpeed, float newVSpeed); 77 void setWidth(const float width) 78 { this->width_ = width; } 79 float getWidth() const 80 { return width_; } 81 void setHeight(const float height) 82 { this->height_ = height; } 83 float getHeight() const 84 { return height_; } 90 85 91 void setFigure(WeakPtr<JumpFigure> bats); //!< Set the bats for the ball. 92 93 virtual void touchFigure(); 86 bool attachedToFigure_; 94 87 95 88 protected: … … 97 90 float fieldHeight_; //!< The height of the playing field. 98 91 92 WeakPtr<JumpFigure> figure_; //!< An array with the two bats. 93 float height_; 94 float width_; 95 99 96 float leftBoundary_; 100 97 float rightBoundary_; 101 98 float lowerBoundary_; 102 99 float upperBoundary_; 103 104 WeakPtr<JumpFigure> figure_; //!< An array with the two bats.105 100 }; 106 101 } -
code/branches/pickupsFS14/src/modules/jump/JumpPlatform.cc
r10050 r10074 58 58 RegisterObject(JumpPlatform); 59 59 60 this->figure_ = 0;60 figure_ = 0; 61 61 62 62 //initialize sound 63 63 if (GameMode::isMaster()) 64 64 { 65 this->defScoreSound_ = new WorldSound(this->getContext());66 this->defScoreSound_->setVolume(1.0f);67 this->defBatSound_ = new WorldSound(this->getContext());68 this->defBatSound_->setVolume(0.4f);69 this->defBoundarySound_ = new WorldSound(this->getContext());70 this->defBoundarySound_->setVolume(0.5f);65 defScoreSound_ = new WorldSound(this->getContext()); 66 defScoreSound_->setVolume(1.0f); 67 defBatSound_ = new WorldSound(this->getContext()); 68 defBatSound_->setVolume(0.4f); 69 defBoundarySound_ = new WorldSound(this->getContext()); 70 defBoundarySound_->setVolume(0.5f); 71 71 } 72 72 else 73 73 { 74 this->defScoreSound_ = 0;75 this->defBatSound_ = 0;76 this->defBoundarySound_ = 0;74 defScoreSound_ = 0; 75 defBatSound_ = 0; 76 defBoundarySound_ = 0; 77 77 } 78 78 79 this->setPosition(Vector3(0,0,0));80 this->setVelocity(Vector3(0,0,0));81 this->setAcceleration(Vector3(0,0,0));79 setPosition(Vector3(0,0,0)); 80 setVelocity(Vector3(0,0,0)); 81 setAcceleration(Vector3(0,0,0)); 82 82 } 83 83 … … 88 88 JumpPlatform::~JumpPlatform() 89 89 { 90 /*if (this->isInitialized())91 {92 if (this->bDeleteBats_)93 delete this->figure_;94 90 95 delete[] this->batID_;96 }*/97 91 } 98 92 … … 101 95 { 102 96 SUPER(JumpPlatform, XMLPort, xmlelement, mode); 97 98 XMLPortParam(JumpPlatform, "height", setHeight, getHeight, xmlelement, mode); 99 XMLPortParam(JumpPlatform, "width", setWidth, getWidth, xmlelement, mode); 100 103 101 XMLPortParam(JumpPlatform, "defScoreSound", setDefScoreSound, getDefScoreSound, xmlelement, mode); 104 102 XMLPortParam(JumpPlatform, "defBatSound", setDefBatSound, getDefBatSound, xmlelement, mode); … … 124 122 Vector3 figureVelocity = figure_->getVelocity(); 125 123 126 if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-10 && figurePosition.x < platformPosition.x+10 && figurePosition.z > platformPosition.z-4 && figurePosition.z < platformPosition.z+4) 124 float tolerance = 3.0; 125 126 if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-width_/2 && figurePosition.x < platformPosition.x+width_/2 && figurePosition.z > platformPosition.z-height_/2*tolerance && figurePosition.z < platformPosition.z+height_/2) 127 127 { 128 128 touchFigure(); 129 129 } 130 130 } 131 132 133 134 135 136 /*137 // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters).138 if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)139 {140 defBoundarySound_->play(); //play boundary sound141 // Its velocity in z-direction is inverted (i.e. it bounces off).142 velocity.z = -velocity.z;143 // And its position is set as to not overstep the boundary it has just crossed.144 if (position.z > this->fieldHeight_ / 2)145 position.z = this->fieldHeight_ / 2;146 if (position.z < -this->fieldHeight_ / 2)147 position.z = -this->fieldHeight_ / 2;148 149 this->fireEvent();150 }151 152 // If the ball has crossed the left or right boundary of the playing field (i.e. a player has just scored, if the bat isn't there to parry).153 if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)154 {155 float distance = 0;156 157 if (this->bat_ != NULL) // If there are bats.158 {159 // If the right boundary has been crossed.160 if (position.x > this->fieldWidth_ / 2 && this->bat_[1] != NULL)161 {162 // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)163 distance = (position.z - this->bat_[1]->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);164 if (fabs(distance) <= 1) // If the bat is there to parry.165 {166 defBatSound_->play(); //play bat sound167 // Set the ball to be exactly at the boundary.168 position.x = this->fieldWidth_ / 2;169 // Invert its velocity in x-direction (i.e. it bounces off).170 velocity.x = -velocity.x;171 // Adjust the velocity in the z-direction, depending on where the ball hit the bat.172 velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;173 acceleration = this->bat_[1]->getVelocity() * this->accelerationFactor_ * -1;174 175 this->fireEvent();176 }177 // If the left player scores.178 else if (GameMode::isMaster() && position.x > this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))179 {180 defScoreSound_->play();//play score sound181 if (this->getGametype() && this->bat_[0])182 {183 this->getGametype()->playerScored(this->bat_[0]->getPlayer());184 return;185 }186 }187 }188 // If the left boundary has been crossed.189 else if (position.x < -this->fieldWidth_ / 2 && this->bat_[0] != NULL)190 {191 // Calculate the distance (in z-direction) between the ball and the center of the bat, weighted by half of the effective length of the bat (with additional 10%)192 distance = (position.z - this->figure_->getPosition().z) / (this->fieldHeight_ * (this->batlength_ * 1.10f) / 2);193 if (fabs(distance) <= 1) // If the bat is there to parry.194 {195 defBatSound_->play(); //play bat sound196 // Set the ball to be exactly at the boundary.197 position.x = -this->fieldWidth_ / 2;198 // Invert its velocity in x-direction (i.e. it bounces off).199 velocity.x = -velocity.x;200 // Adjust the velocity in the z-direction, depending on where the ball hit the bat.201 velocity.z = distance * distance * sgn(distance) * JumpPlatform::MAX_REL_Z_VELOCITY * this->speed_;202 acceleration = this->bat_[0]->getVelocity() * this->accelerationFactor_ * -1;203 204 this->fireEvent();205 }206 // If the right player scores.207 else if (GameMode::isMaster() && position.x < -this->fieldWidth_ / 2 * (1 + this->relMercyOffset_))208 {209 defScoreSound_->play();//play score sound210 if (this->getGametype() && this->bat_[1])211 {212 this->getGametype()->playerScored(this->bat_[1]->getPlayer());213 return;214 }215 }216 }217 }218 }219 */220 131 } 221 132 222 /**223 @brief224 Set the bats for the ball.225 @param bats226 An array (of size 2) of weak pointers, to be set as the new bats.227 */228 133 void JumpPlatform::setFigure(WeakPtr<JumpFigure> newFigure) 229 134 { 230 135 figure_ = newFigure; 231 }232 233 void JumpPlatform::accelerateFigure()234 {235 figure_->JumpFromPlatform(this);236 136 } 237 137 -
code/branches/pickupsFS14/src/modules/jump/JumpPlatform.h
r10050 r10074 62 62 JumpPlatform(Context* context); 63 63 virtual ~JumpPlatform(); 64 65 64 virtual void tick(float dt); 66 67 65 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 68 69 /**70 @brief Set the dimensions of the playing field.71 @param width The width of the playing field.72 @param height The height of the playing field.73 */74 void setFieldDimension(float width, float height)75 { this->fieldWidth_ = width; this->fieldHeight_ = height; }76 /**77 @brief Get the dimensions of the playing field.78 @param dimension A vector with the width as the first and height as the second component.79 */80 void setFieldDimension(const Vector2& dimension)81 { this->setFieldDimension(dimension.x, dimension.y); }82 /**83 @brief Get the dimensions of the playing field.84 @return Returns a vector with the width as the first and height as the second component.85 */86 Vector2 getFieldDimension() const87 { return Vector2(this->fieldWidth_, this->fieldHeight_); }88 89 90 66 void setFigure(WeakPtr<JumpFigure> bats); //!< Set the bats for the ball. 91 92 virtual void accelerateFigure();93 67 virtual void touchFigure(); 94 68 … … 102 76 const std::string& getDefBoundarySound(); 103 77 78 void setWidth(const float width) 79 { this->width_ = width; } 80 float getWidth() const 81 { return width_; } 82 void setHeight(const float height) 83 { this->height_ = height; } 84 float getHeight() const 85 { return height_; } 86 104 87 protected: 105 float fieldWidth_; //!< The width of the playing field.106 float fieldHeight_; //!< The height of the playing field.107 WeakPtr<JumpFigure> figure_; //!< An array with the two bats.88 float width_; 89 float height_; 90 WeakPtr<JumpFigure> figure_; 108 91 WorldSound* defScoreSound_; 109 92 WorldSound* defBatSound_; -
code/branches/pickupsFS14/src/modules/jump/JumpPlatformDisappear.cc
r10050 r10074 101 101 if (isActive()) 102 102 { 103 accelerateFigure();103 figure_->JumpFromPlatform(this); 104 104 active_ = false; 105 orxout() << "platform deactivated" << endl;106 105 } 107 106 } -
code/branches/pickupsFS14/src/modules/jump/JumpPlatformFake.cc
r10050 r10074 44 44 #include "core/XMLPort.h" 45 45 46 #include "graphics/Backlight.h"47 48 46 namespace orxonox 49 47 { -
code/branches/pickupsFS14/src/modules/jump/JumpPlatformHMove.cc
r10050 r10074 116 116 void JumpPlatformHMove::touchFigure() 117 117 { 118 accelerateFigure();118 figure_->JumpFromPlatform(this); 119 119 } 120 120 } -
code/branches/pickupsFS14/src/modules/jump/JumpPlatformStatic.cc
r10050 r10074 87 87 void JumpPlatformStatic::touchFigure() 88 88 { 89 accelerateFigure();89 figure_->JumpFromPlatform(this); 90 90 } 91 91 } -
code/branches/pickupsFS14/src/modules/jump/JumpPlatformTimer.cc
r10050 r10074 117 117 void JumpPlatformTimer::touchFigure() 118 118 { 119 accelerateFigure();120 119 if (isActive()) 121 120 { 122 accelerateFigure();121 figure_->JumpFromPlatform(this); 123 122 } 124 123 } -
code/branches/pickupsFS14/src/modules/jump/JumpPlatformVMove.cc
r10050 r10074 113 113 void JumpPlatformVMove::touchFigure() 114 114 { 115 accelerateFigure();115 figure_->JumpFromPlatform(this); 116 116 } 117 117 } -
code/branches/pickupsFS14/src/modules/jump/JumpPrereqs.h
r10050 r10074 79 79 class JumpEnemy; 80 80 class JumpItem; 81 class JumpSpring; 82 class JumpRocket; 83 class JumpPropeller; 84 class JumpBoots; 85 class JumpShield; 81 86 class JumpFigure; 82 87 class JumpCenterpoint; -
code/branches/pickupsFS14/src/modules/jump/JumpProjectile.cc
r10050 r10074 56 56 RegisterObject(JumpProjectile); 57 57 58 this->figure_ = 0;58 figure_ = 0; 59 59 60 this->registerVariables();60 registerVariables(); 61 61 62 this->setPosition(Vector3(0,0,0));63 this->setVelocity(Vector3(0,0,0));64 this->setAcceleration(Vector3(0,0,0));62 setPosition(Vector3(0,0,0)); 63 setVelocity(Vector3(0,0,250.0)); 64 setAcceleration(Vector3(0,0,0)); 65 65 } 66 66 … … 108 108 SUPER(JumpProjectile, tick, dt); 109 109 110 Vector3 p latformPosition = this->getPosition();110 Vector3 projectilePosition = getPosition(); 111 111 112 if (figure_ != NULL) 113 { 114 Vector3 figurePosition = figure_->getPosition(); 115 Vector3 figureVelocity = figure_->getVelocity(); 112 for (ObjectList<JumpEnemy>::iterator it = ObjectList<JumpEnemy>::begin(); it != ObjectList<JumpEnemy>::end(); ++it) 113 { 114 Vector3 enemyPosition = it->getPosition(); 115 float enemyWidth = it->getWidth(); 116 float enemyHeight = it->getHeight(); 116 117 117 if(figureVelocity.z < 0 && figurePosition.x > platformPosition.x-10 && figurePosition.x < platformPosition.x+10 && figurePosition.z > platformPosition.z-4 && figurePosition.z < platformPosition.z+4)118 119 touchFigure();120 121 118 if(projectilePosition.x > enemyPosition.x-enemyWidth && projectilePosition.x < enemyPosition.x+enemyWidth && projectilePosition.z > enemyPosition.z-enemyHeight && projectilePosition.z < enemyPosition.z+enemyHeight) 119 { 120 it->dead_ = true; 121 } 122 } 122 123 } 123 124 … … 128 129 An array (of size 2) of weak pointers, to be set as the new bats. 129 130 */ 130 void JumpProjectile::setFigure(WeakPtr<JumpFigure> newFigure)131 void JumpProjectile::setFigure(WeakPtr<JumpFigure> figure) 131 132 { 132 figure_ = newFigure; 133 } 134 135 void JumpProjectile::accelerateFigure() 136 { 137 138 } 139 140 void JumpProjectile::touchFigure() 141 { 142 133 figure_ = figure; 143 134 } 144 135 } -
code/branches/pickupsFS14/src/modules/jump/JumpProjectile.h
r10050 r10074 67 67 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 68 68 69 /**70 @brief Set the dimensions of the playing field.71 @param width The width of the playing field.72 @param height The height of the playing field.73 */74 69 void setFieldDimension(float width, float height) 75 70 { this->fieldWidth_ = width; this->fieldHeight_ = height; } 76 /** 77 @brief Get the dimensions of the playing field. 78 @param dimension A vector with the width as the first and height as the second component. 79 */ 71 80 72 void setFieldDimension(const Vector2& dimension) 81 73 { this->setFieldDimension(dimension.x, dimension.y); } 82 /** 83 @brief Get the dimensions of the playing field. 84 @return Returns a vector with the width as the first and height as the second component. 85 */ 74 86 75 Vector2 getFieldDimension() const 87 76 { return Vector2(this->fieldWidth_, this->fieldHeight_); } 88 77 89 78 90 void setFigure(WeakPtr<JumpFigure> bats); //!< Set the bats for the ball. 91 92 virtual void accelerateFigure(); 93 virtual void touchFigure(); 79 void setFigure(WeakPtr<JumpFigure> figure); 94 80 95 81 protected: -
code/branches/pickupsFS14/src/modules/jump/JumpScore.cc
r10050 r10074 55 55 RegisterObject(JumpScore); 56 56 57 this->owner_ = NULL; 58 57 owner_ = NULL; 58 showScore_ = false; 59 showMessages_ = false; 59 60 } 60 61 … … 75 76 { 76 77 SUPER(JumpScore, XMLPort, xmlelement, mode); 78 79 XMLPortParam(JumpScore, "showScore", setShowScore, getShowScore, xmlelement, mode); 80 XMLPortParam(JumpScore, "showMessages", setShowMessages, getShowMessages, xmlelement, mode); 81 XMLPortParam(JumpScore, "gameOverText", setGameOverText, getGameOverText, xmlelement, mode); 77 82 } 78 83 … … 92 97 if (this->owner_ != NULL) 93 98 { 94 /*95 if (!this->owner_->hasEnded())96 {97 // Get the two players.98 player1_ = this->owner_->getPlayer();99 }100 101 std::string name1;102 103 std::string score1("0");104 105 // Save the name and score of each player as a string.106 if (player1_ != NULL)107 {108 name1 = player1_->getName();109 score1 = multi_cast<std::string>(this->owner_->getScore(player1_));110 }111 112 // Assemble the strings, depending on what should all be displayed.113 std::string output1;114 if (this->bShowLeftPlayer_)115 {116 if (this->bShowName_ && this->bShowScore_ && player1_ != NULL)117 output1 = name1 + " - " + score1;118 else if (this->bShowScore_)119 output1 = score1;120 else if (this->bShowName_)121 output1 = name1;122 }123 124 std::string output("JUMP");125 if (this->bShowName_ || this->bShowScore_)126 {127 if (this->bShowLeftPlayer_ && this->bShowRightPlayer_)128 output = output1 + ':' + output2;129 else if (this->bShowLeftPlayer_ || this->bShowRightPlayer_)130 output = output1 + output2;131 }132 133 this->setCaption(output);*/134 135 136 137 138 99 if (!owner_->hasEnded()) 139 100 { … … 142 103 if (player_ != NULL) 143 104 { 144 int score = owner_->getScore(player_); 105 if (showScore_ == true) 106 { 107 int score = owner_->getScore(player_); 145 108 146 std::string str = multi_cast<std::string>(score); 147 setCaption(str); 109 std::string str = multi_cast<std::string>(score); 110 setCaption(str); 111 } 112 else if (showMessages_ == true) 113 { 114 115 setCaption(owner_->getDead(player_) == true ? gameOverText_ : ""); 116 } 148 117 } 149 118 } -
code/branches/pickupsFS14/src/modules/jump/JumpScore.h
r10050 r10074 64 64 virtual void changedOwner(); //!< Is called when the owner changes. 65 65 66 void setShowScore(const bool showScore) 67 { showScore_ = showScore; } 68 69 const bool getShowScore() const 70 { return showScore_; } 71 72 void setShowMessages(const bool showMessages) 73 { showMessages_ = showMessages; } 74 75 const bool getShowMessages() const 76 { return showMessages_; } 77 78 void setGameOverText(const std::string& gameOverText) 79 { this->gameOverText_ = gameOverText; } 80 81 const std::string& getGameOverText() const 82 { return this->gameOverText_; } 83 66 84 private: 67 85 Jump* owner_; //!< The Jump game that owns this JumpScore. 68 86 WeakPtr<PlayerInfo> player_; //!< Store information about left player permanently. 69 87 WorldSound* scoreSound_; 88 bool showScore_; 89 bool showMessages_; 90 std::string gameOverText_; 70 91 71 92 };
Note: See TracChangeset
for help on using the changeset viewer.