Changeset 10074 for code/branches/pickupsFS14/src/modules/jump/Jump.cc
- Timestamp:
- May 22, 2014, 3:05:46 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.