Changeset 10215
- Timestamp:
- Jan 31, 2015, 5:31:23 PM (10 years ago)
- Location:
- code/branches/presentationFS14/src
- Files:
-
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS14/src/modules/jump/Jump.cc
r10078 r10215 84 84 void Jump::tick(float dt) 85 85 { 86 87 88 89 90 91 92 93 94 95 96 97 98 86 SUPER(Jump, tick, dt); 87 88 if (figure_ != NULL) 89 { 90 Vector3 figurePosition = figure_->getPosition(); 91 Vector3 figureVelocity = figure_->getVelocity(); 92 93 float boundary = totalScreenShift_+center_->getCameraOffset(); 94 95 if (figurePosition.z > boundary) 96 { 97 screenShiftSinceLastUpdate_ += figurePosition.z - boundary; 98 totalScreenShift_ = figurePosition.z - center_->getCameraOffset(); 99 99 100 100 // Create new platforms if needed 101 101 if (screenShiftSinceLastUpdate_ > center_->getSectionLength()) 102 102 { 103 104 105 106 107 108 109 110 111 112 103 if (sectionNumber_ > 2 && sectionNumber_%4 == 0 && rand()%2 == 0 && figure_->propellerActive_ == false && figure_->rocketActive_ == false && addAdventure(adventureNumber_) == true) 104 { 105 screenShiftSinceLastUpdate_ -= 2*center_->getSectionLength(); 106 ++ adventureNumber_; 107 } 108 else 109 { 110 screenShiftSinceLastUpdate_ -= center_->getSectionLength(); 111 addSection(); 112 } 113 113 } 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 114 } 115 116 if (figurePosition.z < totalScreenShift_ - center_->getFieldDimension().y + platformHeight_ && figureVelocity.z < 0) 117 { 118 figure_->dead_ = true; 119 } 120 121 if (figure_->fireSignal_ == true) 122 { 123 if (figure_->dead_ == true) 124 { 125 end(); 126 } 127 else 128 { 129 figure_->fireSignal_ = false; 130 addProjectile(figurePosition.x, figurePosition.z + figure_->getPropellerPos()); 131 } 132 } 133 134 135 if (camera != NULL) 136 { 137 Vector3 cameraPosition = Vector3(0, totalScreenShift_, 0); 138 camera->setPosition(cameraPosition); 139 } 140 else 141 { 142 orxout() << "No camera found." << endl; 143 } 144 } 145 146 ObjectList<JumpPlatform>::iterator beginPlatform = ObjectList<JumpPlatform>::begin(); 147 ObjectList<JumpPlatform>::iterator endPlatform = ObjectList<JumpPlatform>::end(); 148 ObjectList<JumpPlatform>::iterator itPlatform = beginPlatform; 149 Vector3 platformPosition; 150 151 while (itPlatform != endPlatform) 152 { 153 platformPosition = itPlatform->getPosition(); 154 if (platformPosition.z < totalScreenShift_ - center_->getFieldDimension().y) 155 { 156 ObjectList<JumpPlatform>::iterator temp = itPlatform; 157 ++ itPlatform; 158 center_->detach(*temp); 159 temp->destroy(); 160 } 161 else 162 { 163 ++ itPlatform; 164 } 165 } 166 167 // Deleted deactivated platforms 168 ObjectList<JumpPlatformDisappear>::iterator beginDisappear = ObjectList<JumpPlatformDisappear>::begin(); 169 ObjectList<JumpPlatformDisappear>::iterator endDisappear = ObjectList<JumpPlatformDisappear>::end(); 170 ObjectList<JumpPlatformDisappear>::iterator itDisappear = beginDisappear; 171 172 while (itDisappear != endDisappear) 173 { 174 if (!itDisappear->isActive()) 175 { 176 ObjectList<JumpPlatformDisappear>::iterator temp = itDisappear; 177 ++ itDisappear; 178 center_->detach(*temp); 179 temp->destroy(); 180 } 181 else 182 { 183 ++ itDisappear; 184 } 185 } 186 187 ObjectList<JumpPlatformTimer>::iterator beginTimer = ObjectList<JumpPlatformTimer>::begin(); 188 ObjectList<JumpPlatformTimer>::iterator endTimer = ObjectList<JumpPlatformTimer>::end(); 189 ObjectList<JumpPlatformTimer>::iterator itTimer = beginTimer; 190 191 while (itTimer != endTimer) 192 { 193 if (!itTimer->isActive()) 194 { 195 ObjectList<JumpPlatformTimer>::iterator temp = itTimer; 196 ++ itTimer; 197 center_->detach(*temp); 198 temp->destroy(); 199 } 200 else 201 { 202 ++ itTimer; 203 } 204 } 205 206 ObjectList<JumpProjectile>::iterator beginProjectile = ObjectList<JumpProjectile>::begin(); 207 ObjectList<JumpProjectile>::iterator endProjectile = ObjectList<JumpProjectile>::end(); 208 ObjectList<JumpProjectile>::iterator itProjectile = beginProjectile; 209 Vector3 projectilePosition; 210 211 while (itProjectile != endProjectile) 212 { 213 projectilePosition = itProjectile->getPosition(); 214 if (projectilePosition.z > totalScreenShift_ + 5*center_->getFieldDimension().y) 215 { 216 ObjectList<JumpProjectile>::iterator temp = itProjectile; 217 ++ itProjectile; 218 center_->detach(*temp); 219 temp->destroy(); 220 } 221 else 222 { 223 ++ itProjectile; 224 } 225 } 226 227 ObjectList<JumpEnemy>::iterator beginEnemy = ObjectList<JumpEnemy>::begin(); 228 ObjectList<JumpEnemy>::iterator endEnemy = ObjectList<JumpEnemy>::end(); 229 ObjectList<JumpEnemy>::iterator itEnemy = beginEnemy; 230 Vector3 enemyPosition; 231 232 while (itEnemy != endEnemy) 233 { 234 enemyPosition = itEnemy->getPosition(); 235 if (enemyPosition.z < totalScreenShift_ - center_->getFieldDimension().y || itEnemy->dead_ == true) 236 { 237 ObjectList<JumpEnemy>::iterator temp = itEnemy; 238 ++ itEnemy; 239 center_->detach(*temp); 240 temp->destroy(); 241 } 242 else 243 { 244 ++ itEnemy; 245 } 246 } 247 248 ObjectList<JumpItem>::iterator beginItem = ObjectList<JumpItem>::begin(); 249 ObjectList<JumpItem>::iterator endItem = ObjectList<JumpItem>::end(); 250 ObjectList<JumpItem>::iterator itItem = beginItem; 251 Vector3 itemPosition; 252 253 while (itItem != endItem) 254 { 255 itemPosition = itItem->getPosition(); 256 257 WorldEntity* parent = itItem->getParent(); 258 259 if (itItem->attachedToFigure_ == false && itemPosition.z < totalScreenShift_ - center_->getFieldDimension().y && parent == center_) 260 { 261 ObjectList<JumpItem>::iterator temp = itItem; 262 ++ itItem; 263 center_->detach(*temp); 264 temp->destroy(); 265 } 266 else 267 { 268 ++ itItem; 269 } 270 } 271 271 } 272 272 273 273 void Jump::cleanup() 274 274 { 275 275 camera = 0; 276 276 } 277 277 … … 280 280 if (center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place. 281 281 { 282 283 284 285 286 287 282 if (figure_ == NULL) 283 { 284 figure_ = new JumpFigure(center_->getContext()); 285 figure_->addTemplate(center_->getFigureTemplate()); 286 figure_->InitializeAnimation(center_->getContext()); 287 } 288 288 289 289 center_->attach(figure_); … … 303 303 if (figure_ != NULL) 304 304 { 305 305 camera = figure_->getCamera(); 306 306 } 307 307 … … 318 318 void Jump::end() 319 319 { 320 321 320 cleanup(); 321 GSLevel::startMainMenu(); 322 322 323 323 Deathmatch::end(); … … 349 349 void Jump::addPlatform(JumpPlatform* newPlatform, std::string platformTemplate, float xPosition, float zPosition) 350 350 { 351 352 353 354 355 356 357 351 if (newPlatform != NULL && center_ != NULL) 352 { 353 newPlatform->addTemplate(platformTemplate); 354 newPlatform->setPosition(Vector3(xPosition, 0.0, zPosition)); 355 newPlatform->setFigure(this->figure_); 356 center_->attach(newPlatform); 357 } 358 358 } 359 359 360 360 JumpPlatformStatic* Jump::addPlatformStatic(float xPosition, float zPosition) 361 361 { 362 363 364 365 362 JumpPlatformStatic* newPlatform = new JumpPlatformStatic(center_->getContext()); 363 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, zPosition); 364 365 return newPlatform; 366 366 } 367 367 368 368 JumpPlatformHMove* Jump::addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed) 369 369 { 370 371 372 373 374 370 JumpPlatformHMove* newPlatform = new JumpPlatformHMove(center_->getContext()); 371 newPlatform->setProperties(leftBoundary, rightBoundary, speed); 372 addPlatform(newPlatform, center_->getPlatformHMoveTemplate(), xPosition, zPosition); 373 374 return newPlatform; 375 375 } 376 376 377 377 JumpPlatformVMove* Jump::addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed) 378 378 { 379 380 381 382 383 379 JumpPlatformVMove* newPlatform = new JumpPlatformVMove(center_->getContext()); 380 newPlatform->setProperties(lowerBoundary, upperBoundary, speed); 381 addPlatform(newPlatform, center_->getPlatformVMoveTemplate(), xPosition, zPosition); 382 383 return newPlatform; 384 384 } 385 385 386 386 JumpPlatformDisappear* Jump::addPlatformDisappear(float xPosition, float zPosition) 387 387 { 388 389 390 391 392 388 JumpPlatformDisappear* newPlatform = new JumpPlatformDisappear(center_->getContext()); 389 newPlatform->setProperties(true); 390 addPlatform(newPlatform, center_->getPlatformDisappearTemplate(), xPosition, zPosition); 391 392 return newPlatform; 393 393 } 394 394 395 395 JumpPlatformTimer* Jump::addPlatformTimer(float xPosition, float zPosition, float time, float variance) 396 396 { 397 398 399 400 401 402 403 397 float additionalTime = (float)(rand()%100)/(100*variance) - variance/2; 398 399 JumpPlatformTimer* newPlatform = new JumpPlatformTimer(center_->getContext()); 400 newPlatform->setProperties(time + additionalTime); 401 addPlatform(newPlatform, center_->getPlatformTimerTemplate(), xPosition, zPosition); 402 403 return newPlatform; 404 404 } 405 405 406 406 JumpPlatformFake* Jump::addPlatformFake(float xPosition, float zPosition) 407 407 { 408 409 410 411 412 408 JumpPlatformFake* newPlatform = new JumpPlatformFake(center_->getContext()); 409 addPlatform(newPlatform, center_->getPlatformFakeTemplate(), xPosition, zPosition); 410 newPlatform->setAngularVelocity(Vector3(0, 0, 2.0)); 411 412 return newPlatform; 413 413 } 414 414 … … 416 416 void Jump::addProjectile(float xPosition, float zPosition) 417 417 { 418 419 420 421 422 423 424 425 426 418 JumpProjectile* newProjectile = new JumpProjectile(center_->getContext()); 419 if (newProjectile != NULL && center_ != NULL) 420 { 421 newProjectile->addTemplate(center_->getProjectileTemplate()); 422 newProjectile->setPosition(Vector3(xPosition, 0.0, zPosition)); 423 newProjectile->setFieldDimension(center_->getFieldDimension()); 424 newProjectile->setFigure(this->figure_); 425 center_->attach(newProjectile); 426 } 427 427 } 428 428 429 429 void Jump::addSpring(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 430 430 { 431 432 433 434 435 436 437 438 439 431 JumpSpring* newSpring = new JumpSpring(center_->getContext()); 432 if (newSpring != NULL && center_ != NULL) 433 { 434 newSpring->addTemplate(center_->getSpringTemplate()); 435 newSpring->setPosition(Vector3(xPosition, 0.0, zPosition)); 436 newSpring->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 437 newSpring->setFigure(figure_); 438 center_->attach(newSpring); 439 } 440 440 } 441 441 442 442 void Jump::addSpring(JumpPlatform* platform) 443 443 { 444 445 446 447 448 449 450 451 452 444 JumpSpring* newSpring = new JumpSpring(center_->getContext()); 445 if (newSpring != NULL && center_ != NULL) 446 { 447 newSpring->addTemplate(center_->getSpringTemplate()); 448 newSpring->setPosition(Vector3(0.0, 0.0, 0.0)); 449 newSpring->setProperties(-10.0, 10.0, -10.0, 10.0, 0.0, 0.0); 450 newSpring->setFigure(figure_); 451 platform->attach(newSpring); 452 } 453 453 } 454 454 455 455 void Jump::addRocket(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 456 456 { 457 458 459 460 461 462 463 464 465 457 JumpRocket* newRocket = new JumpRocket(center_->getContext()); 458 if (newRocket != NULL && center_ != NULL) 459 { 460 newRocket->addTemplate(center_->getRocketTemplate()); 461 newRocket->setPosition(Vector3(xPosition, 0.0, zPosition)); 462 newRocket->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 463 newRocket->setFigure(figure_); 464 center_->attach(newRocket); 465 } 466 466 } 467 467 468 468 void Jump::addRocket(JumpPlatform* platform) 469 469 { 470 471 472 473 474 475 476 477 478 470 JumpRocket* newRocket = new JumpRocket(center_->getContext()); 471 if (newRocket != NULL && center_ != NULL) 472 { 473 newRocket->addTemplate(center_->getRocketTemplate()); 474 newRocket->setPosition(Vector3(0.0, 0.0, 0.0)); 475 newRocket->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 476 newRocket->setFigure(figure_); 477 platform->attach(newRocket); 478 } 479 479 } 480 480 481 481 void Jump::addPropeller(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 482 482 { 483 484 485 486 487 488 489 490 491 483 JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); 484 if (newPropeller != NULL && center_ != NULL) 485 { 486 newPropeller->addTemplate(center_->getPropellerTemplate()); 487 newPropeller->setPosition(Vector3(xPosition, 0.0, zPosition)); 488 newPropeller->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 489 newPropeller->setFigure(figure_); 490 center_->attach(newPropeller); 491 } 492 492 } 493 493 494 494 void Jump::addPropeller(JumpPlatform* platform) 495 495 { 496 497 498 499 500 501 502 503 504 496 JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); 497 if (newPropeller != NULL && center_ != NULL) 498 { 499 newPropeller->addTemplate(center_->getPropellerTemplate()); 500 newPropeller->setPosition(Vector3(0.0, 0.0, 0.0)); 501 newPropeller->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 502 newPropeller->setFigure(figure_); 503 platform->attach(newPropeller); 504 } 505 505 } 506 506 507 507 void Jump::addBoots(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 508 508 { 509 510 511 512 513 514 515 516 517 509 JumpBoots* newBoots = new JumpBoots(center_->getContext()); 510 if (newBoots != NULL && center_ != NULL) 511 { 512 newBoots->addTemplate(center_->getBootsTemplate()); 513 newBoots->setPosition(Vector3(xPosition, 0.0, zPosition)); 514 newBoots->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 515 newBoots->setFigure(figure_); 516 center_->attach(newBoots); 517 } 518 518 } 519 519 520 520 void Jump::addBoots(JumpPlatform* platform) 521 521 { 522 523 524 525 526 527 528 529 530 522 JumpBoots* newBoots = new JumpBoots(center_->getContext()); 523 if (newBoots != NULL && center_ != NULL) 524 { 525 newBoots->addTemplate(center_->getBootsTemplate()); 526 newBoots->setPosition(Vector3(0.0, 0.0, 0.0)); 527 newBoots->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 528 newBoots->setFigure(figure_); 529 platform->attach(newBoots); 530 } 531 531 } 532 532 533 533 void Jump::addShield(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 534 534 { 535 536 537 538 539 540 541 542 543 535 JumpShield* newShield = new JumpShield(center_->getContext()); 536 if (newShield != NULL && center_ != NULL) 537 { 538 newShield->addTemplate(center_->getShieldTemplate()); 539 newShield->setPosition(Vector3(xPosition, 0.0, zPosition)); 540 newShield->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 541 newShield->setFigure(figure_); 542 center_->attach(newShield); 543 } 544 544 } 545 545 546 546 void Jump::addShield(JumpPlatform* platform) 547 547 { 548 549 550 551 552 553 554 555 556 548 JumpShield* newShield = new JumpShield(center_->getContext()); 549 if (newShield != NULL && center_ != NULL) 550 { 551 newShield->addTemplate(center_->getShieldTemplate()); 552 newShield->setPosition(Vector3(0.0, 0.0, 0.0)); 553 newShield->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); 554 newShield->setFigure(figure_); 555 platform->attach(newShield); 556 } 557 557 } 558 558 559 559 void Jump::addEnemy(int type, float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) 560 560 { 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 561 JumpEnemy* newEnemy = new JumpEnemy(center_->getContext()); 562 if (newEnemy != NULL && center_ != NULL) 563 { 564 switch (type) 565 { 566 case 1: 567 newEnemy->addTemplate(center_->getEnemy1Template()); 568 break; 569 case 2: 570 newEnemy->addTemplate(center_->getEnemy2Template()); 571 break; 572 case 3: 573 newEnemy->addTemplate(center_->getEnemy3Template()); 574 break; 575 case 4: 576 newEnemy->addTemplate(center_->getEnemy4Template()); 577 break; 578 default: 579 return; 580 } 581 582 newEnemy->setPosition(Vector3(xPosition, 0.0, zPosition)); 583 newEnemy->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); 584 newEnemy->setFieldDimension(center_->getFieldDimension()); 585 newEnemy->setFigure(this->figure_); 586 center_->attach(newEnemy); 587 } 588 588 } 589 589 590 590 void Jump::addStartSection() 591 591 { 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 592 JumpPlatform* newPlatform; 593 594 float sectionLength = center_->getSectionLength(); 595 596 newPlatform = new JumpPlatformStatic(center_->getContext()); 597 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), 0.0, -0.05*sectionLength); 598 599 platformWidth_ = newPlatform->getWidth(); 600 platformHeight_ = newPlatform->getHeight(); 601 602 for (float xPosition = platformWidth_; xPosition <= center_->getFieldDimension().x; xPosition += platformWidth_) 603 { 604 newPlatform = new JumpPlatformStatic(center_->getContext()); 605 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, -0.05*sectionLength); 606 newPlatform = new JumpPlatformStatic(center_->getContext()); 607 addPlatform(newPlatform, center_->getPlatformStaticTemplate(), -xPosition, -0.05*sectionLength); 608 } 609 609 } 610 610 … … 619 619 int numJ = 4; 620 620 621 622 623 624 625 626 627 628 629 621 enum PlatformType 622 { 623 PLATFORM_EMPTY, PLATFORM_STATIC, PLATFORM_HMOVE, PLATFORM_VMOVE, PLATFORM_DISAPPEAR, PLATFORM_TIMER, PLATFORM_FAKE 624 }; 625 626 enum ItemType 627 { 628 ITEM_NOTHING, ITEM_SPRING, ITEM_PROPELLER, ITEM_ROCKET, ITEM_BOOTS, ITEM_SHIELD 629 }; 630 630 631 631 struct PlatformMatrix 632 632 { 633 633 PlatformType type; 634 634 bool done; 635 635 } matrix[numI][numJ]; 636 636 637 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 638 for (int i = 0; i < numI; ++i) 639 { 640 for (int j = 0; j < numJ; ++j) 641 { 642 matrix[i][j].type = PLATFORM_EMPTY; 643 matrix[i][j].done = false; 644 } 645 } 646 PlatformType platformtype1; 647 PlatformType platformtype2; 648 ItemType itemType = ITEM_NOTHING; 649 650 if (rand()%2 == 0) 651 { 652 itemType = ITEM_SPRING; 653 } 654 else if (rand()%2 == 0 && sectionNumber_ > 3) 655 { 656 switch(rand()%4) 657 { 658 case 0: 659 itemType = ITEM_PROPELLER; 660 break; 661 case 1: 662 itemType = ITEM_ROCKET; 663 break; 664 case 2: 665 itemType = ITEM_BOOTS; 666 break; 667 case 3: 668 itemType = ITEM_SHIELD; 669 break; 670 default: 671 break; 672 } 673 } 674 675 switch((sectionNumber_ > 28) ? rand()%29 : rand()%(sectionNumber_+1)) 676 { 677 case 0: 678 platformtype1 = PLATFORM_STATIC; 679 platformtype2 = PLATFORM_STATIC; 680 break; 681 case 1: 682 platformtype1 = PLATFORM_STATIC; 683 platformtype2 = PLATFORM_STATIC; 684 break; 685 case 2: 686 platformtype1 = PLATFORM_STATIC; 687 platformtype2 = PLATFORM_HMOVE; 688 break; 689 case 3: 690 platformtype1 = PLATFORM_STATIC; 691 platformtype2 = PLATFORM_DISAPPEAR; 692 break; 693 case 4: 694 platformtype1 = PLATFORM_STATIC; 695 platformtype2 = PLATFORM_VMOVE; 696 break; 697 case 5: 698 platformtype1 = PLATFORM_STATIC; 699 platformtype2 = PLATFORM_TIMER; 700 break; 701 case 6: 702 platformtype1 = PLATFORM_HMOVE; 703 platformtype2 = PLATFORM_STATIC; 704 break; 705 case 7: 706 platformtype1 = PLATFORM_HMOVE; 707 platformtype2 = PLATFORM_HMOVE; 708 break; 709 case 8: 710 platformtype1 = PLATFORM_HMOVE; 711 platformtype2 = PLATFORM_HMOVE; 712 break; 713 case 9: 714 platformtype1 = PLATFORM_HMOVE; 715 platformtype2 = PLATFORM_DISAPPEAR; 716 break; 717 case 10: 718 platformtype1 = PLATFORM_HMOVE; 719 platformtype2 = PLATFORM_VMOVE; 720 break; 721 case 11: 722 platformtype1 = PLATFORM_HMOVE; 723 platformtype2 = PLATFORM_TIMER; 724 break; 725 case 12: 726 platformtype1 = PLATFORM_DISAPPEAR; 727 platformtype2 = PLATFORM_STATIC; 728 break; 729 case 13: 730 platformtype1 = PLATFORM_DISAPPEAR; 731 platformtype2 = PLATFORM_HMOVE; 732 break; 733 case 14: 734 platformtype1 = PLATFORM_DISAPPEAR; 735 platformtype2 = PLATFORM_DISAPPEAR; 736 break; 737 case 15: 738 platformtype1 = PLATFORM_DISAPPEAR; 739 platformtype2 = PLATFORM_DISAPPEAR; 740 break; 741 case 16: 742 platformtype1 = PLATFORM_DISAPPEAR; 743 platformtype2 = PLATFORM_VMOVE; 744 break; 745 case 17: 746 platformtype1 = PLATFORM_DISAPPEAR; 747 platformtype2 = PLATFORM_TIMER; 748 break; 749 case 18: 750 platformtype1 = PLATFORM_VMOVE; 751 platformtype2 = PLATFORM_STATIC; 752 break; 753 case 19: 754 platformtype1 = PLATFORM_VMOVE; 755 platformtype2 = PLATFORM_HMOVE; 756 break; 757 case 20: 758 platformtype1 = PLATFORM_VMOVE; 759 platformtype2 = PLATFORM_DISAPPEAR; 760 break; 761 case 21: 762 platformtype1 = PLATFORM_VMOVE; 763 platformtype2 = PLATFORM_VMOVE; 764 break; 765 case 22: 766 platformtype1 = PLATFORM_VMOVE; 767 platformtype2 = PLATFORM_VMOVE; 768 break; 769 case 23: 770 platformtype1 = PLATFORM_VMOVE; 771 platformtype2 = PLATFORM_TIMER; 772 break; 773 case 24: 774 platformtype1 = PLATFORM_TIMER; 775 platformtype2 = PLATFORM_STATIC; 776 break; 777 case 25: 778 platformtype1 = PLATFORM_TIMER; 779 platformtype2 = PLATFORM_HMOVE; 780 break; 781 case 26: 782 platformtype1 = PLATFORM_TIMER; 783 platformtype2 = PLATFORM_DISAPPEAR; 784 break; 785 case 27: 786 platformtype1 = PLATFORM_TIMER; 787 platformtype2 = PLATFORM_VMOVE; 788 break; 789 case 28: 790 platformtype1 = PLATFORM_TIMER; 791 platformtype2 = PLATFORM_TIMER; 792 break; 793 default: 794 platformtype1 = PLATFORM_TIMER; 795 platformtype2 = PLATFORM_TIMER; 796 break; 797 } 798 799 // Fill matrix with selected platform types 800 for (int i = 0; i < numI; ++ i) 801 { 802 for (int j = 0; j < numJ; ++ j) 803 { 804 if (rand()%3 == 0) 805 { 806 matrix[i][j].type = platformtype1; 807 } 808 else 809 { 810 matrix[i][j].type = platformtype2; 811 } 812 matrix[i][j].done = false; 813 } 814 } 815 816 if (platformtype1 == platformtype2 && sectionNumber_ > 10 && rand()%2 == 0) 817 { 818 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 819 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 820 } 821 822 // Delete some planned platforms or replace them with fake platforms 823 if (sectionNumber_ > 5) 824 { 825 if (rand()%2 == 0) 826 { 827 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 828 } 829 else 830 { 831 matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; 832 } 833 } 834 else if (sectionNumber_ > 10) 835 { 836 if (rand()%2 == 0) 837 { 838 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 839 } 840 else 841 { 842 matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; 843 } 844 if (rand()%2 == 0) 845 { 846 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 847 } 848 else 849 { 850 matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; 851 } 852 } 853 else if (sectionNumber_ > 15) 854 { 855 if (rand()%2 == 0) 856 { 857 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 858 } 859 else 860 { 861 matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; 862 } 863 if (rand()%2 == 0) 864 { 865 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 866 } 867 else 868 { 869 matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; 870 } 871 if (rand()%2 == 0) 872 { 873 matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; 874 } 875 else 876 { 877 matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; 878 } 879 } 880 881 std::vector<JumpPlatform*> platformList; 882 883 for (int i = 0; i < numI; ++ i) 884 { 885 for (int j = 0; j < numJ; ++ j) 886 { 887 if (matrix[i][j].done == false) 888 { 889 float xPosition = 0.0; 890 float zPosition = 0.0; 891 float leftBoundary = 0.0; 892 float rightBoundary = 0.0; 893 float lowerBoundary = 0.0; 894 float upperBoundary = 0.0; 895 float xVelocity = 0.0; 896 float zVelocity = 0.0; 897 898 switch(matrix[i][j].type) 899 { 900 case PLATFORM_EMPTY: 901 matrix[i][j].done = true; 902 break; 903 case PLATFORM_STATIC: 904 xPosition = randomXPosition(numJ, j); 905 zPosition = sectionBegin + i*sectionLength/numI; 906 platformList.push_back(addPlatformStatic(xPosition, zPosition)); 907 matrix[i][j].done = true; 908 break; 909 case PLATFORM_FAKE: 910 xPosition = randomXPosition(numJ, j); 911 zPosition = sectionBegin + i*sectionLength/numI; 912 platformList.push_back(addPlatformFake(xPosition, zPosition)); 913 matrix[i][j].done = true; 914 break; 915 case PLATFORM_TIMER: 916 xPosition = randomXPosition(numJ, j); 917 zPosition = sectionBegin + i*sectionLength/numI; 918 platformList.push_back(addPlatformTimer(xPosition, zPosition, 12.0, 1.5)); 919 matrix[i][j].done = true; 920 break; 921 case PLATFORM_DISAPPEAR: 922 xPosition = randomXPosition(numJ, j); 923 zPosition = sectionBegin + i*sectionLength/numI; 924 platformList.push_back(addPlatformDisappear(xPosition, zPosition)); 925 matrix[i][j].done = true; 926 break; 927 case PLATFORM_HMOVE: 928 xVelocity = randomSpeed(); 929 if (j <= numJ-3 && matrix[i][j+1].type == PLATFORM_HMOVE && matrix[i][j+2].type == PLATFORM_HMOVE && rand()%2 == 0) 930 { 931 leftBoundary = randomXPositionLeft(numJ, j); 932 rightBoundary = randomXPositionRight(numJ, j+2); 933 xPosition = randomPosition(leftBoundary, rightBoundary); 934 zPosition = sectionBegin + i*sectionLength/numI; 935 platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); 936 matrix[i][j].done = true; 937 matrix[i][j+1].done = true; 938 matrix[i][j+2].done = true; 939 } 940 else if (j <= numJ-2 && matrix[i][j+1].type == PLATFORM_HMOVE && rand()%2 == 0) 941 { 942 leftBoundary = randomXPositionLeft(numJ, j); 943 rightBoundary = randomXPositionRight(numJ, j+1); 944 xPosition = randomPosition(leftBoundary, rightBoundary); 945 zPosition = sectionBegin + i*sectionLength/numI; 946 platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); 947 matrix[i][j].done = true; 948 matrix[i][j+1].done = true; 949 } 950 else 951 { 952 leftBoundary = randomXPositionLeft(numJ, j); 953 rightBoundary = randomXPositionRight(numJ, j); 954 xPosition = randomPosition(leftBoundary, rightBoundary); 955 zPosition = sectionBegin + i*sectionLength/numI; 956 platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); 957 matrix[i][j].done = true; 958 } 959 break; 960 case PLATFORM_VMOVE: 961 zVelocity = randomSpeed(); 962 if (i <= numI-3 && matrix[i+1][j].type == PLATFORM_VMOVE && matrix[i+2][j].type == PLATFORM_VMOVE && rand()%2 == 0) 963 { 964 lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); 965 upperBoundary = randomZPositionUpper(numI, i+2, sectionBegin, sectionEnd); 966 zPosition = randomPosition(lowerBoundary, upperBoundary); 967 xPosition = randomXPosition(numJ, j); 968 platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); 969 matrix[i][j].done = true; 970 matrix[i+1][j].done = true; 971 matrix[i+2][j].done = true; 972 } 973 else if (i <= numI-2 && matrix[i+1][j].type == PLATFORM_VMOVE && rand()%2 == 0) 974 { 975 lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); 976 upperBoundary = randomZPositionUpper(numI, i+1, sectionBegin, sectionEnd); 977 zPosition = randomPosition(lowerBoundary, upperBoundary); 978 xPosition = randomXPosition(numJ, j); 979 platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); 980 matrix[i][j].done = true; 981 matrix[i+1][j].done = true; 982 } 983 else 984 { 985 lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); 986 upperBoundary = randomZPositionUpper(numI, i, sectionBegin, sectionEnd); 987 zPosition = randomPosition(lowerBoundary, upperBoundary); 988 xPosition = randomXPosition(numJ, j); 989 platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); 990 matrix[i][j].done = true; 991 } 992 break; 993 default: 994 //ERROR 995 break; 996 997 } 998 } 999 } 1000 } 1001 1002 //Add items 1003 int numNewPlatforms = platformList.size(); 1004 1005 if (rand()%4 == 0) 1006 { 1007 if (rand()%2 == 0) 1008 { 1009 switch (itemType) 1010 { 1011 case ITEM_ROCKET: 1012 addRocket(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); 1013 break; 1014 case ITEM_PROPELLER: 1015 addPropeller(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); 1016 break; 1017 case ITEM_BOOTS: 1018 addBoots(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); 1019 break; 1020 case ITEM_SHIELD: 1021 addShield(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); 1022 break; 1023 default: 1024 break; 1025 } 1026 } 1027 else 1028 { 1029 switch (itemType) 1030 { 1031 case ITEM_ROCKET: 1032 addRocket(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); 1033 break; 1034 case ITEM_PROPELLER: 1035 addPropeller(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); 1036 break; 1037 case ITEM_BOOTS: 1038 addBoots(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); 1039 break; 1040 case ITEM_SHIELD: 1041 addShield(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); 1042 break; 1043 default: 1044 break; 1045 } 1046 } 1047 } 1048 else 1049 { 1050 if (numNewPlatforms > 0) 1051 { 1052 JumpPlatform* itemPlatform = platformList[rand()%numNewPlatforms]; 1053 1054 switch (itemType) 1055 { 1056 case ITEM_SPRING: 1057 addSpring(itemPlatform); 1058 break; 1059 case ITEM_ROCKET: 1060 addRocket(itemPlatform); 1061 break; 1062 case ITEM_PROPELLER: 1063 addPropeller(itemPlatform); 1064 break; 1065 case ITEM_BOOTS: 1066 addBoots(itemPlatform); 1067 break; 1068 case ITEM_SHIELD: 1069 addShield(itemPlatform); 1070 break; 1071 default: 1072 break; 1073 } 1074 } 1075 } 1076 1076 1077 1077 if (sectionNumber_ >= 5 && rand()%3 == 0) 1078 1078 { 1079 1080 1079 switch(rand()%4) 1080 { 1081 1081 case 0: 1082 1083 1082 addEnemy(1, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); 1083 break; 1084 1084 case 1: 1085 1086 1085 addEnemy(2, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); 1086 break; 1087 1087 case 2: 1088 1089 1088 addEnemy(3, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); 1089 break; 1090 1090 case 3: 1091 1092 1093 1094 } 1095 1091 addEnemy(4, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); 1092 break; 1093 } 1094 } 1095 ++ sectionNumber_; 1096 1096 } 1097 1097 … … 1106 1106 { 1107 1107 case 0: 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1108 { 1109 int numI = 10; 1110 if (rand()%2 == 0) 1111 { 1112 for (int i = 0; i < numI; ++ i) 1113 { 1114 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+i*sectionLength/numI); 1115 } 1116 } 1117 else 1118 { 1119 for (int i = 0; i < numI; ++ i) 1120 { 1121 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+(numI-i)*sectionLength/numI); 1122 } 1123 } 1124 break; 1125 } 1126 1126 case 1: 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1127 { 1128 int numI = 7; 1129 1130 addPlatformStatic(0.0, sectionBegin); 1131 if (rand()%2 == 0) 1132 { 1133 for (int i = 1; i < numI; ++ i) 1134 { 1135 addPlatformStatic((fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); 1136 addPlatformStatic(-(fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); 1137 } 1138 } 1139 else 1140 { 1141 for (int i = 1; i < numI; ++ i) 1142 { 1143 addPlatformStatic((fieldWidth-platformWidth_/2)*i/numI, sectionBegin+(numI-i)*sectionLength/numI); 1144 addPlatformStatic(-(fieldWidth-platformWidth_/2)*i/numI, sectionBegin+(numI-i)*sectionLength/numI); 1145 } 1146 } 1147 break; 1148 } 1149 1149 case 2: 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1150 { 1151 int numI = 5; 1152 for (int i = 0; i <= numI; ++ i) 1153 { 1154 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin); 1155 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength/5); 1156 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*2/5); 1157 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*3/5); 1158 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*4/5); 1159 addEnemy(4, (2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength/2, -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 0.0, 0.0); 1160 } 1161 break; 1162 } 1163 1163 case 3: 1164 1165 1166 1167 1168 1164 { 1165 addRocket(addPlatformStatic(0.0, sectionBegin)); 1166 addEnemy(2, 0.0, sectionBegin+sectionLength/5, 0.0,0.0, 0.0, 0.0, 0.0, 0.0); 1167 break; 1168 } 1169 1169 case 4: 1170 1171 1172 1173 1174 1175 1170 { 1171 addPropeller(addPlatformStatic(0.0, sectionBegin)); 1172 addPropeller(addPlatformStatic(-fieldWidth/2, sectionBegin)); 1173 addPropeller(addPlatformStatic(fieldWidth/2, sectionBegin)); 1174 break; 1175 } 1176 1176 default: 1177 1177 return false; 1178 1178 } 1179 1179 sectionNumber_ +=2; … … 1185 1185 float fieldWidth = center_->getFieldDimension().x; 1186 1186 1187 1187 return (float)(rand()%(2*(int)fieldWidth)) - fieldWidth; 1188 1188 } 1189 1189 1190 1190 float Jump::randomXPosition(int totalColumns, int culomn) 1191 1191 { 1192 1193 1194 1195 1196 1197 1198 1192 float fieldWidth = center_->getFieldDimension().x; 1193 1194 float halfWidth = fieldWidth/totalColumns; 1195 float leftBound = culomn*halfWidth*2-fieldWidth; 1196 float rightBound = leftBound + 2*halfWidth; 1197 1198 return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); 1199 1199 } 1200 1200 1201 1201 float Jump::randomXPositionLeft(int totalColumns, int culomn) 1202 1202 { 1203 1204 1205 1206 1207 1208 1209 1203 float fieldWidth = center_->getFieldDimension().x; 1204 1205 float halfWidth = fieldWidth/totalColumns; 1206 float leftBound = culomn*halfWidth*2-fieldWidth; 1207 float rightBound = leftBound + 2*halfWidth/3; 1208 1209 return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); 1210 1210 } 1211 1211 1212 1212 float Jump::randomXPositionRight(int totalColumns, int culomn) 1213 1213 { 1214 1215 1216 1217 1218 1219 1214 float fieldWidth = center_->getFieldDimension().x; 1215 1216 float halfWidth = fieldWidth/totalColumns; 1217 float rightBound = (culomn+1)*halfWidth*2-fieldWidth; 1218 float leftBound = rightBound - 2*halfWidth/3; 1219 return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); 1220 1220 } 1221 1221 1222 1222 float Jump::randomZPosition(int totalRows, int row, float sectionBegin, float SectionEnd) 1223 1223 { 1224 1225 1226 1227 1228 1229 1224 float fieldHeight = SectionEnd - sectionBegin; 1225 float halfHeight = fieldHeight/totalRows; 1226 float lowerBound = row*halfHeight*2+sectionBegin; 1227 float upperBound = lowerBound + 2*halfHeight; 1228 1229 return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); 1230 1230 } 1231 1231 1232 1232 float Jump::randomZPositionLower(int totalRows, int row, float sectionBegin, float SectionEnd) 1233 1233 { 1234 1235 1236 1237 1238 1239 1234 float fieldHeight = SectionEnd - sectionBegin; 1235 float rowHeight = fieldHeight/totalRows; 1236 float lowerBound = row*rowHeight+sectionBegin; 1237 float upperBound = lowerBound + rowHeight/3; 1238 1239 return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); 1240 1240 } 1241 1241 1242 1242 float Jump::randomZPositionUpper(int totalRows, int row, float sectionBegin, float SectionEnd) 1243 1243 { 1244 1245 1246 1247 1248 1249 1244 float fieldHeight = SectionEnd - sectionBegin; 1245 float rowHeight = fieldHeight/totalRows; 1246 float lowerBound = (row+1)*rowHeight+sectionBegin; 1247 float upperBound = lowerBound - rowHeight/3; 1248 1249 return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); 1250 1250 } 1251 1251 1252 1252 float Jump::randomPosition(float lowerBoundary, float upperBoundary) 1253 1253 { 1254 1255 1256 1257 1258 1259 1254 if (lowerBoundary >= upperBoundary) 1255 { 1256 return (lowerBoundary + upperBoundary)/2; 1257 } 1258 1259 return (float)(rand()%(int)(100*(upperBoundary - lowerBoundary)))/100 + lowerBoundary; 1260 1260 } 1261 1261 1262 1262 float Jump::randomSpeed() 1263 1263 { 1264 1265 1264 float platformSpeed = center_->getPlatformSpeed(); 1265 return randomPosition(0.5*platformSpeed, 1.5*platformSpeed); 1266 1266 } 1267 1267 -
code/branches/presentationFS14/src/modules/jump/JumpBoots.cc
r10078 r10215 83 83 if(figurePosition.x > rocketPosition.x-width_ && figurePosition.x < rocketPosition.x+width_ && figurePosition.z > rocketPosition.z-height_ && figurePosition.z < rocketPosition.z+height_) 84 84 { 85 85 touchFigure(); 86 86 } 87 87 } 88 88 else if (attachedToFigure_ == true) 89 89 { 90 91 92 93 94 90 fuel_ -= dt; 91 if (fuel_ < 0.0) 92 { 93 figure_->StopBoots(this); 94 } 95 95 } 96 96 } … … 98 98 void JumpBoots::touchFigure() 99 99 { 100 100 JumpItem::touchFigure(); 101 101 102 102 attachedToFigure_ = figure_->StartBoots(this); 103 103 } 104 104 } -
code/branches/presentationFS14/src/modules/jump/JumpEnemy.cc
r10078 r10215 107 107 if ((position.x < leftBoundary_ && velocity.x < 0) || (position.x > rightBoundary_ && velocity.x > 0)) 108 108 { 109 109 velocity.x = -velocity.x; 110 110 } 111 111 112 112 if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0)) 113 113 { 114 114 velocity.z = -velocity.z; 115 115 } 116 116 … … 130 130 if(figurePosition.x > enemyPosition.x-width_ && figurePosition.x < enemyPosition.x+width_ && figurePosition.z > enemyPosition.z-height_ && figurePosition.z < enemyPosition.z+height_) 131 131 { 132 132 touchFigure(); 133 133 } 134 134 } … … 158 158 void JumpEnemy::touchFigure() 159 159 { 160 161 162 163 160 if (dead_ == false) 161 { 162 figure_->CollisionWithEnemy(this); 163 } 164 164 } 165 165 } -
code/branches/presentationFS14/src/modules/jump/JumpFigure.cc
r10078 r10215 45 45 RegisterObject(JumpFigure); 46 46 47 47 // initialize variables 48 48 leftHand_ = NULL; 49 49 rightHand_ = NULL; … … 98 98 void JumpFigure::tick(float dt) 99 99 { 100 100 SUPER(JumpFigure, tick, dt); 101 101 102 102 if (hasLocalController()) 103 103 { 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 104 timeSinceLastFire_ += dt; 105 106 // Move up/down 107 Vector3 velocity = getVelocity(); 108 if (rocketActive_ == true) 109 { 110 velocity.z = rocketSpeed_; 111 } 112 else if (propellerActive_ == true) 113 { 114 velocity.z = propellerSpeed_; 115 } 116 else 117 { 118 velocity.z -= gravityAcceleration_; 119 } 120 121 // Animate Hands 122 if (animateHands_ == true) 123 { 124 if (turnUp_ == true) 125 { 126 handAngle_ += handSpeed_ * dt; 127 } 128 else 129 { 130 handAngle_ -= handSpeed_ * dt; 131 } 132 if (handAngle_ > handMaxAngle_) 133 { 134 turnUp_ = false; 135 } 136 if (handAngle_ <= handMinAngle_) 137 { 138 animateHands_ = false; 139 } 140 141 if (leftHand_ != NULL) 142 { 143 leftHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(-handAngle_)); 144 } 145 if (rightHand_ != NULL) 146 { 147 rightHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(handAngle_)); 148 } 149 } 150 151 // Move left/right 152 if (dead_ == false) 153 { 154 velocity.x = -mouseFactor_*horizontalSpeed_; 155 } 156 else 157 { 158 velocity.x = 0.0; 159 } 160 161 // Cheats 162 /*if (moveUpPressed_ == true) 163 { 164 velocity.z = 400.0f; 165 moveUpPressed_ = false; 166 dead_ = false; 167 } 168 if (moveDownPressed_ == true) 169 { 170 moveDownPressed_ = false; 171 }*/ 172 173 setVelocity(velocity); 174 175 176 if (firePressed_ && timeSinceLastFire_ >= maxFireRate_) 177 { 178 firePressed_ = false; 179 timeSinceLastFire_ = 0.0; 180 fireSignal_ = true; 181 } 182 182 } 183 183 … … 186 186 if (position.x < -fieldWidth_*1.1) 187 187 { 188 188 position.x = fieldWidth_*1.1; 189 189 } 190 190 else if (position.x > fieldWidth_*1.1) 191 191 { 192 192 position.x = -fieldWidth_*1.1; 193 193 } 194 194 setPosition(position); … … 204 204 void JumpFigure::JumpFromPlatform(JumpPlatform* platform) 205 205 { 206 207 208 209 210 211 212 213 214 215 206 if (dead_ == false) 207 { 208 Vector3 velocity = getVelocity(); 209 velocity.z = (bootsActive_ ? 1.2*jumpSpeed_ : jumpSpeed_); 210 setVelocity(velocity); 211 212 animateHands_ = true; 213 handAngle_ = 0.0; 214 turnUp_ = true; 215 } 216 216 } 217 217 218 218 void JumpFigure::JumpFromSpring(JumpSpring* spring) 219 219 { 220 221 222 223 224 225 220 if (dead_ == false) 221 { 222 Vector3 velocity = getVelocity(); 223 velocity.z = 1.2*jumpSpeed_; 224 setVelocity(velocity); 225 } 226 226 } 227 227 228 228 void JumpFigure::CollisionWithEnemy(JumpEnemy* enemy) 229 230 231 232 233 234 229 { 230 if (rocketActive_ == false && propellerActive_ == false && shieldActive_ == false) 231 { 232 dead_ = true; 233 } 234 } 235 235 236 236 bool JumpFigure::StartRocket(JumpRocket* rocket) 237 237 { 238 239 240 241 242 243 244 245 246 247 248 238 if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) 239 { 240 attach(rocket); 241 rocket->setPosition(0.0, rocketPos_, 0.0); 242 rocket->setVelocity(0.0, 0.0, 0.0); 243 rocketActive_ = true; 244 245 return true; 246 } 247 248 return false; 249 249 } 250 250 251 251 void JumpFigure::StopRocket(JumpRocket* rocket) 252 252 { 253 254 255 256 257 253 rocket->setPosition(0.0, 0.0, -1000.0); 254 rocket->setVelocity(0.0, 0.0, 0.0); 255 detach(rocket); 256 rocket->destroy(); 257 rocketActive_ = false; 258 258 } 259 259 260 260 bool JumpFigure::StartPropeller(JumpPropeller* propeller) 261 261 { 262 263 264 265 266 267 268 269 270 271 272 262 if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) 263 { 264 attach(propeller); 265 propeller->setPosition(0.0, 0.0, propellerPos_); 266 propeller->setVelocity(0.0, 0.0, 0.0); 267 propellerActive_ = true; 268 269 return true; 270 } 271 272 return false; 273 273 } 274 274 275 275 void JumpFigure::StopPropeller(JumpPropeller* propeller) 276 276 { 277 278 279 280 281 277 propeller->setPosition(0.0, 0.0, -1000.0); 278 propeller->setVelocity(0.0, 0.0, 0.0); 279 detach(propeller); 280 propeller->destroy(); 281 propellerActive_ = false; 282 282 } 283 283 284 284 bool JumpFigure::StartBoots(JumpBoots* boots) 285 285 { 286 287 288 289 290 291 292 293 294 295 296 286 if (rocketActive_ == false && propellerActive_ == false && bootsActive_ == false) 287 { 288 attach(boots); 289 boots->setPosition(0.0, 0.0, bootsPos_); 290 boots->setVelocity(0.0, 0.0, 0.0); 291 bootsActive_ = true; 292 293 return true; 294 } 295 296 return false; 297 297 } 298 298 299 299 void JumpFigure::StopBoots(JumpBoots* boots) 300 300 { 301 302 303 304 305 301 boots->setPosition(0.0, 0.0, -1000.0); 302 boots->setVelocity(0.0, 0.0, 0.0); 303 detach(boots); 304 boots->destroy(); 305 bootsActive_ = false; 306 306 } 307 307 308 308 bool JumpFigure::StartShield(JumpShield* shield) 309 309 { 310 311 312 313 314 315 316 317 318 319 320 310 if (shieldActive_ == false) 311 { 312 attach(shield); 313 shield->setPosition(0.0, 0.0, propellerPos_); 314 shield->setVelocity(0.0, 0.0, 0.0); 315 shieldActive_ = true; 316 317 return true; 318 } 319 320 return false; 321 321 } 322 322 323 323 void JumpFigure::StopShield(JumpShield* shield) 324 324 { 325 326 327 328 329 325 shield->setPosition(0.0, 0.0, -1000.0); 326 shield->setVelocity(0.0, 0.0, 0.0); 327 detach(shield); 328 shield->destroy(); 329 shieldActive_ = false; 330 330 } 331 331 332 332 void JumpFigure::InitializeAnimation(Context* context) 333 333 { 334 335 336 337 338 339 340 341 334 leftHand_ = new Model(context); 335 rightHand_ = new Model(context); 336 337 leftHand_->addTemplate(modelLeftHand_); 338 rightHand_->addTemplate(modelRightHand_); 339 340 attach(leftHand_); 341 attach(rightHand_); 342 342 } 343 343 344 344 void JumpFigure::moveFrontBack(const Vector2& value) 345 345 { 346 347 348 349 350 351 352 353 354 355 346 if (value.x > 0) 347 { 348 moveUpPressed_ = true; 349 moveDownPressed_ = false; 350 } 351 else 352 { 353 moveUpPressed_ = false; 354 moveDownPressed_ = true; 355 } 356 356 } 357 357 358 358 void JumpFigure::moveRightLeft(const Vector2& value) 359 359 { 360 361 362 363 364 365 366 367 368 369 360 if (value.x > 0) 361 { 362 moveLeftPressed_ = false; 363 moveRightPressed_ = true; 364 } 365 else 366 { 367 moveLeftPressed_ = true; 368 moveRightPressed_ = false; 369 } 370 370 } 371 371 372 372 void JumpFigure::rotateYaw(const Vector2& value) 373 373 { 374 374 horizontalSpeed_ = value.x; 375 375 } 376 376 … … 394 394 void JumpFigure::fired(unsigned int firemode) 395 395 { 396 396 firePressed_ = true; 397 397 } 398 398 } -
code/branches/presentationFS14/src/modules/jump/JumpFigure.h
r10078 r10215 85 85 const float getRocketPos() const 86 86 { return rocketPos_; } 87 88 89 90 91 92 93 94 87 void setPropellerPos(const float propellerPos) 88 { propellerPos_ = propellerPos; } 89 const float getPropellerPos() const 90 { return propellerPos_; } 91 void setBootsPos(const float bootsPos) 92 { bootsPos_ = bootsPos; } 93 const float getBootsPos() const 94 { return bootsPos_; } 95 95 void setJumpSpeed(const float jumpSpeed) 96 96 { jumpSpeed_ = jumpSpeed; } -
code/branches/presentationFS14/src/modules/jump/JumpItem.cc
r10078 r10215 84 84 if ((position.x < leftBoundary_ && velocity.x < 0) || (position.x > rightBoundary_ && velocity.x > 0)) 85 85 { 86 86 velocity.x = -velocity.x; 87 87 } 88 88 89 89 if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0)) 90 90 { 91 91 velocity.z = -velocity.z; 92 92 } 93 93 -
code/branches/presentationFS14/src/modules/jump/JumpPlatform.cc
r10078 r10215 56 56 //initialize sound 57 57 if (GameMode::isMaster()) 58 59 60 61 62 63 64 65 66 67 68 69 70 71 58 { 59 defScoreSound_ = new WorldSound(this->getContext()); 60 defScoreSound_->setVolume(1.0f); 61 defBatSound_ = new WorldSound(this->getContext()); 62 defBatSound_->setVolume(0.4f); 63 defBoundarySound_ = new WorldSound(this->getContext()); 64 defBoundarySound_->setVolume(0.5f); 65 } 66 else 67 { 68 defScoreSound_ = 0; 69 defBatSound_ = 0; 70 defBoundarySound_ = 0; 71 } 72 72 73 73 setPosition(Vector3(0,0,0)); … … 120 120 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) 121 121 { 122 122 touchFigure(); 123 123 } 124 124 } -
code/branches/presentationFS14/src/modules/jump/JumpPlatformDisappear.cc
r10078 r10215 72 72 void JumpPlatformDisappear::setProperties(bool active) 73 73 { 74 74 active_ = active; 75 75 } 76 76 77 77 bool JumpPlatformDisappear::isActive() 78 78 { 79 79 return active_; 80 80 } 81 81 82 82 void JumpPlatformDisappear::touchFigure() 83 83 { 84 85 86 87 88 84 if (isActive()) 85 { 86 figure_->JumpFromPlatform(this); 87 active_ = false; 88 } 89 89 } 90 90 } -
code/branches/presentationFS14/src/modules/jump/JumpPlatformDisappear.h
r10078 r10215 45 45 { 46 46 public: 47 47 JumpPlatformDisappear(Context* context); 48 48 virtual ~JumpPlatformDisappear(); 49 49 virtual void tick(float dt); -
code/branches/presentationFS14/src/modules/jump/JumpPlatformFake.h
r10078 r10215 48 48 { 49 49 public: 50 50 JumpPlatformFake(Context* context); 51 51 virtual ~JumpPlatformFake(); 52 52 virtual void tick(float dt); -
code/branches/presentationFS14/src/modules/jump/JumpPlatformHMove.cc
r10078 r10215 72 72 73 73 { 74 74 velocity.x = -velocity.x; 75 75 } 76 76 … … 88 88 void JumpPlatformHMove::setProperties(float leftBoundary, float rightBoundary, float speed) 89 89 { 90 91 90 leftBoundary_ = leftBoundary; 91 rightBoundary_ = rightBoundary; 92 92 setVelocity(Vector3(speed,0,0)); 93 93 } … … 95 95 void JumpPlatformHMove::touchFigure() 96 96 { 97 97 figure_->JumpFromPlatform(this); 98 98 } 99 99 } -
code/branches/presentationFS14/src/modules/jump/JumpPlatformHMove.h
r10078 r10215 43 43 { 44 44 public: 45 45 JumpPlatformHMove(Context* context); 46 46 virtual ~JumpPlatformHMove(); 47 47 virtual void tick(float dt); -
code/branches/presentationFS14/src/modules/jump/JumpPlatformStatic.cc
r10078 r10215 68 68 void JumpPlatformStatic::touchFigure() 69 69 { 70 70 figure_->JumpFromPlatform(this); 71 71 } 72 72 } -
code/branches/presentationFS14/src/modules/jump/JumpPlatformStatic.h
r10078 r10215 42 42 { 43 43 public: 44 44 JumpPlatformStatic(Context* context); 45 45 virtual ~JumpPlatformStatic(); 46 46 -
code/branches/presentationFS14/src/modules/jump/JumpPlatformTimer.cc
r10078 r10215 75 75 { 76 76 77 78 77 particleSpawner_ = new ParticleSpawner(getContext()); 78 particleSpawner_->setSource(effectPath_); 79 79 particleSpawner_->setLoop(false); 80 80 particleSpawner_->setLOD(LODParticle::Low); … … 87 87 void JumpPlatformTimer::setProperties(float time) 88 88 { 89 89 time_ = time; 90 90 } 91 91 92 92 bool JumpPlatformTimer::isActive(void) 93 93 { 94 94 return time_ > 0.0; 95 95 } 96 96 97 97 void JumpPlatformTimer::touchFigure() 98 98 { 99 100 101 102 99 if (isActive()) 100 { 101 figure_->JumpFromPlatform(this); 102 } 103 103 } 104 104 } -
code/branches/presentationFS14/src/modules/jump/JumpPlatformTimer.h
r10078 r10215 49 49 { 50 50 public: 51 51 JumpPlatformTimer(Context* context); 52 52 virtual ~JumpPlatformTimer(); 53 53 virtual void tick(float dt); -
code/branches/presentationFS14/src/modules/jump/JumpPlatformVMove.cc
r10078 r10215 71 71 if ((position.z < lowerBoundary_ && velocity.z < 0) || (position.z > upperBoundary_ && velocity.z > 0)) 72 72 { 73 73 velocity.z = -velocity.z; 74 74 } 75 75 … … 87 87 void JumpPlatformVMove::setProperties(float lowerBoundary, float upperBoundary, float speed) 88 88 { 89 90 89 lowerBoundary_ = lowerBoundary; 90 upperBoundary_ = upperBoundary; 91 91 92 92 setVelocity(Vector3(0,0,speed)); … … 96 96 void JumpPlatformVMove::touchFigure() 97 97 { 98 98 figure_->JumpFromPlatform(this); 99 99 } 100 100 } -
code/branches/presentationFS14/src/modules/jump/JumpPlatformVMove.h
r10078 r10215 39 39 { 40 40 public: 41 41 JumpPlatformVMove(Context* context); 42 42 virtual ~JumpPlatformVMove(); 43 43 virtual void tick(float dt); -
code/branches/presentationFS14/src/modules/jump/JumpProjectile.cc
r10078 r10215 71 71 Vector3 projectilePosition = getPosition(); 72 72 73 74 75 76 77 73 for (ObjectList<JumpEnemy>::iterator it = ObjectList<JumpEnemy>::begin(); it != ObjectList<JumpEnemy>::end(); ++it) 74 { 75 Vector3 enemyPosition = it->getPosition(); 76 float enemyWidth = it->getWidth(); 77 float enemyHeight = it->getHeight(); 78 78 79 80 81 82 83 79 if(projectilePosition.x > enemyPosition.x-enemyWidth && projectilePosition.x < enemyPosition.x+enemyWidth && projectilePosition.z > enemyPosition.z-enemyHeight && projectilePosition.z < enemyPosition.z+enemyHeight) 80 { 81 it->dead_ = true; 82 } 83 } 84 84 } 85 85 -
code/branches/presentationFS14/src/modules/jump/JumpPropeller.cc
r10078 r10215 83 83 if(figurePosition.x > PropellerPosition.x-width_ && figurePosition.x < PropellerPosition.x+width_ && figurePosition.z > PropellerPosition.z-height_ && figurePosition.z < PropellerPosition.z+height_) 84 84 { 85 85 touchFigure(); 86 86 } 87 87 } 88 88 else if (attachedToFigure_ == true) 89 89 { 90 91 92 93 94 90 fuel_ -= dt; 91 if (fuel_ < 0.0) 92 { 93 figure_->StopPropeller(this); 94 } 95 95 } 96 96 } … … 98 98 void JumpPropeller::touchFigure() 99 99 { 100 100 JumpItem::touchFigure(); 101 101 102 103 104 105 106 102 attachedToFigure_ = figure_->StartPropeller(this); 103 if (attachedToFigure_) 104 { 105 setAngularVelocity(Vector3(0,0,10.0)); 106 } 107 107 } 108 108 } -
code/branches/presentationFS14/src/modules/jump/JumpRocket.cc
r10078 r10215 80 80 if(figurePosition.x > rocketPosition.x-width_ && figurePosition.x < rocketPosition.x+width_ && figurePosition.z > rocketPosition.z-height_ && figurePosition.z < rocketPosition.z+height_) 81 81 { 82 82 touchFigure(); 83 83 } 84 84 } 85 85 else if (attachedToFigure_ == true) 86 86 { 87 88 89 90 91 87 fuel_ -= dt; 88 if (fuel_ < 0.0) 89 { 90 figure_->StopRocket(this); 91 } 92 92 } 93 93 } … … 95 95 void JumpRocket::touchFigure() 96 96 { 97 97 JumpItem::touchFigure(); 98 98 99 99 attachedToFigure_ = figure_->StartRocket(this); 100 100 } 101 101 } -
code/branches/presentationFS14/src/modules/jump/JumpScore.cc
r10078 r10215 79 79 if (player_ != NULL) 80 80 { 81 82 83 81 if (showScore_ == true) 82 { 83 int score = owner_->getScore(player_); 84 84 85 86 87 88 89 85 std::string str = multi_cast<std::string>(score); 86 setCaption(str); 87 } 88 else if (showMessages_ == true) 89 { 90 90 91 92 91 setCaption(owner_->getDead(player_) == true ? gameOverText_ : ""); 92 } 93 93 } 94 94 } -
code/branches/presentationFS14/src/modules/jump/JumpShield.cc
r10078 r10215 83 83 if(figurePosition.x > shieldPosition.x-width_ && figurePosition.x < shieldPosition.x+width_ && figurePosition.z > shieldPosition.z-height_ && figurePosition.z < shieldPosition.z+height_) 84 84 { 85 85 touchFigure(); 86 86 } 87 87 } 88 88 else if (attachedToFigure_ == true) 89 89 { 90 91 92 93 94 90 fuel_ -= dt; 91 if (fuel_ < 0.0) 92 { 93 figure_->StopShield(this); 94 } 95 95 } 96 96 } … … 98 98 void JumpShield::touchFigure() 99 99 { 100 100 JumpItem::touchFigure(); 101 101 102 102 attachedToFigure_ = figure_->StartShield(this); 103 103 } 104 104 } -
code/branches/presentationFS14/src/modules/jump/JumpSpring.cc
r10078 r10215 74 74 if (stretch_ > 1.0) 75 75 { 76 77 76 stretch_ -= dt; 77 setScale3D(1.0, 1.0, stretch_); 78 78 } 79 79 … … 87 87 if(figureVelocity.z < 0 && figurePosition.x > springPosition.x-width_ && figurePosition.x < springPosition.x+width_ && figurePosition.z > springPosition.z-height_ && figurePosition.z < springPosition.z+height_) 88 88 { 89 89 touchFigure(); 90 90 } 91 91 } … … 94 94 void JumpSpring::touchFigure() 95 95 { 96 96 JumpItem::touchFigure(); 97 97 98 98 stretch_ = 3.0; 99 99 100 100 accelerateFigure(); 101 101 } 102 102 103 103 void JumpSpring::accelerateFigure() 104 104 { 105 106 107 108 105 if (figure_ != 0) 106 { 107 figure_->JumpFromSpring(this); 108 } 109 109 } 110 110 } -
code/branches/presentationFS14/src/modules/objects/controllers/TeamTargetProxy.cc
r10072 r10215 33 33 namespace orxonox 34 34 { 35 35 RegisterClass(TeamTargetProxy); 36 36 37 37 /** … … 42 42 The context 43 43 */ 44 45 46 44 TeamTargetProxy::TeamTargetProxy(Context* context) : FormationController(context) 45 { 46 RegisterObject(TeamTargetProxy); 47 47 48 49 48 this->once_ = false; 49 } 50 50 51 51 /** … … 53 53 Destructor. Nothing to see here. 54 54 */ 55 56 57 55 TeamTargetProxy::~TeamTargetProxy() 56 { 57 } 58 58 59 59 /** … … 63 63 That's all there is. 64 64 */ 65 66 67 68 65 void TeamTargetProxy::tick(float dt) 66 { 67 if (!this->isActive() || !this->getControllableEntity()) 68 return; 69 69 70 70 ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent()); … … 102 102 } 103 103 } 104 104 } 105 105 } -
code/branches/presentationFS14/src/modules/objects/controllers/TeamTargetProxy.h
r10072 r10215 35 35 namespace orxonox 36 36 { 37 38 39 37 /** 38 @brief 39 A controller, that just copies the team and the target of a parent for itself and it's controllable entity. 40 40 41 42 43 44 45 46 47 48 49 50 51 41 Useful for following (and similar) situations: (-> means attached to) 42 turret (rotates) -> some kind of turret base (looks nice) -> spaceship (flies around) 43 The turret has a controller that wants to copy the spaceship's target and team. In this case it doesn't work though, 44 because the turret isn't directly attached to the spaceship. Here's where this controller comes in. Drawback: the base 45 has to be controllable and ticks every second (performance?) 46 */ 47 class _OrxonoxExport TeamTargetProxy : public FormationController, public Tickable 48 { 49 public: 50 TeamTargetProxy(Context* context); 51 virtual ~TeamTargetProxy(); 52 52 53 53 virtual void tick(float dt); 54 54 55 56 57 55 private: 56 bool once_; //!< Flag for executing code in the tick function only once. 57 }; 58 58 } 59 59 -
code/branches/presentationFS14/src/modules/objects/controllers/TurretController.cc
r10072 r10215 33 33 namespace orxonox 34 34 { 35 35 RegisterClass(TurretController); 36 36 37 37 /** … … 42 42 The context 43 43 */ 44 45 46 47 48 49 50 44 TurretController::TurretController(Context* context) : ArtificialController(context) 45 { 46 RegisterObject(TurretController); 47 48 this->once_ = false; 49 50 } 51 51 52 52 /** … … 54 54 Destructor. Nothing to see here. 55 55 */ 56 57 58 59 56 TurretController::~TurretController() 57 { 58 59 } 60 60 61 61 /** … … 69 69 The function that scores the pawns. 70 70 */ 71 72 71 void TurretController::searchTarget() 72 { 73 73 Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity()); 74 74 … … 76 76 if(this->target_ && turret->isInRange(target_) != -1.f && !FormationController::sameTeam(turret, this->target_, this->getGametype())) 77 77 { 78 78 return; 79 79 } 80 80 else 81 81 { 82 83 82 this->forgetTarget(); 83 turret->setTarget(0); 84 84 } 85 85 … … 88 88 if(parent) 89 89 { 90 91 92 93 94 95 96 90 Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget()); 91 if(parenttarget && turret->isInRange(parenttarget)) 92 { 93 this->setTarget(parenttarget); 94 turret->setTarget(parenttarget); 95 return; 96 } 97 97 } 98 98 … … 101 101 Pawn* minScorePawn = 0; 102 102 103 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)104 { 105 103 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it) 104 { 105 Pawn* entity = orxonox_cast<Pawn*>(*it); 106 106 if (!entity || FormationController::sameTeam(this->getControllableEntity(), entity, this->getGametype())) 107 107 continue; 108 108 tempScore = turret->isInRange(entity); 109 109 if(tempScore != -1.f) 110 110 { 111 112 113 114 115 116 } 117 111 if(tempScore < minScore) 112 { 113 minScore = tempScore; 114 minScorePawn = entity; 115 } 116 } 117 } 118 118 this->setTarget(minScorePawn); 119 119 turret->setTarget(minScorePawn); 120 120 } 121 121 122 122 /** … … 124 124 Tests, if the turret is looking at the target, with a specified tolerance 125 125 126 127 128 129 126 This uses the world position as opposed to the local position in the old version. 127 128 @param angle 129 The tolerance, in radians 130 130 */ 131 131 bool TurretController::isLookingAtTargetNew(float angle) const … … 140 140 The more health and distance a pawn has, the higher the score. This means lower equals better. 141 141 142 143 144 145 146 142 @param pawn 143 The pawn to score 144 145 @param distance 146 The distance. Can be squared or normed, doesn't matter as long as all are treated the same. 147 147 */ 148 149 150 151 152 153 /** 154 155 156 157 158 159 */ 160 161 162 163 148 float TurretController::targetScore(Pawn* pawn, float distance) const 149 { 150 return pawn->getHealth()/pawn->getMaxHealth() + distance; 151 } 152 153 /** 154 @brief 155 Does all the controlling of the turret. 156 157 If the turret has a parent, copies the team from there, if it's not already set. 158 Other actions are: Search a target. If a target has been found, aim and shoot at it. 159 */ 160 void TurretController::tick(float dt) 161 { 162 if (!this->isActive() || !this->getControllableEntity()) 163 return; 164 164 165 165 … … 171 171 172 172 if(!this->once_) 173 173 this->once_ = true; 174 174 175 175 //Teams aren't set immediately, after creation, so we have to check every tick... … … 188 188 } 189 189 190 191 192 193 194 195 196 197 198 199 200 201 190 this->searchTarget(); 191 if(this->target_) 192 { 193 Turret* turret = orxonox_cast<Turret*> (this->getControllableEntity()); 194 this->aimAtTarget(); 195 turret->aimAtPosition(target_->getWorldPosition()); 196 if(this->isLookingAtTargetNew(Degree(5).valueRadians())) 197 { 198 this->getControllableEntity()->fire(0); 199 } 200 } 201 } 202 202 } -
code/branches/presentationFS14/src/modules/objects/controllers/TurretController.h
r10072 r10215 39 39 namespace orxonox 40 40 { 41 42 43 41 /** 42 @brief 43 Controller for turrets. Chooses a target, and makes the turret aim/shoot at it. 44 44 45 46 47 48 49 50 51 45 The controllableEntity gets casted to Turret, so this controller won't work for anything else. 46 */ 47 class _OrxonoxExport TurretController : public ArtificialController, public Tickable 48 { 49 public: 50 TurretController(Context* context); 51 virtual ~TurretController(); 52 52 53 53 virtual void tick(float dt); 54 54 55 55 private: 56 56 57 58 59 57 void searchTarget(); 58 bool isLookingAtTargetNew(float angle) const; 59 float targetScore(Pawn* pawn, float distance) const; 60 60 61 62 61 bool once_; //!< Flag for executing code in the tick function only once. 62 }; 63 63 } 64 64 -
code/branches/presentationFS14/src/orxonox/controllers/ControllerDirector.cc
r10077 r10215 106 106 } 107 107 108 109 108 bool ControllerDirector::preparationToTakeControl(BaseObject * trigger) 110 109 { … … 130 129 } 131 130 132 133 131 this->entity_ = this->player_->getControllableEntity(); 132 assert(this->entity_); 134 133 135 134 return true; -
code/branches/presentationFS14/src/orxonox/controllers/ControllerDirector.h
r10076 r10215 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 46 bool party(bool bTriggered, BaseObject* trigger); 47 48 49 47 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 48 49 50 50 /* Take over control of a given object */ 51 52 51 void takeControl(Controller * controller, BaseObject * trigger); 52 bool preparationToTakeControl(BaseObject * trigger); 53 53 54 54 // currently unused 55 //void setNewController(Controller * controller); 56 57 55 //void setNewController(Controller * controller); 58 56 59 57 private: 60 61 58 PlayerInfo* player_; 62 59 ControllableEntity* entity_; 63 60 PlayerTrigger * pTrigger_; 64 61 Context* context_; 65 66 67 62 }; 68 63 }
Note: See TracChangeset
for help on using the changeset viewer.