| 1 | /* | 
|---|
| 2 |  *   ORXONOX - the hottest 3D action shooter ever to exist | 
|---|
| 3 |  *                    > www.orxonox.net < | 
|---|
| 4 |  * | 
|---|
| 5 |  * | 
|---|
| 6 |  *   License notice: | 
|---|
| 7 |  * | 
|---|
| 8 |  *   This program is free software; you can redistribute it and/or | 
|---|
| 9 |  *   modify it under the terms of the GNU General Public License | 
|---|
| 10 |  *   as published by the Free Software Foundation; either version 2 | 
|---|
| 11 |  *   of the License, or (at your option) any later version. | 
|---|
| 12 |  * | 
|---|
| 13 |  *   This program is distributed in the hope that it will be useful, | 
|---|
| 14 |  *   but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 |  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 |  *   GNU General Public License for more details. | 
|---|
| 17 |  * | 
|---|
| 18 |  *   You should have received a copy of the GNU General Public License | 
|---|
| 19 |  *   along with this program; if not, write to the Free Software | 
|---|
| 20 |  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | 
|---|
| 21 |  * | 
|---|
| 22 |  *   Author: | 
|---|
| 23 |  *      Fabien Vultier | 
|---|
| 24 |  *   Co-authors: | 
|---|
| 25 |  *      ... | 
|---|
| 26 |  * | 
|---|
| 27 |  */ | 
|---|
| 28 |  | 
|---|
| 29 | /** | 
|---|
| 30 |     @file Jump.cc | 
|---|
| 31 |     @brief This is the gametype for the awesome minigame. Here the level is randomly created, the camera is shifted, ... | 
|---|
| 32 | */ | 
|---|
| 33 |  | 
|---|
| 34 | #include "Jump.h" | 
|---|
| 35 | #include "core/CoreIncludes.h" | 
|---|
| 36 | #include "Highscore.h" | 
|---|
| 37 |  | 
|---|
| 38 | #include "JumpCenterpoint.h" | 
|---|
| 39 | #include "JumpPlatform.h" | 
|---|
| 40 | #include "JumpPlatformStatic.h" | 
|---|
| 41 | #include "JumpPlatformHMove.h" | 
|---|
| 42 | #include "JumpPlatformVMove.h" | 
|---|
| 43 | #include "JumpPlatformDisappear.h" | 
|---|
| 44 | #include "JumpPlatformTimer.h" | 
|---|
| 45 | #include "JumpPlatformFake.h" | 
|---|
| 46 | #include "JumpProjectile.h" | 
|---|
| 47 | #include "JumpEnemy.h" | 
|---|
| 48 | #include "JumpFigure.h" | 
|---|
| 49 | #include "JumpItem.h" | 
|---|
| 50 | #include "JumpSpring.h" | 
|---|
| 51 | #include "JumpRocket.h" | 
|---|
| 52 | #include "JumpPropeller.h" | 
|---|
| 53 | #include "JumpBoots.h" | 
|---|
| 54 | #include "JumpShield.h" | 
|---|
| 55 |  | 
|---|
| 56 | #include "gamestates/GSLevel.h" | 
|---|
| 57 | #include "infos/PlayerInfo.h" | 
|---|
| 58 | #include "graphics/Camera.h" | 
|---|
| 59 |  | 
|---|
| 60 | namespace orxonox | 
|---|
| 61 | { | 
|---|
| 62 |     RegisterUnloadableClass(Jump); | 
|---|
| 63 |  | 
|---|
| 64 |     Jump::Jump(Context* context) : Deathmatch(context) | 
|---|
| 65 |     { | 
|---|
| 66 |         RegisterObject(Jump); | 
|---|
| 67 |  | 
|---|
| 68 |         center_ = nullptr; | 
|---|
| 69 |         figure_ = nullptr; | 
|---|
| 70 |         camera = nullptr; | 
|---|
| 71 |         setHUDTemplate("JumpHUD"); | 
|---|
| 72 |     } | 
|---|
| 73 |  | 
|---|
| 74 |     Jump::~Jump() | 
|---|
| 75 |     { | 
|---|
| 76 |         if (isInitialized()) | 
|---|
| 77 |         { | 
|---|
| 78 |             cleanup(); | 
|---|
| 79 |         } | 
|---|
| 80 |     } | 
|---|
| 81 |  | 
|---|
| 82 |     void Jump::tick(float dt) | 
|---|
| 83 |     { | 
|---|
| 84 |         SUPER(Jump, tick, dt); | 
|---|
| 85 |  | 
|---|
| 86 |         if (figure_ != nullptr) | 
|---|
| 87 |         { | 
|---|
| 88 |             Vector3 figurePosition = figure_->getPosition(); | 
|---|
| 89 |             Vector3 figureVelocity = figure_->getVelocity(); | 
|---|
| 90 |  | 
|---|
| 91 |             float boundary = totalScreenShift_+center_->getCameraOffset(); | 
|---|
| 92 |  | 
|---|
| 93 |             if (figurePosition.z > boundary) | 
|---|
| 94 |             { | 
|---|
| 95 |                 screenShiftSinceLastUpdate_ += figurePosition.z - boundary; | 
|---|
| 96 |                 totalScreenShift_ = figurePosition.z - center_->getCameraOffset(); | 
|---|
| 97 |  | 
|---|
| 98 |                 // Create new platforms if needed | 
|---|
| 99 |                 if (screenShiftSinceLastUpdate_ > center_->getSectionLength()) | 
|---|
| 100 |                 { | 
|---|
| 101 |                     if (sectionNumber_ > 2 && sectionNumber_%4 == 0 && rand()%2 == 0 && figure_->propellerActive_ == nullptr && figure_->rocketActive_ == nullptr && addAdventure(adventureNumber_) == true) | 
|---|
| 102 |                     { | 
|---|
| 103 |                         screenShiftSinceLastUpdate_ -= 2*center_->getSectionLength(); | 
|---|
| 104 |                         ++ adventureNumber_; | 
|---|
| 105 |                     } | 
|---|
| 106 |                     else | 
|---|
| 107 |                     { | 
|---|
| 108 |                         screenShiftSinceLastUpdate_ -= center_->getSectionLength(); | 
|---|
| 109 |                         addSection(); | 
|---|
| 110 |                     } | 
|---|
| 111 |                 } | 
|---|
| 112 |             } | 
|---|
| 113 |  | 
|---|
| 114 |             if (figurePosition.z < totalScreenShift_ - center_->getFieldDimension().y + platformHeight_ && figureVelocity.z < 0) | 
|---|
| 115 |             { | 
|---|
| 116 |                 figure_->dead_ = true; | 
|---|
| 117 |             } | 
|---|
| 118 |  | 
|---|
| 119 |             if (figure_->fireSignal_ == true) | 
|---|
| 120 |             { | 
|---|
| 121 |                 if (figure_->dead_ == true) | 
|---|
| 122 |                 { | 
|---|
| 123 |                     end(); | 
|---|
| 124 |                 } | 
|---|
| 125 |                 else | 
|---|
| 126 |                 { | 
|---|
| 127 |                     figure_->fireSignal_ = false; | 
|---|
| 128 |                     addProjectile(figurePosition.x, figurePosition.z + figure_->getPropellerPos()); | 
|---|
| 129 |                 } | 
|---|
| 130 |             } | 
|---|
| 131 |  | 
|---|
| 132 |  | 
|---|
| 133 |             if (camera != nullptr) | 
|---|
| 134 |             { | 
|---|
| 135 |                 Vector3 cameraPosition = Vector3(0, totalScreenShift_, 0); | 
|---|
| 136 |                 camera->setPosition(cameraPosition); | 
|---|
| 137 |             } | 
|---|
| 138 |             else | 
|---|
| 139 |             { | 
|---|
| 140 |                 orxout() << "No camera found." << endl; | 
|---|
| 141 |             } | 
|---|
| 142 |         } | 
|---|
| 143 |  | 
|---|
| 144 |         ObjectList<JumpPlatform> listPlatform; | 
|---|
| 145 |         ObjectList<JumpPlatform>::iterator itPlatform = listPlatform.begin(); | 
|---|
| 146 |         Vector3 platformPosition; | 
|---|
| 147 |  | 
|---|
| 148 |         while (itPlatform != listPlatform.end()) | 
|---|
| 149 |         { | 
|---|
| 150 |             platformPosition = itPlatform->getPosition(); | 
|---|
| 151 |             if (platformPosition.z < totalScreenShift_ - center_->getFieldDimension().y) | 
|---|
| 152 |             { | 
|---|
| 153 |                 ObjectList<JumpPlatform>::iterator temp = itPlatform; | 
|---|
| 154 |                 ++ itPlatform; | 
|---|
| 155 |                 center_->detach(*temp); | 
|---|
| 156 |                 temp->destroy(); | 
|---|
| 157 |             } | 
|---|
| 158 |             else | 
|---|
| 159 |             { | 
|---|
| 160 |                 ++ itPlatform; | 
|---|
| 161 |             } | 
|---|
| 162 |         } | 
|---|
| 163 |  | 
|---|
| 164 |         // Deleted deactivated platforms | 
|---|
| 165 |         ObjectList<JumpPlatformDisappear> listDisappear; | 
|---|
| 166 |         ObjectList<JumpPlatformDisappear>::iterator itDisappear = listDisappear.begin(); | 
|---|
| 167 |  | 
|---|
| 168 |         while (itDisappear != listDisappear.end()) | 
|---|
| 169 |         { | 
|---|
| 170 |             if (!itDisappear->isActive()) | 
|---|
| 171 |             { | 
|---|
| 172 |                 ObjectList<JumpPlatformDisappear>::iterator temp = itDisappear; | 
|---|
| 173 |                 ++ itDisappear; | 
|---|
| 174 |                 center_->detach(*temp); | 
|---|
| 175 |                 temp->destroy(); | 
|---|
| 176 |             } | 
|---|
| 177 |             else | 
|---|
| 178 |             { | 
|---|
| 179 |                 ++ itDisappear; | 
|---|
| 180 |             } | 
|---|
| 181 |         } | 
|---|
| 182 |  | 
|---|
| 183 |         ObjectList<JumpPlatformTimer> listTimer; | 
|---|
| 184 |         ObjectList<JumpPlatformTimer>::iterator itTimer = listTimer.begin(); | 
|---|
| 185 |  | 
|---|
| 186 |         while (itTimer != listTimer.end()) | 
|---|
| 187 |         { | 
|---|
| 188 |             if (!itTimer->isActive()) | 
|---|
| 189 |             { | 
|---|
| 190 |                 ObjectList<JumpPlatformTimer>::iterator temp = itTimer; | 
|---|
| 191 |                 ++ itTimer; | 
|---|
| 192 |                 center_->detach(*temp); | 
|---|
| 193 |                 temp->destroy(); | 
|---|
| 194 |             } | 
|---|
| 195 |             else | 
|---|
| 196 |             { | 
|---|
| 197 |                 ++ itTimer; | 
|---|
| 198 |             } | 
|---|
| 199 |         } | 
|---|
| 200 |  | 
|---|
| 201 |         ObjectList<JumpProjectile> listProjectile; | 
|---|
| 202 |         ObjectList<JumpProjectile>::iterator itProjectile = listProjectile.begin(); | 
|---|
| 203 |         Vector3 projectilePosition; | 
|---|
| 204 |  | 
|---|
| 205 |         while (itProjectile != listProjectile.end()) | 
|---|
| 206 |         { | 
|---|
| 207 |             projectilePosition = itProjectile->getPosition(); | 
|---|
| 208 |             if (projectilePosition.z > totalScreenShift_ + 5*center_->getFieldDimension().y) | 
|---|
| 209 |             { | 
|---|
| 210 |                 ObjectList<JumpProjectile>::iterator temp = itProjectile; | 
|---|
| 211 |                 ++ itProjectile; | 
|---|
| 212 |                 center_->detach(*temp); | 
|---|
| 213 |                 temp->destroy(); | 
|---|
| 214 |             } | 
|---|
| 215 |             else | 
|---|
| 216 |             { | 
|---|
| 217 |                 ++ itProjectile; | 
|---|
| 218 |             } | 
|---|
| 219 |         } | 
|---|
| 220 |  | 
|---|
| 221 |         ObjectList<JumpEnemy> listEnemy; | 
|---|
| 222 |         ObjectList<JumpEnemy>::iterator itEnemy = listEnemy.begin(); | 
|---|
| 223 |         Vector3 enemyPosition; | 
|---|
| 224 |  | 
|---|
| 225 |         while (itEnemy != listEnemy.end()) | 
|---|
| 226 |         { | 
|---|
| 227 |             enemyPosition = itEnemy->getPosition(); | 
|---|
| 228 |             if (enemyPosition.z < totalScreenShift_ - center_->getFieldDimension().y || itEnemy->dead_ == true) | 
|---|
| 229 |             { | 
|---|
| 230 |                 ObjectList<JumpEnemy>::iterator temp = itEnemy; | 
|---|
| 231 |                 ++ itEnemy; | 
|---|
| 232 |                 center_->detach(*temp); | 
|---|
| 233 |                 temp->destroy(); | 
|---|
| 234 |             } | 
|---|
| 235 |             else | 
|---|
| 236 |             { | 
|---|
| 237 |                 ++ itEnemy; | 
|---|
| 238 |             } | 
|---|
| 239 |         } | 
|---|
| 240 |  | 
|---|
| 241 |         ObjectList<JumpItem> listItem; | 
|---|
| 242 |         ObjectList<JumpItem>::iterator itItem = listItem.begin(); | 
|---|
| 243 |         Vector3 itemPosition; | 
|---|
| 244 |  | 
|---|
| 245 |         while (itItem != listItem.end()) | 
|---|
| 246 |         { | 
|---|
| 247 |             itemPosition = itItem->getPosition(); | 
|---|
| 248 |  | 
|---|
| 249 |             WorldEntity* parent = itItem->getParent(); | 
|---|
| 250 |  | 
|---|
| 251 |             if (itItem->attachedToFigure_ == false && itemPosition.z < totalScreenShift_ - center_->getFieldDimension().y && parent == center_) | 
|---|
| 252 |             { | 
|---|
| 253 |                 ObjectList<JumpItem>::iterator temp = itItem; | 
|---|
| 254 |                 ++ itItem; | 
|---|
| 255 |                 center_->detach(*temp); | 
|---|
| 256 |                 temp->destroy(); | 
|---|
| 257 |             } | 
|---|
| 258 |             else | 
|---|
| 259 |             { | 
|---|
| 260 |                 ++ itItem; | 
|---|
| 261 |             } | 
|---|
| 262 |         } | 
|---|
| 263 |     } | 
|---|
| 264 |  | 
|---|
| 265 |     void Jump::cleanup() | 
|---|
| 266 |     { | 
|---|
| 267 |         camera = nullptr; | 
|---|
| 268 |     } | 
|---|
| 269 |  | 
|---|
| 270 |     void Jump::start() | 
|---|
| 271 |     { | 
|---|
| 272 |         if (center_ != nullptr) // There needs to be a JumpCenterpoint, i.e. the area the game takes place. | 
|---|
| 273 |         { | 
|---|
| 274 |             if (figure_ == nullptr) | 
|---|
| 275 |             { | 
|---|
| 276 |                 figure_ = new JumpFigure(center_->getContext()); | 
|---|
| 277 |                 figure_->addTemplate(center_->getFigureTemplate()); | 
|---|
| 278 |                 figure_->InitializeAnimation(center_->getContext()); | 
|---|
| 279 |             } | 
|---|
| 280 |  | 
|---|
| 281 |             center_->attach(figure_); | 
|---|
| 282 |             figure_->setPosition(0, 0, 0); | 
|---|
| 283 |             figure_->setFieldDimension(center_->getFieldDimension()); | 
|---|
| 284 |         } | 
|---|
| 285 |         else // If no centerpoint was specified, an error is thrown and the level is exited. | 
|---|
| 286 |         { | 
|---|
| 287 |             orxout(internal_error) << "Jump: No Centerpoint specified." << endl; | 
|---|
| 288 |             GSLevel::startMainMenu(); | 
|---|
| 289 |             return; | 
|---|
| 290 |         } | 
|---|
| 291 |  | 
|---|
| 292 |         // Call start for the parent class. | 
|---|
| 293 |         Deathmatch::start(); | 
|---|
| 294 |  | 
|---|
| 295 |         if (figure_ != nullptr) | 
|---|
| 296 |         { | 
|---|
| 297 |             camera = figure_->getCamera(); | 
|---|
| 298 |         } | 
|---|
| 299 |  | 
|---|
| 300 |         totalScreenShift_ = 0.0; | 
|---|
| 301 |         screenShiftSinceLastUpdate_ = 0.0; | 
|---|
| 302 |         sectionNumber_ = 0; | 
|---|
| 303 |         adventureNumber_ = 0; | 
|---|
| 304 |  | 
|---|
| 305 |         addStartSection(); | 
|---|
| 306 |         addSection(); | 
|---|
| 307 |         addSection(); | 
|---|
| 308 |     } | 
|---|
| 309 |  | 
|---|
| 310 |     void Jump::end() | 
|---|
| 311 |     { | 
|---|
| 312 |         cleanup(); | 
|---|
| 313 |         GSLevel::startMainMenu(); | 
|---|
| 314 |         if (Highscore::exists()){ | 
|---|
| 315 |                     int score = this->getScore(this->getPlayer()); | 
|---|
| 316 |                     if(score > Highscore::getInstance().getHighestScoreOfGame("Jump"))  | 
|---|
| 317 |                         Highscore::getInstance().storeHighscore("Jump",score); | 
|---|
| 318 |  | 
|---|
| 319 |           } | 
|---|
| 320 |         Deathmatch::end(); | 
|---|
| 321 |     } | 
|---|
| 322 |  | 
|---|
| 323 |     void Jump::spawnPlayer(PlayerInfo* player) | 
|---|
| 324 |     { | 
|---|
| 325 |         assert(player); | 
|---|
| 326 |  | 
|---|
| 327 |         if (figure_->getPlayer() == nullptr) | 
|---|
| 328 |         { | 
|---|
| 329 |             player->startControl(figure_); | 
|---|
| 330 |             players_[player].state_ = PlayerState::Alive; | 
|---|
| 331 |         } | 
|---|
| 332 |     } | 
|---|
| 333 |  | 
|---|
| 334 |     PlayerInfo* Jump::getPlayer() const | 
|---|
| 335 |     { | 
|---|
| 336 |         if (this->figure_ != nullptr) | 
|---|
| 337 |         { | 
|---|
| 338 |             return this->figure_->getPlayer(); | 
|---|
| 339 |         } | 
|---|
| 340 |         else | 
|---|
| 341 |         { | 
|---|
| 342 |             return nullptr; | 
|---|
| 343 |         } | 
|---|
| 344 |     } | 
|---|
| 345 |  | 
|---|
| 346 |     void Jump::addPlatform(JumpPlatform* newPlatform, std::string platformTemplate, float xPosition, float zPosition) | 
|---|
| 347 |     { | 
|---|
| 348 |         if (newPlatform != nullptr && center_ != nullptr) | 
|---|
| 349 |         { | 
|---|
| 350 |             newPlatform->addTemplate(platformTemplate); | 
|---|
| 351 |             newPlatform->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 352 |             newPlatform->setFigure(this->figure_); | 
|---|
| 353 |             center_->attach(newPlatform); | 
|---|
| 354 |         } | 
|---|
| 355 |     } | 
|---|
| 356 |  | 
|---|
| 357 |     JumpPlatformStatic* Jump::addPlatformStatic(float xPosition, float zPosition) | 
|---|
| 358 |     { | 
|---|
| 359 |         JumpPlatformStatic* newPlatform = new JumpPlatformStatic(center_->getContext()); | 
|---|
| 360 |         addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, zPosition); | 
|---|
| 361 |  | 
|---|
| 362 |         return newPlatform; | 
|---|
| 363 |     } | 
|---|
| 364 |  | 
|---|
| 365 |     JumpPlatformHMove* Jump::addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed) | 
|---|
| 366 |     { | 
|---|
| 367 |         JumpPlatformHMove* newPlatform = new JumpPlatformHMove(center_->getContext()); | 
|---|
| 368 |         newPlatform->setProperties(leftBoundary, rightBoundary, speed); | 
|---|
| 369 |         addPlatform(newPlatform, center_->getPlatformHMoveTemplate(), xPosition, zPosition); | 
|---|
| 370 |  | 
|---|
| 371 |         return newPlatform; | 
|---|
| 372 |     } | 
|---|
| 373 |  | 
|---|
| 374 |     JumpPlatformVMove* Jump::addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed) | 
|---|
| 375 |     { | 
|---|
| 376 |         JumpPlatformVMove* newPlatform = new JumpPlatformVMove(center_->getContext()); | 
|---|
| 377 |         newPlatform->setProperties(lowerBoundary, upperBoundary, speed); | 
|---|
| 378 |         addPlatform(newPlatform, center_->getPlatformVMoveTemplate(), xPosition, zPosition); | 
|---|
| 379 |  | 
|---|
| 380 |         return newPlatform; | 
|---|
| 381 |     } | 
|---|
| 382 |  | 
|---|
| 383 |     JumpPlatformDisappear* Jump::addPlatformDisappear(float xPosition, float zPosition) | 
|---|
| 384 |     { | 
|---|
| 385 |         JumpPlatformDisappear* newPlatform = new JumpPlatformDisappear(center_->getContext()); | 
|---|
| 386 |         newPlatform->setProperties(true); | 
|---|
| 387 |         addPlatform(newPlatform, center_->getPlatformDisappearTemplate(), xPosition, zPosition); | 
|---|
| 388 |  | 
|---|
| 389 |         return newPlatform; | 
|---|
| 390 |     } | 
|---|
| 391 |  | 
|---|
| 392 |     JumpPlatformTimer* Jump::addPlatformTimer(float xPosition, float zPosition, float time, float variance) | 
|---|
| 393 |     { | 
|---|
| 394 |         float additionalTime = (float)(rand()%100)/100.0f*variance - variance/2.0f; | 
|---|
| 395 |  | 
|---|
| 396 |         JumpPlatformTimer* newPlatform = new JumpPlatformTimer(center_->getContext()); | 
|---|
| 397 |         newPlatform->setProperties(time + additionalTime); | 
|---|
| 398 |         addPlatform(newPlatform, center_->getPlatformTimerTemplate(), xPosition, zPosition); | 
|---|
| 399 |  | 
|---|
| 400 |         return newPlatform; | 
|---|
| 401 |     } | 
|---|
| 402 |  | 
|---|
| 403 |     JumpPlatformFake* Jump::addPlatformFake(float xPosition, float zPosition) | 
|---|
| 404 |     { | 
|---|
| 405 |         JumpPlatformFake* newPlatform = new JumpPlatformFake(center_->getContext()); | 
|---|
| 406 |         addPlatform(newPlatform, center_->getPlatformFakeTemplate(), xPosition, zPosition); | 
|---|
| 407 |         newPlatform->setAngularVelocity(Vector3(0, 0, 2.0)); | 
|---|
| 408 |  | 
|---|
| 409 |         return newPlatform; | 
|---|
| 410 |     } | 
|---|
| 411 |  | 
|---|
| 412 |  | 
|---|
| 413 |     void Jump::addProjectile(float xPosition, float zPosition) | 
|---|
| 414 |     { | 
|---|
| 415 |         JumpProjectile* newProjectile = new JumpProjectile(center_->getContext()); | 
|---|
| 416 |         if (newProjectile != nullptr && center_ != nullptr) | 
|---|
| 417 |         { | 
|---|
| 418 |             newProjectile->addTemplate(center_->getProjectileTemplate()); | 
|---|
| 419 |             newProjectile->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 420 |             newProjectile->setFieldDimension(center_->getFieldDimension()); | 
|---|
| 421 |             newProjectile->setFigure(this->figure_); | 
|---|
| 422 |             center_->attach(newProjectile); | 
|---|
| 423 |         } | 
|---|
| 424 |     } | 
|---|
| 425 |  | 
|---|
| 426 |     void Jump::addSpring(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) | 
|---|
| 427 |     { | 
|---|
| 428 |         JumpSpring* newSpring = new JumpSpring(center_->getContext()); | 
|---|
| 429 |         if (newSpring != nullptr && center_ != nullptr) | 
|---|
| 430 |         { | 
|---|
| 431 |             newSpring->addTemplate(center_->getSpringTemplate()); | 
|---|
| 432 |             newSpring->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 433 |             newSpring->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); | 
|---|
| 434 |             newSpring->setFigure(figure_); | 
|---|
| 435 |             center_->attach(newSpring); | 
|---|
| 436 |         } | 
|---|
| 437 |     } | 
|---|
| 438 |  | 
|---|
| 439 |     void Jump::addSpring(JumpPlatform* platform) | 
|---|
| 440 |     { | 
|---|
| 441 |         JumpSpring* newSpring = new JumpSpring(center_->getContext()); | 
|---|
| 442 |         if (newSpring != nullptr && center_ != nullptr) | 
|---|
| 443 |         { | 
|---|
| 444 |             newSpring->addTemplate(center_->getSpringTemplate()); | 
|---|
| 445 |             newSpring->setPosition(Vector3(0.0, 0.0, 0.0)); | 
|---|
| 446 |             newSpring->setProperties(-10.0, 10.0, -10.0, 10.0, 0.0, 0.0); | 
|---|
| 447 |             newSpring->setFigure(figure_); | 
|---|
| 448 |             platform->attach(newSpring); | 
|---|
| 449 |         } | 
|---|
| 450 |     } | 
|---|
| 451 |  | 
|---|
| 452 |     void Jump::addRocket(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) | 
|---|
| 453 |     { | 
|---|
| 454 |         JumpRocket* newRocket = new JumpRocket(center_->getContext()); | 
|---|
| 455 |         if (newRocket != nullptr && center_ != nullptr) | 
|---|
| 456 |         { | 
|---|
| 457 |             newRocket->addTemplate(center_->getRocketTemplate()); | 
|---|
| 458 |             newRocket->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 459 |             newRocket->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); | 
|---|
| 460 |             newRocket->setFigure(figure_); | 
|---|
| 461 |             center_->attach(newRocket); | 
|---|
| 462 |         } | 
|---|
| 463 |     } | 
|---|
| 464 |  | 
|---|
| 465 |     void Jump::addRocket(JumpPlatform* platform) | 
|---|
| 466 |     { | 
|---|
| 467 |         JumpRocket* newRocket = new JumpRocket(center_->getContext()); | 
|---|
| 468 |         if (newRocket != nullptr && center_ != nullptr) | 
|---|
| 469 |         { | 
|---|
| 470 |             newRocket->addTemplate(center_->getRocketTemplate()); | 
|---|
| 471 |             newRocket->setPosition(Vector3(0.0, 0.0, 0.0)); | 
|---|
| 472 |             newRocket->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | 
|---|
| 473 |             newRocket->setFigure(figure_); | 
|---|
| 474 |             platform->attach(newRocket); | 
|---|
| 475 |         } | 
|---|
| 476 |     } | 
|---|
| 477 |  | 
|---|
| 478 |     void Jump::addPropeller(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) | 
|---|
| 479 |     { | 
|---|
| 480 |         JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); | 
|---|
| 481 |         if (newPropeller != nullptr && center_ != nullptr) | 
|---|
| 482 |         { | 
|---|
| 483 |             newPropeller->addTemplate(center_->getPropellerTemplate()); | 
|---|
| 484 |             newPropeller->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 485 |             newPropeller->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); | 
|---|
| 486 |             newPropeller->setFigure(figure_); | 
|---|
| 487 |             center_->attach(newPropeller); | 
|---|
| 488 |         } | 
|---|
| 489 |     } | 
|---|
| 490 |  | 
|---|
| 491 |     void Jump::addPropeller(JumpPlatform* platform) | 
|---|
| 492 |     { | 
|---|
| 493 |         JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); | 
|---|
| 494 |         if (newPropeller != nullptr && center_ != nullptr) | 
|---|
| 495 |         { | 
|---|
| 496 |             newPropeller->addTemplate(center_->getPropellerTemplate()); | 
|---|
| 497 |             newPropeller->setPosition(Vector3(0.0, 0.0, 0.0)); | 
|---|
| 498 |             newPropeller->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | 
|---|
| 499 |             newPropeller->setFigure(figure_); | 
|---|
| 500 |             platform->attach(newPropeller); | 
|---|
| 501 |         } | 
|---|
| 502 |     } | 
|---|
| 503 |  | 
|---|
| 504 |     void Jump::addBoots(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) | 
|---|
| 505 |     { | 
|---|
| 506 |         JumpBoots* newBoots = new JumpBoots(center_->getContext()); | 
|---|
| 507 |         if (newBoots != nullptr && center_ != nullptr) | 
|---|
| 508 |         { | 
|---|
| 509 |             newBoots->addTemplate(center_->getBootsTemplate()); | 
|---|
| 510 |             newBoots->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 511 |             newBoots->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); | 
|---|
| 512 |             newBoots->setFigure(figure_); | 
|---|
| 513 |             center_->attach(newBoots); | 
|---|
| 514 |         } | 
|---|
| 515 |     } | 
|---|
| 516 |  | 
|---|
| 517 |     void Jump::addBoots(JumpPlatform* platform) | 
|---|
| 518 |     { | 
|---|
| 519 |         JumpBoots* newBoots = new JumpBoots(center_->getContext()); | 
|---|
| 520 |         if (newBoots != nullptr && center_ != nullptr) | 
|---|
| 521 |         { | 
|---|
| 522 |             newBoots->addTemplate(center_->getBootsTemplate()); | 
|---|
| 523 |             newBoots->setPosition(Vector3(0.0, 0.0, 0.0)); | 
|---|
| 524 |             newBoots->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | 
|---|
| 525 |             newBoots->setFigure(figure_); | 
|---|
| 526 |             platform->attach(newBoots); | 
|---|
| 527 |         } | 
|---|
| 528 |     } | 
|---|
| 529 |  | 
|---|
| 530 |     void Jump::addShield(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) | 
|---|
| 531 |     { | 
|---|
| 532 |         JumpShield* newShield = new JumpShield(center_->getContext()); | 
|---|
| 533 |         if (newShield != nullptr && center_ != nullptr) | 
|---|
| 534 |         { | 
|---|
| 535 |             newShield->addTemplate(center_->getShieldTemplate()); | 
|---|
| 536 |             newShield->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 537 |             newShield->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); | 
|---|
| 538 |             newShield->setFigure(figure_); | 
|---|
| 539 |             center_->attach(newShield); | 
|---|
| 540 |         } | 
|---|
| 541 |     } | 
|---|
| 542 |  | 
|---|
| 543 |     void Jump::addShield(JumpPlatform* platform) | 
|---|
| 544 |     { | 
|---|
| 545 |         JumpShield* newShield = new JumpShield(center_->getContext()); | 
|---|
| 546 |         if (newShield != nullptr && center_ != nullptr) | 
|---|
| 547 |         { | 
|---|
| 548 |             newShield->addTemplate(center_->getShieldTemplate()); | 
|---|
| 549 |             newShield->setPosition(Vector3(0.0, 0.0, 0.0)); | 
|---|
| 550 |             newShield->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | 
|---|
| 551 |             newShield->setFigure(figure_); | 
|---|
| 552 |             platform->attach(newShield); | 
|---|
| 553 |         } | 
|---|
| 554 |     } | 
|---|
| 555 |  | 
|---|
| 556 |     void Jump::addEnemy(int type, float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) | 
|---|
| 557 |     { | 
|---|
| 558 |         JumpEnemy* newEnemy = new JumpEnemy(center_->getContext()); | 
|---|
| 559 |         if (newEnemy != nullptr && center_ != nullptr) | 
|---|
| 560 |         { | 
|---|
| 561 |             switch (type) | 
|---|
| 562 |             { | 
|---|
| 563 |             case 1: | 
|---|
| 564 |                 newEnemy->addTemplate(center_->getEnemy1Template()); | 
|---|
| 565 |                 break; | 
|---|
| 566 |             case 2: | 
|---|
| 567 |                 newEnemy->addTemplate(center_->getEnemy2Template()); | 
|---|
| 568 |                 break; | 
|---|
| 569 |             case 3: | 
|---|
| 570 |                 newEnemy->addTemplate(center_->getEnemy3Template()); | 
|---|
| 571 |                 break; | 
|---|
| 572 |             case 4: | 
|---|
| 573 |                 newEnemy->addTemplate(center_->getEnemy4Template()); | 
|---|
| 574 |                 break; | 
|---|
| 575 |             default: | 
|---|
| 576 |                 return; | 
|---|
| 577 |             } | 
|---|
| 578 |  | 
|---|
| 579 |             newEnemy->setPosition(Vector3(xPosition, 0.0, zPosition)); | 
|---|
| 580 |             newEnemy->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); | 
|---|
| 581 |             newEnemy->setFieldDimension(center_->getFieldDimension()); | 
|---|
| 582 |             newEnemy->setFigure(this->figure_); | 
|---|
| 583 |             center_->attach(newEnemy); | 
|---|
| 584 |         } | 
|---|
| 585 |     } | 
|---|
| 586 |  | 
|---|
| 587 |     void Jump::addStartSection() | 
|---|
| 588 |     { | 
|---|
| 589 |         JumpPlatform* newPlatform; | 
|---|
| 590 |  | 
|---|
| 591 |         float sectionLength = center_->getSectionLength(); | 
|---|
| 592 |  | 
|---|
| 593 |         newPlatform = new JumpPlatformStatic(center_->getContext()); | 
|---|
| 594 |         addPlatform(newPlatform, center_->getPlatformStaticTemplate(), 0.0, -0.05f*sectionLength); | 
|---|
| 595 |  | 
|---|
| 596 |         platformWidth_ = newPlatform->getWidth(); | 
|---|
| 597 |         platformHeight_ = newPlatform->getHeight(); | 
|---|
| 598 |  | 
|---|
| 599 |         for (float xPosition = platformWidth_; xPosition <= center_->getFieldDimension().x; xPosition += platformWidth_) | 
|---|
| 600 |         { | 
|---|
| 601 |             newPlatform = new JumpPlatformStatic(center_->getContext()); | 
|---|
| 602 |             addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, -0.05f*sectionLength); | 
|---|
| 603 |             newPlatform = new JumpPlatformStatic(center_->getContext()); | 
|---|
| 604 |             addPlatform(newPlatform, center_->getPlatformStaticTemplate(), -xPosition, -0.05f*sectionLength); | 
|---|
| 605 |         } | 
|---|
| 606 |     } | 
|---|
| 607 |  | 
|---|
| 608 |     void Jump::addSection() | 
|---|
| 609 |     { | 
|---|
| 610 |         float fieldWidth = center_->getFieldDimension().x; | 
|---|
| 611 |         float sectionLength = center_->getSectionLength(); | 
|---|
| 612 |         float sectionBegin = sectionNumber_ * sectionLength; | 
|---|
| 613 |         float sectionEnd = (1 + sectionNumber_) * sectionLength; | 
|---|
| 614 |  | 
|---|
| 615 |         const int numI = 6; | 
|---|
| 616 |         const int numJ = 4; | 
|---|
| 617 |  | 
|---|
| 618 |         enum class PlatformType | 
|---|
| 619 |         { | 
|---|
| 620 |             EMPTY, STATIC, HMOVE, VMOVE, DISAPPEAR, TIMER, FAKE | 
|---|
| 621 |         }; | 
|---|
| 622 |  | 
|---|
| 623 |         enum class ItemType | 
|---|
| 624 |         { | 
|---|
| 625 |             NOTHING, SPRING, PROPELLER, ROCKET, BOOTS, SHIELD | 
|---|
| 626 |         }; | 
|---|
| 627 |  | 
|---|
| 628 |         struct PlatformMatrix | 
|---|
| 629 |         { | 
|---|
| 630 |             PlatformType type; | 
|---|
| 631 |             bool done; | 
|---|
| 632 |         } matrix[numI][numJ]; | 
|---|
| 633 |  | 
|---|
| 634 |  | 
|---|
| 635 |         for (int i = 0; i < numI; ++i) | 
|---|
| 636 |         { | 
|---|
| 637 |             for (int j = 0; j < numJ; ++j) | 
|---|
| 638 |             { | 
|---|
| 639 |                 matrix[i][j].type = PlatformType::EMPTY; | 
|---|
| 640 |                 matrix[i][j].done = false; | 
|---|
| 641 |             } | 
|---|
| 642 |         } | 
|---|
| 643 |         PlatformType platformtype1; | 
|---|
| 644 |         PlatformType platformtype2; | 
|---|
| 645 |         ItemType itemType = ItemType::NOTHING; | 
|---|
| 646 |  | 
|---|
| 647 |         if (rand()%2 == 0) | 
|---|
| 648 |         { | 
|---|
| 649 |             itemType = ItemType::SPRING; | 
|---|
| 650 |         } | 
|---|
| 651 |         else if (rand()%2 == 0 && sectionNumber_ > 3) | 
|---|
| 652 |         { | 
|---|
| 653 |             switch(rand()%4) | 
|---|
| 654 |             { | 
|---|
| 655 |             case 0: | 
|---|
| 656 |                 itemType = ItemType::PROPELLER; | 
|---|
| 657 |                 break; | 
|---|
| 658 |             case 1: | 
|---|
| 659 |                 itemType = ItemType::ROCKET; | 
|---|
| 660 |                 break; | 
|---|
| 661 |             case 2: | 
|---|
| 662 |                 itemType = ItemType::BOOTS; | 
|---|
| 663 |                 break; | 
|---|
| 664 |             case 3: | 
|---|
| 665 |                 itemType = ItemType::SHIELD; | 
|---|
| 666 |                 break; | 
|---|
| 667 |             default: | 
|---|
| 668 |                 break; | 
|---|
| 669 |             } | 
|---|
| 670 |         } | 
|---|
| 671 |  | 
|---|
| 672 |         switch((sectionNumber_ > 28) ? rand()%29 : rand()%(sectionNumber_+1)) | 
|---|
| 673 |         { | 
|---|
| 674 |         case 0: | 
|---|
| 675 |             platformtype1 = PlatformType::STATIC; | 
|---|
| 676 |             platformtype2 = PlatformType::STATIC; | 
|---|
| 677 |             break; | 
|---|
| 678 |         case 1: | 
|---|
| 679 |             platformtype1 = PlatformType::STATIC; | 
|---|
| 680 |             platformtype2 = PlatformType::STATIC; | 
|---|
| 681 |             break; | 
|---|
| 682 |         case 2: | 
|---|
| 683 |             platformtype1 = PlatformType::STATIC; | 
|---|
| 684 |             platformtype2 = PlatformType::HMOVE; | 
|---|
| 685 |             break; | 
|---|
| 686 |         case 3: | 
|---|
| 687 |             platformtype1 = PlatformType::STATIC; | 
|---|
| 688 |             platformtype2 = PlatformType::DISAPPEAR; | 
|---|
| 689 |             break; | 
|---|
| 690 |         case 4: | 
|---|
| 691 |             platformtype1 = PlatformType::STATIC; | 
|---|
| 692 |             platformtype2 = PlatformType::VMOVE; | 
|---|
| 693 |             break; | 
|---|
| 694 |         case 5: | 
|---|
| 695 |             platformtype1 = PlatformType::STATIC; | 
|---|
| 696 |             platformtype2 = PlatformType::TIMER; | 
|---|
| 697 |             break; | 
|---|
| 698 |         case 6: | 
|---|
| 699 |             platformtype1 = PlatformType::HMOVE; | 
|---|
| 700 |             platformtype2 = PlatformType::STATIC; | 
|---|
| 701 |             break; | 
|---|
| 702 |         case 7: | 
|---|
| 703 |             platformtype1 = PlatformType::HMOVE; | 
|---|
| 704 |             platformtype2 = PlatformType::HMOVE; | 
|---|
| 705 |             break; | 
|---|
| 706 |         case 8: | 
|---|
| 707 |             platformtype1 = PlatformType::HMOVE; | 
|---|
| 708 |             platformtype2 = PlatformType::HMOVE; | 
|---|
| 709 |             break; | 
|---|
| 710 |         case 9: | 
|---|
| 711 |             platformtype1 = PlatformType::HMOVE; | 
|---|
| 712 |             platformtype2 = PlatformType::DISAPPEAR; | 
|---|
| 713 |             break; | 
|---|
| 714 |         case 10: | 
|---|
| 715 |             platformtype1 = PlatformType::HMOVE; | 
|---|
| 716 |             platformtype2 = PlatformType::VMOVE; | 
|---|
| 717 |             break; | 
|---|
| 718 |         case 11: | 
|---|
| 719 |             platformtype1 = PlatformType::HMOVE; | 
|---|
| 720 |             platformtype2 = PlatformType::TIMER; | 
|---|
| 721 |             break; | 
|---|
| 722 |         case 12: | 
|---|
| 723 |             platformtype1 = PlatformType::DISAPPEAR; | 
|---|
| 724 |             platformtype2 = PlatformType::STATIC; | 
|---|
| 725 |             break; | 
|---|
| 726 |         case 13: | 
|---|
| 727 |             platformtype1 = PlatformType::DISAPPEAR; | 
|---|
| 728 |             platformtype2 = PlatformType::HMOVE; | 
|---|
| 729 |             break; | 
|---|
| 730 |         case 14: | 
|---|
| 731 |             platformtype1 = PlatformType::DISAPPEAR; | 
|---|
| 732 |             platformtype2 = PlatformType::DISAPPEAR; | 
|---|
| 733 |             break; | 
|---|
| 734 |         case 15: | 
|---|
| 735 |             platformtype1 = PlatformType::DISAPPEAR; | 
|---|
| 736 |             platformtype2 = PlatformType::DISAPPEAR; | 
|---|
| 737 |             break; | 
|---|
| 738 |         case 16: | 
|---|
| 739 |             platformtype1 = PlatformType::DISAPPEAR; | 
|---|
| 740 |             platformtype2 = PlatformType::VMOVE; | 
|---|
| 741 |             break; | 
|---|
| 742 |         case 17: | 
|---|
| 743 |             platformtype1 = PlatformType::DISAPPEAR; | 
|---|
| 744 |             platformtype2 = PlatformType::TIMER; | 
|---|
| 745 |             break; | 
|---|
| 746 |         case 18: | 
|---|
| 747 |             platformtype1 = PlatformType::VMOVE; | 
|---|
| 748 |             platformtype2 = PlatformType::STATIC; | 
|---|
| 749 |             break; | 
|---|
| 750 |         case 19: | 
|---|
| 751 |             platformtype1 = PlatformType::VMOVE; | 
|---|
| 752 |             platformtype2 = PlatformType::HMOVE; | 
|---|
| 753 |             break; | 
|---|
| 754 |         case 20: | 
|---|
| 755 |             platformtype1 = PlatformType::VMOVE; | 
|---|
| 756 |             platformtype2 = PlatformType::DISAPPEAR; | 
|---|
| 757 |             break; | 
|---|
| 758 |         case 21: | 
|---|
| 759 |             platformtype1 = PlatformType::VMOVE; | 
|---|
| 760 |             platformtype2 = PlatformType::VMOVE; | 
|---|
| 761 |             break; | 
|---|
| 762 |         case 22: | 
|---|
| 763 |             platformtype1 = PlatformType::VMOVE; | 
|---|
| 764 |             platformtype2 = PlatformType::VMOVE; | 
|---|
| 765 |             break; | 
|---|
| 766 |         case 23: | 
|---|
| 767 |             platformtype1 = PlatformType::VMOVE; | 
|---|
| 768 |             platformtype2 = PlatformType::TIMER; | 
|---|
| 769 |             break; | 
|---|
| 770 |         case 24: | 
|---|
| 771 |             platformtype1 = PlatformType::TIMER; | 
|---|
| 772 |             platformtype2 = PlatformType::STATIC; | 
|---|
| 773 |             break; | 
|---|
| 774 |         case 25: | 
|---|
| 775 |             platformtype1 = PlatformType::TIMER; | 
|---|
| 776 |             platformtype2 = PlatformType::HMOVE; | 
|---|
| 777 |             break; | 
|---|
| 778 |         case 26: | 
|---|
| 779 |             platformtype1 = PlatformType::TIMER; | 
|---|
| 780 |             platformtype2 = PlatformType::DISAPPEAR; | 
|---|
| 781 |             break; | 
|---|
| 782 |         case 27: | 
|---|
| 783 |             platformtype1 = PlatformType::TIMER; | 
|---|
| 784 |             platformtype2 = PlatformType::VMOVE; | 
|---|
| 785 |             break; | 
|---|
| 786 |         case 28: | 
|---|
| 787 |             platformtype1 = PlatformType::TIMER; | 
|---|
| 788 |             platformtype2 = PlatformType::TIMER; | 
|---|
| 789 |             break; | 
|---|
| 790 |         default: | 
|---|
| 791 |             platformtype1 = PlatformType::TIMER; | 
|---|
| 792 |             platformtype2 = PlatformType::TIMER; | 
|---|
| 793 |             break; | 
|---|
| 794 |         } | 
|---|
| 795 |  | 
|---|
| 796 |         // Fill matrix with selected platform types | 
|---|
| 797 |         for (int i = 0; i < numI; ++ i) | 
|---|
| 798 |         { | 
|---|
| 799 |             for (int j = 0; j < numJ; ++ j) | 
|---|
| 800 |             { | 
|---|
| 801 |                 if (rand()%3 == 0) | 
|---|
| 802 |                 { | 
|---|
| 803 |                     matrix[i][j].type = platformtype1; | 
|---|
| 804 |                 } | 
|---|
| 805 |                 else | 
|---|
| 806 |                 { | 
|---|
| 807 |                     matrix[i][j].type = platformtype2; | 
|---|
| 808 |                 } | 
|---|
| 809 |                 matrix[i][j].done = false; | 
|---|
| 810 |             } | 
|---|
| 811 |         } | 
|---|
| 812 |  | 
|---|
| 813 |         if (platformtype1 == platformtype2 && sectionNumber_ > 10 && rand()%2 == 0) | 
|---|
| 814 |         { | 
|---|
| 815 |             matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 816 |             matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 817 |         } | 
|---|
| 818 |  | 
|---|
| 819 |         // Delete some planned platforms or replace them with fake platforms | 
|---|
| 820 |         if (sectionNumber_ > 5) | 
|---|
| 821 |         { | 
|---|
| 822 |             if (rand()%2 == 0) | 
|---|
| 823 |             { | 
|---|
| 824 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 825 |             } | 
|---|
| 826 |             else | 
|---|
| 827 |             { | 
|---|
| 828 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; | 
|---|
| 829 |             } | 
|---|
| 830 |         } | 
|---|
| 831 |         else if (sectionNumber_ > 10) | 
|---|
| 832 |         { | 
|---|
| 833 |             if (rand()%2 == 0) | 
|---|
| 834 |             { | 
|---|
| 835 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 836 |             } | 
|---|
| 837 |             else | 
|---|
| 838 |             { | 
|---|
| 839 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; | 
|---|
| 840 |             } | 
|---|
| 841 |             if (rand()%2 == 0) | 
|---|
| 842 |             { | 
|---|
| 843 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 844 |             } | 
|---|
| 845 |             else | 
|---|
| 846 |             { | 
|---|
| 847 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; | 
|---|
| 848 |             } | 
|---|
| 849 |         } | 
|---|
| 850 |         else if (sectionNumber_ > 15) | 
|---|
| 851 |         { | 
|---|
| 852 |             if (rand()%2 == 0) | 
|---|
| 853 |             { | 
|---|
| 854 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 855 |             } | 
|---|
| 856 |             else | 
|---|
| 857 |             { | 
|---|
| 858 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; | 
|---|
| 859 |             } | 
|---|
| 860 |             if (rand()%2 == 0) | 
|---|
| 861 |             { | 
|---|
| 862 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 863 |             } | 
|---|
| 864 |             else | 
|---|
| 865 |             { | 
|---|
| 866 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; | 
|---|
| 867 |             } | 
|---|
| 868 |             if (rand()%2 == 0) | 
|---|
| 869 |             { | 
|---|
| 870 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; | 
|---|
| 871 |             } | 
|---|
| 872 |             else | 
|---|
| 873 |             { | 
|---|
| 874 |                 matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; | 
|---|
| 875 |             } | 
|---|
| 876 |         } | 
|---|
| 877 |  | 
|---|
| 878 |         std::vector<JumpPlatform*> platformList; | 
|---|
| 879 |  | 
|---|
| 880 |         for (int i = 0; i < numI; ++ i) | 
|---|
| 881 |         { | 
|---|
| 882 |             for (int j = 0; j < numJ; ++ j) | 
|---|
| 883 |             { | 
|---|
| 884 |                 if (matrix[i][j].done == false) | 
|---|
| 885 |                 { | 
|---|
| 886 |                     float xPosition = 0.0; | 
|---|
| 887 |                     float zPosition = 0.0; | 
|---|
| 888 |                     float leftBoundary = 0.0; | 
|---|
| 889 |                     float rightBoundary = 0.0; | 
|---|
| 890 |                     float lowerBoundary = 0.0; | 
|---|
| 891 |                     float upperBoundary = 0.0; | 
|---|
| 892 |                     float xVelocity = 0.0; | 
|---|
| 893 |                     float zVelocity = 0.0; | 
|---|
| 894 |  | 
|---|
| 895 |                     switch(matrix[i][j].type) | 
|---|
| 896 |                     { | 
|---|
| 897 |                     case PlatformType::EMPTY: | 
|---|
| 898 |                         matrix[i][j].done = true; | 
|---|
| 899 |                         break; | 
|---|
| 900 |                     case PlatformType::STATIC: | 
|---|
| 901 |                         xPosition = randomXPosition(numJ, j); | 
|---|
| 902 |                         zPosition = sectionBegin + i*sectionLength/numI; | 
|---|
| 903 |                         platformList.push_back(addPlatformStatic(xPosition, zPosition)); | 
|---|
| 904 |                         matrix[i][j].done = true; | 
|---|
| 905 |                         break; | 
|---|
| 906 |                     case PlatformType::FAKE: | 
|---|
| 907 |                         xPosition = randomXPosition(numJ, j); | 
|---|
| 908 |                         zPosition = sectionBegin + i*sectionLength/numI; | 
|---|
| 909 |                         platformList.push_back(addPlatformFake(xPosition, zPosition)); | 
|---|
| 910 |                         matrix[i][j].done = true; | 
|---|
| 911 |                         break; | 
|---|
| 912 |                     case PlatformType::TIMER: | 
|---|
| 913 |                         xPosition = randomXPosition(numJ, j); | 
|---|
| 914 |                         zPosition = sectionBegin + i*sectionLength/numI; | 
|---|
| 915 |                         platformList.push_back(addPlatformTimer(xPosition, zPosition, 12.0, 1.5)); | 
|---|
| 916 |                         matrix[i][j].done = true; | 
|---|
| 917 |                         break; | 
|---|
| 918 |                     case PlatformType::DISAPPEAR: | 
|---|
| 919 |                         xPosition = randomXPosition(numJ, j); | 
|---|
| 920 |                         zPosition = sectionBegin + i*sectionLength/numI; | 
|---|
| 921 |                         platformList.push_back(addPlatformDisappear(xPosition, zPosition)); | 
|---|
| 922 |                         matrix[i][j].done = true; | 
|---|
| 923 |                         break; | 
|---|
| 924 |                     case PlatformType::HMOVE: | 
|---|
| 925 |                         xVelocity = randomSpeed(); | 
|---|
| 926 |                         if (j <= numJ-3 && matrix[i][j+1].type == PlatformType::HMOVE && matrix[i][j+2].type == PlatformType::HMOVE && rand()%2 == 0) | 
|---|
| 927 |                         { | 
|---|
| 928 |                             leftBoundary = randomXPositionLeft(numJ, j); | 
|---|
| 929 |                             rightBoundary = randomXPositionRight(numJ, j+2); | 
|---|
| 930 |                             xPosition = randomPosition(leftBoundary, rightBoundary); | 
|---|
| 931 |                             zPosition = sectionBegin + i*sectionLength/numI; | 
|---|
| 932 |                             platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); | 
|---|
| 933 |                             matrix[i][j].done = true; | 
|---|
| 934 |                             matrix[i][j+1].done = true; | 
|---|
| 935 |                             matrix[i][j+2].done = true; | 
|---|
| 936 |                         } | 
|---|
| 937 |                         else if (j <= numJ-2 && matrix[i][j+1].type == PlatformType::HMOVE && rand()%2 == 0) | 
|---|
| 938 |                         { | 
|---|
| 939 |                             leftBoundary = randomXPositionLeft(numJ, j); | 
|---|
| 940 |                             rightBoundary = randomXPositionRight(numJ, j+1); | 
|---|
| 941 |                             xPosition = randomPosition(leftBoundary, rightBoundary); | 
|---|
| 942 |                             zPosition = sectionBegin + i*sectionLength/numI; | 
|---|
| 943 |                             platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); | 
|---|
| 944 |                             matrix[i][j].done = true; | 
|---|
| 945 |                             matrix[i][j+1].done = true; | 
|---|
| 946 |                         } | 
|---|
| 947 |                         else | 
|---|
| 948 |                         { | 
|---|
| 949 |                             leftBoundary = randomXPositionLeft(numJ, j); | 
|---|
| 950 |                             rightBoundary = randomXPositionRight(numJ, j); | 
|---|
| 951 |                             xPosition = randomPosition(leftBoundary, rightBoundary); | 
|---|
| 952 |                             zPosition = sectionBegin + i*sectionLength/numI; | 
|---|
| 953 |                             platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); | 
|---|
| 954 |                             matrix[i][j].done = true; | 
|---|
| 955 |                         } | 
|---|
| 956 |                         break; | 
|---|
| 957 |                     case PlatformType::VMOVE: | 
|---|
| 958 |                         zVelocity = randomSpeed(); | 
|---|
| 959 |                         if (i <= numI-3 && matrix[i+1][j].type == PlatformType::VMOVE && matrix[i+2][j].type == PlatformType::VMOVE && rand()%2 == 0) | 
|---|
| 960 |                         { | 
|---|
| 961 |                             lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); | 
|---|
| 962 |                             upperBoundary = randomZPositionUpper(numI, i+2, sectionBegin, sectionEnd); | 
|---|
| 963 |                             zPosition = randomPosition(lowerBoundary, upperBoundary); | 
|---|
| 964 |                             xPosition = randomXPosition(numJ, j); | 
|---|
| 965 |                             platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); | 
|---|
| 966 |                             matrix[i][j].done = true; | 
|---|
| 967 |                             matrix[i+1][j].done = true; | 
|---|
| 968 |                             matrix[i+2][j].done = true; | 
|---|
| 969 |                         } | 
|---|
| 970 |                         else if (i <= numI-2 && matrix[i+1][j].type == PlatformType::VMOVE && rand()%2 == 0) | 
|---|
| 971 |                         { | 
|---|
| 972 |                             lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); | 
|---|
| 973 |                             upperBoundary = randomZPositionUpper(numI, i+1, sectionBegin, sectionEnd); | 
|---|
| 974 |                             zPosition = randomPosition(lowerBoundary, upperBoundary); | 
|---|
| 975 |                             xPosition = randomXPosition(numJ, j); | 
|---|
| 976 |                             platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); | 
|---|
| 977 |                             matrix[i][j].done = true; | 
|---|
| 978 |                             matrix[i+1][j].done = true; | 
|---|
| 979 |                         } | 
|---|
| 980 |                         else | 
|---|
| 981 |                         { | 
|---|
| 982 |                             lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); | 
|---|
| 983 |                             upperBoundary = randomZPositionUpper(numI, i, sectionBegin, sectionEnd); | 
|---|
| 984 |                             zPosition = randomPosition(lowerBoundary, upperBoundary); | 
|---|
| 985 |                             xPosition = randomXPosition(numJ, j); | 
|---|
| 986 |                             platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); | 
|---|
| 987 |                             matrix[i][j].done = true; | 
|---|
| 988 |                         } | 
|---|
| 989 |                         break; | 
|---|
| 990 |                     default: | 
|---|
| 991 |                         //ERROR | 
|---|
| 992 |                         break; | 
|---|
| 993 |  | 
|---|
| 994 |                     } | 
|---|
| 995 |                 } | 
|---|
| 996 |             } | 
|---|
| 997 |         } | 
|---|
| 998 |  | 
|---|
| 999 |         //Add items | 
|---|
| 1000 |         int numNewPlatforms = platformList.size(); | 
|---|
| 1001 |  | 
|---|
| 1002 |         if (rand()%4 == 0) | 
|---|
| 1003 |         { | 
|---|
| 1004 |             if (rand()%2 == 0) | 
|---|
| 1005 |             { | 
|---|
| 1006 |                 switch (itemType) | 
|---|
| 1007 |                 { | 
|---|
| 1008 |                 case ItemType::ROCKET: | 
|---|
| 1009 |                     addRocket(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); | 
|---|
| 1010 |                     break; | 
|---|
| 1011 |                 case ItemType::PROPELLER: | 
|---|
| 1012 |                     addPropeller(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); | 
|---|
| 1013 |                     break; | 
|---|
| 1014 |                 case ItemType::BOOTS: | 
|---|
| 1015 |                     addBoots(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); | 
|---|
| 1016 |                     break; | 
|---|
| 1017 |                 case ItemType::SHIELD: | 
|---|
| 1018 |                     addShield(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); | 
|---|
| 1019 |                     break; | 
|---|
| 1020 |                 default: | 
|---|
| 1021 |                     break; | 
|---|
| 1022 |                 } | 
|---|
| 1023 |             } | 
|---|
| 1024 |             else | 
|---|
| 1025 |             { | 
|---|
| 1026 |                 switch (itemType) | 
|---|
| 1027 |                 { | 
|---|
| 1028 |                 case ItemType::ROCKET: | 
|---|
| 1029 |                     addRocket(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); | 
|---|
| 1030 |                     break; | 
|---|
| 1031 |                 case ItemType::PROPELLER: | 
|---|
| 1032 |                     addPropeller(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); | 
|---|
| 1033 |                     break; | 
|---|
| 1034 |                 case ItemType::BOOTS: | 
|---|
| 1035 |                     addBoots(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); | 
|---|
| 1036 |                     break; | 
|---|
| 1037 |                 case ItemType::SHIELD: | 
|---|
| 1038 |                     addShield(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); | 
|---|
| 1039 |                     break; | 
|---|
| 1040 |                 default: | 
|---|
| 1041 |                     break; | 
|---|
| 1042 |                 } | 
|---|
| 1043 |             } | 
|---|
| 1044 |         } | 
|---|
| 1045 |         else | 
|---|
| 1046 |         { | 
|---|
| 1047 |             if (numNewPlatforms > 0) | 
|---|
| 1048 |             { | 
|---|
| 1049 |                 JumpPlatform* itemPlatform = platformList[rand()%numNewPlatforms]; | 
|---|
| 1050 |  | 
|---|
| 1051 |                 switch (itemType) | 
|---|
| 1052 |                 { | 
|---|
| 1053 |                 case ItemType::SPRING: | 
|---|
| 1054 |                     addSpring(itemPlatform); | 
|---|
| 1055 |                     break; | 
|---|
| 1056 |                 case ItemType::ROCKET: | 
|---|
| 1057 |                     addRocket(itemPlatform); | 
|---|
| 1058 |                     break; | 
|---|
| 1059 |                 case ItemType::PROPELLER: | 
|---|
| 1060 |                     addPropeller(itemPlatform); | 
|---|
| 1061 |                     break; | 
|---|
| 1062 |                 case ItemType::BOOTS: | 
|---|
| 1063 |                     addBoots(itemPlatform); | 
|---|
| 1064 |                     break; | 
|---|
| 1065 |                 case ItemType::SHIELD: | 
|---|
| 1066 |                     addShield(itemPlatform); | 
|---|
| 1067 |                     break; | 
|---|
| 1068 |                 default: | 
|---|
| 1069 |                     break; | 
|---|
| 1070 |                 } | 
|---|
| 1071 |             } | 
|---|
| 1072 |         } | 
|---|
| 1073 |  | 
|---|
| 1074 |         if (sectionNumber_ >= 5 && rand()%3 == 0) | 
|---|
| 1075 |         { | 
|---|
| 1076 |             switch(rand()%4) | 
|---|
| 1077 |             { | 
|---|
| 1078 |             case 0: | 
|---|
| 1079 |                 addEnemy(1, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); | 
|---|
| 1080 |                 break; | 
|---|
| 1081 |             case 1: | 
|---|
| 1082 |                 addEnemy(2, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); | 
|---|
| 1083 |                 break; | 
|---|
| 1084 |             case 2: | 
|---|
| 1085 |                 addEnemy(3, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); | 
|---|
| 1086 |                 break; | 
|---|
| 1087 |             case 3: | 
|---|
| 1088 |                 addEnemy(4, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); | 
|---|
| 1089 |                 break; | 
|---|
| 1090 |             } | 
|---|
| 1091 |         } | 
|---|
| 1092 |         ++ sectionNumber_; | 
|---|
| 1093 |     } | 
|---|
| 1094 |  | 
|---|
| 1095 |     bool Jump::addAdventure(int number) | 
|---|
| 1096 |     { | 
|---|
| 1097 |         float fieldWidth = center_->getFieldDimension().x; | 
|---|
| 1098 |         float sectionLength = center_->getSectionLength(); | 
|---|
| 1099 |         float sectionBegin = sectionNumber_ * sectionLength; | 
|---|
| 1100 |         sectionLength *= 2; | 
|---|
| 1101 |  | 
|---|
| 1102 |         switch(number) | 
|---|
| 1103 |         { | 
|---|
| 1104 |         case 0: | 
|---|
| 1105 |         { | 
|---|
| 1106 |             int numI = 10; | 
|---|
| 1107 |             if (rand()%2 == 0) | 
|---|
| 1108 |             { | 
|---|
| 1109 |                 for (int i = 0; i < numI; ++ i) | 
|---|
| 1110 |                 { | 
|---|
| 1111 |                     addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+i*sectionLength/numI); | 
|---|
| 1112 |                 } | 
|---|
| 1113 |             } | 
|---|
| 1114 |             else | 
|---|
| 1115 |             { | 
|---|
| 1116 |                 for (int i = 0; i < numI; ++ i) | 
|---|
| 1117 |                 { | 
|---|
| 1118 |                     addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+(numI-i)*sectionLength/numI); | 
|---|
| 1119 |                 } | 
|---|
| 1120 |             } | 
|---|
| 1121 |             break; | 
|---|
| 1122 |         } | 
|---|
| 1123 |         case 1: | 
|---|
| 1124 |         { | 
|---|
| 1125 |             int numI = 7; | 
|---|
| 1126 |  | 
|---|
| 1127 |             addPlatformStatic(0.0, sectionBegin); | 
|---|
| 1128 |             if (rand()%2 == 0) | 
|---|
| 1129 |             { | 
|---|
| 1130 |                 for (int i = 1; i < numI; ++ i) | 
|---|
| 1131 |                 { | 
|---|
| 1132 |                     addPlatformStatic((fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); | 
|---|
| 1133 |                     addPlatformStatic(-(fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); | 
|---|
| 1134 |                 } | 
|---|
| 1135 |             } | 
|---|
| 1136 |             else | 
|---|
| 1137 |             { | 
|---|
| 1138 |                 for (int i = 1; i < numI; ++ i) | 
|---|
| 1139 |                 { | 
|---|
| 1140 |                     addPlatformStatic((fieldWidth-platformWidth_/2)*i/numI, sectionBegin+(numI-i)*sectionLength/numI); | 
|---|
| 1141 |                     addPlatformStatic(-(fieldWidth-platformWidth_/2)*i/numI, sectionBegin+(numI-i)*sectionLength/numI); | 
|---|
| 1142 |                 } | 
|---|
| 1143 |             } | 
|---|
| 1144 |             break; | 
|---|
| 1145 |         } | 
|---|
| 1146 |         case 2: | 
|---|
| 1147 |         { | 
|---|
| 1148 |             int numI = 5; | 
|---|
| 1149 |             for (int i = 0; i <= numI; ++ i) | 
|---|
| 1150 |             { | 
|---|
| 1151 |                 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin); | 
|---|
| 1152 |                 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength/5); | 
|---|
| 1153 |                 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*2/5); | 
|---|
| 1154 |                 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*3/5); | 
|---|
| 1155 |                 addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*4/5); | 
|---|
| 1156 |                 addEnemy(4, (2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength/2, -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 0.0, 0.0); | 
|---|
| 1157 |             } | 
|---|
| 1158 |             break; | 
|---|
| 1159 |         } | 
|---|
| 1160 |         case 3: | 
|---|
| 1161 |         { | 
|---|
| 1162 |             addRocket(addPlatformStatic(0.0, sectionBegin)); | 
|---|
| 1163 |             addEnemy(2, 0.0, sectionBegin+sectionLength/5, 0.0,0.0, 0.0, 0.0, 0.0, 0.0); | 
|---|
| 1164 |             break; | 
|---|
| 1165 |         } | 
|---|
| 1166 |         case 4: | 
|---|
| 1167 |         { | 
|---|
| 1168 |             addPropeller(addPlatformStatic(0.0, sectionBegin)); | 
|---|
| 1169 |             addPropeller(addPlatformStatic(-fieldWidth/2, sectionBegin)); | 
|---|
| 1170 |             addPropeller(addPlatformStatic(fieldWidth/2, sectionBegin)); | 
|---|
| 1171 |             break; | 
|---|
| 1172 |         } | 
|---|
| 1173 |         default: | 
|---|
| 1174 |             return false; | 
|---|
| 1175 |         } | 
|---|
| 1176 |         sectionNumber_ +=2; | 
|---|
| 1177 |         return true; | 
|---|
| 1178 |     } | 
|---|
| 1179 |  | 
|---|
| 1180 |     float Jump::randomXPosition() | 
|---|
| 1181 |     { | 
|---|
| 1182 |         float fieldWidth = center_->getFieldDimension().x; | 
|---|
| 1183 |  | 
|---|
| 1184 |         return (float)(rand()%(2*(int)fieldWidth)) - fieldWidth; | 
|---|
| 1185 |     } | 
|---|
| 1186 |  | 
|---|
| 1187 |     float Jump::randomXPosition(int totalColumns, int culomn) | 
|---|
| 1188 |     { | 
|---|
| 1189 |         float fieldWidth = center_->getFieldDimension().x; | 
|---|
| 1190 |  | 
|---|
| 1191 |         float halfWidth = fieldWidth/totalColumns; | 
|---|
| 1192 |         float leftBound = culomn*halfWidth*2-fieldWidth; | 
|---|
| 1193 |         float rightBound = leftBound + 2*halfWidth; | 
|---|
| 1194 |  | 
|---|
| 1195 |         return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); | 
|---|
| 1196 |     } | 
|---|
| 1197 |  | 
|---|
| 1198 |     float Jump::randomXPositionLeft(int totalColumns, int culomn) | 
|---|
| 1199 |     { | 
|---|
| 1200 |         float fieldWidth = center_->getFieldDimension().x; | 
|---|
| 1201 |  | 
|---|
| 1202 |         float halfWidth = fieldWidth/totalColumns; | 
|---|
| 1203 |         float leftBound = culomn*halfWidth*2-fieldWidth; | 
|---|
| 1204 |         float rightBound = leftBound + 2*halfWidth/3; | 
|---|
| 1205 |  | 
|---|
| 1206 |         return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); | 
|---|
| 1207 |     } | 
|---|
| 1208 |  | 
|---|
| 1209 |     float Jump::randomXPositionRight(int totalColumns, int culomn) | 
|---|
| 1210 |     { | 
|---|
| 1211 |         float fieldWidth = center_->getFieldDimension().x; | 
|---|
| 1212 |  | 
|---|
| 1213 |         float halfWidth = fieldWidth/totalColumns; | 
|---|
| 1214 |         float rightBound = (culomn+1)*halfWidth*2-fieldWidth; | 
|---|
| 1215 |         float leftBound = rightBound - 2*halfWidth/3; | 
|---|
| 1216 |         return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); | 
|---|
| 1217 |     } | 
|---|
| 1218 |  | 
|---|
| 1219 |     float Jump::randomZPosition(int totalRows, int row, float sectionBegin, float SectionEnd) | 
|---|
| 1220 |     { | 
|---|
| 1221 |         float fieldHeight = SectionEnd - sectionBegin; | 
|---|
| 1222 |         float halfHeight = fieldHeight/totalRows; | 
|---|
| 1223 |         float lowerBound = row*halfHeight*2+sectionBegin; | 
|---|
| 1224 |         float upperBound = lowerBound + 2*halfHeight; | 
|---|
| 1225 |  | 
|---|
| 1226 |         return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); | 
|---|
| 1227 |     } | 
|---|
| 1228 |  | 
|---|
| 1229 |     float Jump::randomZPositionLower(int totalRows, int row, float sectionBegin, float SectionEnd) | 
|---|
| 1230 |     { | 
|---|
| 1231 |         float fieldHeight = SectionEnd - sectionBegin; | 
|---|
| 1232 |         float rowHeight = fieldHeight/totalRows; | 
|---|
| 1233 |         float lowerBound = row*rowHeight+sectionBegin; | 
|---|
| 1234 |         float upperBound = lowerBound + rowHeight/3; | 
|---|
| 1235 |  | 
|---|
| 1236 |         return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); | 
|---|
| 1237 |     } | 
|---|
| 1238 |  | 
|---|
| 1239 |     float Jump::randomZPositionUpper(int totalRows, int row, float sectionBegin, float SectionEnd) | 
|---|
| 1240 |     { | 
|---|
| 1241 |         float fieldHeight = SectionEnd - sectionBegin; | 
|---|
| 1242 |         float rowHeight = fieldHeight/totalRows; | 
|---|
| 1243 |         float lowerBound = (row+1)*rowHeight+sectionBegin; | 
|---|
| 1244 |         float upperBound = lowerBound - rowHeight/3; | 
|---|
| 1245 |  | 
|---|
| 1246 |         return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); | 
|---|
| 1247 |     } | 
|---|
| 1248 |  | 
|---|
| 1249 |     float Jump::randomPosition(float lowerBoundary, float upperBoundary) | 
|---|
| 1250 |     { | 
|---|
| 1251 |         if (lowerBoundary >= upperBoundary) | 
|---|
| 1252 |         { | 
|---|
| 1253 |             return (lowerBoundary + upperBoundary)/2; | 
|---|
| 1254 |         } | 
|---|
| 1255 |  | 
|---|
| 1256 |         return (float)(rand()%(int)(100*(upperBoundary - lowerBoundary)))/100 + lowerBoundary; | 
|---|
| 1257 |     } | 
|---|
| 1258 |  | 
|---|
| 1259 |     float Jump::randomSpeed() | 
|---|
| 1260 |     { | 
|---|
| 1261 |         float platformSpeed = center_->getPlatformSpeed(); | 
|---|
| 1262 |         return randomPosition(0.5f*platformSpeed, 1.5f*platformSpeed); | 
|---|
| 1263 |     } | 
|---|
| 1264 |  | 
|---|
| 1265 |     int Jump::getScore(PlayerInfo* player) const | 
|---|
| 1266 |     { | 
|---|
| 1267 |         return sectionNumber_ - 2; | 
|---|
| 1268 |     } | 
|---|
| 1269 |  | 
|---|
| 1270 |     float Jump::getFuel() const | 
|---|
| 1271 |     { | 
|---|
| 1272 |         if (this->figure_ != nullptr) | 
|---|
| 1273 |         { | 
|---|
| 1274 |             if (this->figure_->rocketActive_ != nullptr) | 
|---|
| 1275 |             { | 
|---|
| 1276 |                 return this->figure_->rocketActive_->getFuelState(); | 
|---|
| 1277 |             } | 
|---|
| 1278 |             else if (this->figure_->propellerActive_ != nullptr) | 
|---|
| 1279 |             { | 
|---|
| 1280 |                 return this->figure_->propellerActive_->getFuelState(); | 
|---|
| 1281 |             } | 
|---|
| 1282 |             else if (this->figure_->shieldActive_ != nullptr) | 
|---|
| 1283 |             { | 
|---|
| 1284 |                 return this->figure_->shieldActive_->getFuelState(); | 
|---|
| 1285 |             } | 
|---|
| 1286 |             else if (this->figure_->bootsActive_ != nullptr) | 
|---|
| 1287 |             { | 
|---|
| 1288 |                 return this->figure_->bootsActive_->getFuelState(); | 
|---|
| 1289 |             } | 
|---|
| 1290 |         } | 
|---|
| 1291 |  | 
|---|
| 1292 |         return 0.0; | 
|---|
| 1293 |     } | 
|---|
| 1294 |  | 
|---|
| 1295 |     bool Jump::getDead(PlayerInfo* player) const | 
|---|
| 1296 |     { | 
|---|
| 1297 |         return figure_->dead_; | 
|---|
| 1298 |     } | 
|---|
| 1299 |  | 
|---|
| 1300 |     void Jump::setCenterpoint(JumpCenterpoint* center) | 
|---|
| 1301 |     { | 
|---|
| 1302 |         center_ = center; | 
|---|
| 1303 |     } | 
|---|
| 1304 |  | 
|---|
| 1305 | } | 
|---|