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 | { |
---|
316 | int score = this->getScore(this->getPlayer()); |
---|
317 | Highscore::getInstance().storeScore("Jump", score, this->getPlayer()); |
---|
318 | } |
---|
319 | Deathmatch::end(); |
---|
320 | } |
---|
321 | |
---|
322 | void Jump::spawnPlayer(PlayerInfo* player) |
---|
323 | { |
---|
324 | assert(player); |
---|
325 | |
---|
326 | if (figure_->getPlayer() == nullptr) |
---|
327 | { |
---|
328 | player->startControl(figure_); |
---|
329 | players_[player].state_ = PlayerState::Alive; |
---|
330 | } |
---|
331 | } |
---|
332 | |
---|
333 | PlayerInfo* Jump::getPlayer() const |
---|
334 | { |
---|
335 | if (this->figure_ != nullptr) |
---|
336 | { |
---|
337 | return this->figure_->getPlayer(); |
---|
338 | } |
---|
339 | else |
---|
340 | { |
---|
341 | return nullptr; |
---|
342 | } |
---|
343 | } |
---|
344 | |
---|
345 | void Jump::addPlatform(JumpPlatform* newPlatform, std::string platformTemplate, float xPosition, float zPosition) |
---|
346 | { |
---|
347 | if (newPlatform != nullptr && center_ != nullptr) |
---|
348 | { |
---|
349 | newPlatform->addTemplate(platformTemplate); |
---|
350 | newPlatform->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
351 | newPlatform->setFigure(this->figure_); |
---|
352 | center_->attach(newPlatform); |
---|
353 | } |
---|
354 | } |
---|
355 | |
---|
356 | JumpPlatformStatic* Jump::addPlatformStatic(float xPosition, float zPosition) |
---|
357 | { |
---|
358 | JumpPlatformStatic* newPlatform = new JumpPlatformStatic(center_->getContext()); |
---|
359 | addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, zPosition); |
---|
360 | |
---|
361 | return newPlatform; |
---|
362 | } |
---|
363 | |
---|
364 | JumpPlatformHMove* Jump::addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed) |
---|
365 | { |
---|
366 | JumpPlatformHMove* newPlatform = new JumpPlatformHMove(center_->getContext()); |
---|
367 | newPlatform->setProperties(leftBoundary, rightBoundary, speed); |
---|
368 | addPlatform(newPlatform, center_->getPlatformHMoveTemplate(), xPosition, zPosition); |
---|
369 | |
---|
370 | return newPlatform; |
---|
371 | } |
---|
372 | |
---|
373 | JumpPlatformVMove* Jump::addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed) |
---|
374 | { |
---|
375 | JumpPlatformVMove* newPlatform = new JumpPlatformVMove(center_->getContext()); |
---|
376 | newPlatform->setProperties(lowerBoundary, upperBoundary, speed); |
---|
377 | addPlatform(newPlatform, center_->getPlatformVMoveTemplate(), xPosition, zPosition); |
---|
378 | |
---|
379 | return newPlatform; |
---|
380 | } |
---|
381 | |
---|
382 | JumpPlatformDisappear* Jump::addPlatformDisappear(float xPosition, float zPosition) |
---|
383 | { |
---|
384 | JumpPlatformDisappear* newPlatform = new JumpPlatformDisappear(center_->getContext()); |
---|
385 | newPlatform->setProperties(true); |
---|
386 | addPlatform(newPlatform, center_->getPlatformDisappearTemplate(), xPosition, zPosition); |
---|
387 | |
---|
388 | return newPlatform; |
---|
389 | } |
---|
390 | |
---|
391 | JumpPlatformTimer* Jump::addPlatformTimer(float xPosition, float zPosition, float time, float variance) |
---|
392 | { |
---|
393 | float additionalTime = (float)(rand()%100)/100.0f*variance - variance/2.0f; |
---|
394 | |
---|
395 | JumpPlatformTimer* newPlatform = new JumpPlatformTimer(center_->getContext()); |
---|
396 | newPlatform->setProperties(time + additionalTime); |
---|
397 | addPlatform(newPlatform, center_->getPlatformTimerTemplate(), xPosition, zPosition); |
---|
398 | |
---|
399 | return newPlatform; |
---|
400 | } |
---|
401 | |
---|
402 | JumpPlatformFake* Jump::addPlatformFake(float xPosition, float zPosition) |
---|
403 | { |
---|
404 | JumpPlatformFake* newPlatform = new JumpPlatformFake(center_->getContext()); |
---|
405 | addPlatform(newPlatform, center_->getPlatformFakeTemplate(), xPosition, zPosition); |
---|
406 | newPlatform->setAngularVelocity(Vector3(0, 0, 2.0)); |
---|
407 | |
---|
408 | return newPlatform; |
---|
409 | } |
---|
410 | |
---|
411 | |
---|
412 | void Jump::addProjectile(float xPosition, float zPosition) |
---|
413 | { |
---|
414 | JumpProjectile* newProjectile = new JumpProjectile(center_->getContext()); |
---|
415 | if (newProjectile != nullptr && center_ != nullptr) |
---|
416 | { |
---|
417 | newProjectile->addTemplate(center_->getProjectileTemplate()); |
---|
418 | newProjectile->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
419 | newProjectile->setFieldDimension(center_->getFieldDimension()); |
---|
420 | newProjectile->setFigure(this->figure_); |
---|
421 | center_->attach(newProjectile); |
---|
422 | } |
---|
423 | } |
---|
424 | |
---|
425 | void Jump::addSpring(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) |
---|
426 | { |
---|
427 | JumpSpring* newSpring = new JumpSpring(center_->getContext()); |
---|
428 | if (newSpring != nullptr && center_ != nullptr) |
---|
429 | { |
---|
430 | newSpring->addTemplate(center_->getSpringTemplate()); |
---|
431 | newSpring->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
432 | newSpring->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); |
---|
433 | newSpring->setFigure(figure_); |
---|
434 | center_->attach(newSpring); |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | void Jump::addSpring(JumpPlatform* platform) |
---|
439 | { |
---|
440 | JumpSpring* newSpring = new JumpSpring(center_->getContext()); |
---|
441 | if (newSpring != nullptr && center_ != nullptr) |
---|
442 | { |
---|
443 | newSpring->addTemplate(center_->getSpringTemplate()); |
---|
444 | newSpring->setPosition(Vector3(0.0, 0.0, 0.0)); |
---|
445 | newSpring->setProperties(-10.0, 10.0, -10.0, 10.0, 0.0, 0.0); |
---|
446 | newSpring->setFigure(figure_); |
---|
447 | platform->attach(newSpring); |
---|
448 | } |
---|
449 | } |
---|
450 | |
---|
451 | void Jump::addRocket(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) |
---|
452 | { |
---|
453 | JumpRocket* newRocket = new JumpRocket(center_->getContext()); |
---|
454 | if (newRocket != nullptr && center_ != nullptr) |
---|
455 | { |
---|
456 | newRocket->addTemplate(center_->getRocketTemplate()); |
---|
457 | newRocket->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
458 | newRocket->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); |
---|
459 | newRocket->setFigure(figure_); |
---|
460 | center_->attach(newRocket); |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | void Jump::addRocket(JumpPlatform* platform) |
---|
465 | { |
---|
466 | JumpRocket* newRocket = new JumpRocket(center_->getContext()); |
---|
467 | if (newRocket != nullptr && center_ != nullptr) |
---|
468 | { |
---|
469 | newRocket->addTemplate(center_->getRocketTemplate()); |
---|
470 | newRocket->setPosition(Vector3(0.0, 0.0, 0.0)); |
---|
471 | newRocket->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
---|
472 | newRocket->setFigure(figure_); |
---|
473 | platform->attach(newRocket); |
---|
474 | } |
---|
475 | } |
---|
476 | |
---|
477 | void Jump::addPropeller(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) |
---|
478 | { |
---|
479 | JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); |
---|
480 | if (newPropeller != nullptr && center_ != nullptr) |
---|
481 | { |
---|
482 | newPropeller->addTemplate(center_->getPropellerTemplate()); |
---|
483 | newPropeller->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
484 | newPropeller->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); |
---|
485 | newPropeller->setFigure(figure_); |
---|
486 | center_->attach(newPropeller); |
---|
487 | } |
---|
488 | } |
---|
489 | |
---|
490 | void Jump::addPropeller(JumpPlatform* platform) |
---|
491 | { |
---|
492 | JumpPropeller* newPropeller = new JumpPropeller(center_->getContext()); |
---|
493 | if (newPropeller != nullptr && center_ != nullptr) |
---|
494 | { |
---|
495 | newPropeller->addTemplate(center_->getPropellerTemplate()); |
---|
496 | newPropeller->setPosition(Vector3(0.0, 0.0, 0.0)); |
---|
497 | newPropeller->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
---|
498 | newPropeller->setFigure(figure_); |
---|
499 | platform->attach(newPropeller); |
---|
500 | } |
---|
501 | } |
---|
502 | |
---|
503 | void Jump::addBoots(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) |
---|
504 | { |
---|
505 | JumpBoots* newBoots = new JumpBoots(center_->getContext()); |
---|
506 | if (newBoots != nullptr && center_ != nullptr) |
---|
507 | { |
---|
508 | newBoots->addTemplate(center_->getBootsTemplate()); |
---|
509 | newBoots->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
510 | newBoots->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); |
---|
511 | newBoots->setFigure(figure_); |
---|
512 | center_->attach(newBoots); |
---|
513 | } |
---|
514 | } |
---|
515 | |
---|
516 | void Jump::addBoots(JumpPlatform* platform) |
---|
517 | { |
---|
518 | JumpBoots* newBoots = new JumpBoots(center_->getContext()); |
---|
519 | if (newBoots != nullptr && center_ != nullptr) |
---|
520 | { |
---|
521 | newBoots->addTemplate(center_->getBootsTemplate()); |
---|
522 | newBoots->setPosition(Vector3(0.0, 0.0, 0.0)); |
---|
523 | newBoots->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
---|
524 | newBoots->setFigure(figure_); |
---|
525 | platform->attach(newBoots); |
---|
526 | } |
---|
527 | } |
---|
528 | |
---|
529 | void Jump::addShield(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) |
---|
530 | { |
---|
531 | JumpShield* newShield = new JumpShield(center_->getContext()); |
---|
532 | if (newShield != nullptr && center_ != nullptr) |
---|
533 | { |
---|
534 | newShield->addTemplate(center_->getShieldTemplate()); |
---|
535 | newShield->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
536 | newShield->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); |
---|
537 | newShield->setFigure(figure_); |
---|
538 | center_->attach(newShield); |
---|
539 | } |
---|
540 | } |
---|
541 | |
---|
542 | void Jump::addShield(JumpPlatform* platform) |
---|
543 | { |
---|
544 | JumpShield* newShield = new JumpShield(center_->getContext()); |
---|
545 | if (newShield != nullptr && center_ != nullptr) |
---|
546 | { |
---|
547 | newShield->addTemplate(center_->getShieldTemplate()); |
---|
548 | newShield->setPosition(Vector3(0.0, 0.0, 0.0)); |
---|
549 | newShield->setProperties(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
---|
550 | newShield->setFigure(figure_); |
---|
551 | platform->attach(newShield); |
---|
552 | } |
---|
553 | } |
---|
554 | |
---|
555 | void Jump::addEnemy(int type, float xPosition, float zPosition, float leftBoundary, float rightBoundary, float lowerBoundary, float upperBoundary, float xVelocity, float zVelocity) |
---|
556 | { |
---|
557 | JumpEnemy* newEnemy = new JumpEnemy(center_->getContext()); |
---|
558 | if (newEnemy != nullptr && center_ != nullptr) |
---|
559 | { |
---|
560 | switch (type) |
---|
561 | { |
---|
562 | case 1: |
---|
563 | newEnemy->addTemplate(center_->getEnemy1Template()); |
---|
564 | break; |
---|
565 | case 2: |
---|
566 | newEnemy->addTemplate(center_->getEnemy2Template()); |
---|
567 | break; |
---|
568 | case 3: |
---|
569 | newEnemy->addTemplate(center_->getEnemy3Template()); |
---|
570 | break; |
---|
571 | case 4: |
---|
572 | newEnemy->addTemplate(center_->getEnemy4Template()); |
---|
573 | break; |
---|
574 | default: |
---|
575 | return; |
---|
576 | } |
---|
577 | |
---|
578 | newEnemy->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
579 | newEnemy->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); |
---|
580 | newEnemy->setFieldDimension(center_->getFieldDimension()); |
---|
581 | newEnemy->setFigure(this->figure_); |
---|
582 | center_->attach(newEnemy); |
---|
583 | } |
---|
584 | } |
---|
585 | |
---|
586 | void Jump::addStartSection() |
---|
587 | { |
---|
588 | JumpPlatform* newPlatform; |
---|
589 | |
---|
590 | float sectionLength = center_->getSectionLength(); |
---|
591 | |
---|
592 | newPlatform = new JumpPlatformStatic(center_->getContext()); |
---|
593 | addPlatform(newPlatform, center_->getPlatformStaticTemplate(), 0.0, -0.05f*sectionLength); |
---|
594 | |
---|
595 | platformWidth_ = newPlatform->getWidth(); |
---|
596 | platformHeight_ = newPlatform->getHeight(); |
---|
597 | |
---|
598 | for (float xPosition = platformWidth_; xPosition <= center_->getFieldDimension().x; xPosition += platformWidth_) |
---|
599 | { |
---|
600 | newPlatform = new JumpPlatformStatic(center_->getContext()); |
---|
601 | addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, -0.05f*sectionLength); |
---|
602 | newPlatform = new JumpPlatformStatic(center_->getContext()); |
---|
603 | addPlatform(newPlatform, center_->getPlatformStaticTemplate(), -xPosition, -0.05f*sectionLength); |
---|
604 | } |
---|
605 | } |
---|
606 | |
---|
607 | void Jump::addSection() |
---|
608 | { |
---|
609 | float fieldWidth = center_->getFieldDimension().x; |
---|
610 | float sectionLength = center_->getSectionLength(); |
---|
611 | float sectionBegin = sectionNumber_ * sectionLength; |
---|
612 | float sectionEnd = (1 + sectionNumber_) * sectionLength; |
---|
613 | |
---|
614 | const int numI = 6; |
---|
615 | const int numJ = 4; |
---|
616 | |
---|
617 | enum class PlatformType |
---|
618 | { |
---|
619 | EMPTY, STATIC, HMOVE, VMOVE, DISAPPEAR, TIMER, FAKE |
---|
620 | }; |
---|
621 | |
---|
622 | enum class ItemType |
---|
623 | { |
---|
624 | NOTHING, SPRING, PROPELLER, ROCKET, BOOTS, SHIELD |
---|
625 | }; |
---|
626 | |
---|
627 | struct PlatformMatrix |
---|
628 | { |
---|
629 | PlatformType type; |
---|
630 | bool done; |
---|
631 | } matrix[numI][numJ]; |
---|
632 | |
---|
633 | |
---|
634 | for (int i = 0; i < numI; ++i) |
---|
635 | { |
---|
636 | for (int j = 0; j < numJ; ++j) |
---|
637 | { |
---|
638 | matrix[i][j].type = PlatformType::EMPTY; |
---|
639 | matrix[i][j].done = false; |
---|
640 | } |
---|
641 | } |
---|
642 | PlatformType platformtype1; |
---|
643 | PlatformType platformtype2; |
---|
644 | ItemType itemType = ItemType::NOTHING; |
---|
645 | |
---|
646 | if (rand()%2 == 0) |
---|
647 | { |
---|
648 | itemType = ItemType::SPRING; |
---|
649 | } |
---|
650 | else if (rand()%2 == 0 && sectionNumber_ > 3) |
---|
651 | { |
---|
652 | switch(rand()%4) |
---|
653 | { |
---|
654 | case 0: |
---|
655 | itemType = ItemType::PROPELLER; |
---|
656 | break; |
---|
657 | case 1: |
---|
658 | itemType = ItemType::ROCKET; |
---|
659 | break; |
---|
660 | case 2: |
---|
661 | itemType = ItemType::BOOTS; |
---|
662 | break; |
---|
663 | case 3: |
---|
664 | itemType = ItemType::SHIELD; |
---|
665 | break; |
---|
666 | default: |
---|
667 | break; |
---|
668 | } |
---|
669 | } |
---|
670 | |
---|
671 | switch((sectionNumber_ > 28) ? rand()%29 : rand()%(sectionNumber_+1)) |
---|
672 | { |
---|
673 | case 0: |
---|
674 | platformtype1 = PlatformType::STATIC; |
---|
675 | platformtype2 = PlatformType::STATIC; |
---|
676 | break; |
---|
677 | case 1: |
---|
678 | platformtype1 = PlatformType::STATIC; |
---|
679 | platformtype2 = PlatformType::STATIC; |
---|
680 | break; |
---|
681 | case 2: |
---|
682 | platformtype1 = PlatformType::STATIC; |
---|
683 | platformtype2 = PlatformType::HMOVE; |
---|
684 | break; |
---|
685 | case 3: |
---|
686 | platformtype1 = PlatformType::STATIC; |
---|
687 | platformtype2 = PlatformType::DISAPPEAR; |
---|
688 | break; |
---|
689 | case 4: |
---|
690 | platformtype1 = PlatformType::STATIC; |
---|
691 | platformtype2 = PlatformType::VMOVE; |
---|
692 | break; |
---|
693 | case 5: |
---|
694 | platformtype1 = PlatformType::STATIC; |
---|
695 | platformtype2 = PlatformType::TIMER; |
---|
696 | break; |
---|
697 | case 6: |
---|
698 | platformtype1 = PlatformType::HMOVE; |
---|
699 | platformtype2 = PlatformType::STATIC; |
---|
700 | break; |
---|
701 | case 7: |
---|
702 | platformtype1 = PlatformType::HMOVE; |
---|
703 | platformtype2 = PlatformType::HMOVE; |
---|
704 | break; |
---|
705 | case 8: |
---|
706 | platformtype1 = PlatformType::HMOVE; |
---|
707 | platformtype2 = PlatformType::HMOVE; |
---|
708 | break; |
---|
709 | case 9: |
---|
710 | platformtype1 = PlatformType::HMOVE; |
---|
711 | platformtype2 = PlatformType::DISAPPEAR; |
---|
712 | break; |
---|
713 | case 10: |
---|
714 | platformtype1 = PlatformType::HMOVE; |
---|
715 | platformtype2 = PlatformType::VMOVE; |
---|
716 | break; |
---|
717 | case 11: |
---|
718 | platformtype1 = PlatformType::HMOVE; |
---|
719 | platformtype2 = PlatformType::TIMER; |
---|
720 | break; |
---|
721 | case 12: |
---|
722 | platformtype1 = PlatformType::DISAPPEAR; |
---|
723 | platformtype2 = PlatformType::STATIC; |
---|
724 | break; |
---|
725 | case 13: |
---|
726 | platformtype1 = PlatformType::DISAPPEAR; |
---|
727 | platformtype2 = PlatformType::HMOVE; |
---|
728 | break; |
---|
729 | case 14: |
---|
730 | platformtype1 = PlatformType::DISAPPEAR; |
---|
731 | platformtype2 = PlatformType::DISAPPEAR; |
---|
732 | break; |
---|
733 | case 15: |
---|
734 | platformtype1 = PlatformType::DISAPPEAR; |
---|
735 | platformtype2 = PlatformType::DISAPPEAR; |
---|
736 | break; |
---|
737 | case 16: |
---|
738 | platformtype1 = PlatformType::DISAPPEAR; |
---|
739 | platformtype2 = PlatformType::VMOVE; |
---|
740 | break; |
---|
741 | case 17: |
---|
742 | platformtype1 = PlatformType::DISAPPEAR; |
---|
743 | platformtype2 = PlatformType::TIMER; |
---|
744 | break; |
---|
745 | case 18: |
---|
746 | platformtype1 = PlatformType::VMOVE; |
---|
747 | platformtype2 = PlatformType::STATIC; |
---|
748 | break; |
---|
749 | case 19: |
---|
750 | platformtype1 = PlatformType::VMOVE; |
---|
751 | platformtype2 = PlatformType::HMOVE; |
---|
752 | break; |
---|
753 | case 20: |
---|
754 | platformtype1 = PlatformType::VMOVE; |
---|
755 | platformtype2 = PlatformType::DISAPPEAR; |
---|
756 | break; |
---|
757 | case 21: |
---|
758 | platformtype1 = PlatformType::VMOVE; |
---|
759 | platformtype2 = PlatformType::VMOVE; |
---|
760 | break; |
---|
761 | case 22: |
---|
762 | platformtype1 = PlatformType::VMOVE; |
---|
763 | platformtype2 = PlatformType::VMOVE; |
---|
764 | break; |
---|
765 | case 23: |
---|
766 | platformtype1 = PlatformType::VMOVE; |
---|
767 | platformtype2 = PlatformType::TIMER; |
---|
768 | break; |
---|
769 | case 24: |
---|
770 | platformtype1 = PlatformType::TIMER; |
---|
771 | platformtype2 = PlatformType::STATIC; |
---|
772 | break; |
---|
773 | case 25: |
---|
774 | platformtype1 = PlatformType::TIMER; |
---|
775 | platformtype2 = PlatformType::HMOVE; |
---|
776 | break; |
---|
777 | case 26: |
---|
778 | platformtype1 = PlatformType::TIMER; |
---|
779 | platformtype2 = PlatformType::DISAPPEAR; |
---|
780 | break; |
---|
781 | case 27: |
---|
782 | platformtype1 = PlatformType::TIMER; |
---|
783 | platformtype2 = PlatformType::VMOVE; |
---|
784 | break; |
---|
785 | case 28: |
---|
786 | platformtype1 = PlatformType::TIMER; |
---|
787 | platformtype2 = PlatformType::TIMER; |
---|
788 | break; |
---|
789 | default: |
---|
790 | platformtype1 = PlatformType::TIMER; |
---|
791 | platformtype2 = PlatformType::TIMER; |
---|
792 | break; |
---|
793 | } |
---|
794 | |
---|
795 | // Fill matrix with selected platform types |
---|
796 | for (int i = 0; i < numI; ++ i) |
---|
797 | { |
---|
798 | for (int j = 0; j < numJ; ++ j) |
---|
799 | { |
---|
800 | if (rand()%3 == 0) |
---|
801 | { |
---|
802 | matrix[i][j].type = platformtype1; |
---|
803 | } |
---|
804 | else |
---|
805 | { |
---|
806 | matrix[i][j].type = platformtype2; |
---|
807 | } |
---|
808 | matrix[i][j].done = false; |
---|
809 | } |
---|
810 | } |
---|
811 | |
---|
812 | if (platformtype1 == platformtype2 && sectionNumber_ > 10 && rand()%2 == 0) |
---|
813 | { |
---|
814 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
815 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
816 | } |
---|
817 | |
---|
818 | // Delete some planned platforms or replace them with fake platforms |
---|
819 | if (sectionNumber_ > 5) |
---|
820 | { |
---|
821 | if (rand()%2 == 0) |
---|
822 | { |
---|
823 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
824 | } |
---|
825 | else |
---|
826 | { |
---|
827 | matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; |
---|
828 | } |
---|
829 | } |
---|
830 | else if (sectionNumber_ > 10) |
---|
831 | { |
---|
832 | if (rand()%2 == 0) |
---|
833 | { |
---|
834 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
835 | } |
---|
836 | else |
---|
837 | { |
---|
838 | matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; |
---|
839 | } |
---|
840 | if (rand()%2 == 0) |
---|
841 | { |
---|
842 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
843 | } |
---|
844 | else |
---|
845 | { |
---|
846 | matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; |
---|
847 | } |
---|
848 | } |
---|
849 | else if (sectionNumber_ > 15) |
---|
850 | { |
---|
851 | if (rand()%2 == 0) |
---|
852 | { |
---|
853 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
854 | } |
---|
855 | else |
---|
856 | { |
---|
857 | matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; |
---|
858 | } |
---|
859 | if (rand()%2 == 0) |
---|
860 | { |
---|
861 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
862 | } |
---|
863 | else |
---|
864 | { |
---|
865 | matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; |
---|
866 | } |
---|
867 | if (rand()%2 == 0) |
---|
868 | { |
---|
869 | matrix[rand()%numI][rand()%numJ].type = PlatformType::EMPTY; |
---|
870 | } |
---|
871 | else |
---|
872 | { |
---|
873 | matrix[rand()%numI][rand()%numJ].type = PlatformType::FAKE; |
---|
874 | } |
---|
875 | } |
---|
876 | |
---|
877 | std::vector<JumpPlatform*> platformList; |
---|
878 | |
---|
879 | for (int i = 0; i < numI; ++ i) |
---|
880 | { |
---|
881 | for (int j = 0; j < numJ; ++ j) |
---|
882 | { |
---|
883 | if (matrix[i][j].done == false) |
---|
884 | { |
---|
885 | float xPosition = 0.0; |
---|
886 | float zPosition = 0.0; |
---|
887 | float leftBoundary = 0.0; |
---|
888 | float rightBoundary = 0.0; |
---|
889 | float lowerBoundary = 0.0; |
---|
890 | float upperBoundary = 0.0; |
---|
891 | float xVelocity = 0.0; |
---|
892 | float zVelocity = 0.0; |
---|
893 | |
---|
894 | switch(matrix[i][j].type) |
---|
895 | { |
---|
896 | case PlatformType::EMPTY: |
---|
897 | matrix[i][j].done = true; |
---|
898 | break; |
---|
899 | case PlatformType::STATIC: |
---|
900 | xPosition = randomXPosition(numJ, j); |
---|
901 | zPosition = sectionBegin + i*sectionLength/numI; |
---|
902 | platformList.push_back(addPlatformStatic(xPosition, zPosition)); |
---|
903 | matrix[i][j].done = true; |
---|
904 | break; |
---|
905 | case PlatformType::FAKE: |
---|
906 | xPosition = randomXPosition(numJ, j); |
---|
907 | zPosition = sectionBegin + i*sectionLength/numI; |
---|
908 | platformList.push_back(addPlatformFake(xPosition, zPosition)); |
---|
909 | matrix[i][j].done = true; |
---|
910 | break; |
---|
911 | case PlatformType::TIMER: |
---|
912 | xPosition = randomXPosition(numJ, j); |
---|
913 | zPosition = sectionBegin + i*sectionLength/numI; |
---|
914 | platformList.push_back(addPlatformTimer(xPosition, zPosition, 12.0, 1.5)); |
---|
915 | matrix[i][j].done = true; |
---|
916 | break; |
---|
917 | case PlatformType::DISAPPEAR: |
---|
918 | xPosition = randomXPosition(numJ, j); |
---|
919 | zPosition = sectionBegin + i*sectionLength/numI; |
---|
920 | platformList.push_back(addPlatformDisappear(xPosition, zPosition)); |
---|
921 | matrix[i][j].done = true; |
---|
922 | break; |
---|
923 | case PlatformType::HMOVE: |
---|
924 | xVelocity = randomSpeed(); |
---|
925 | if (j <= numJ-3 && matrix[i][j+1].type == PlatformType::HMOVE && matrix[i][j+2].type == PlatformType::HMOVE && rand()%2 == 0) |
---|
926 | { |
---|
927 | leftBoundary = randomXPositionLeft(numJ, j); |
---|
928 | rightBoundary = randomXPositionRight(numJ, j+2); |
---|
929 | xPosition = randomPosition(leftBoundary, rightBoundary); |
---|
930 | zPosition = sectionBegin + i*sectionLength/numI; |
---|
931 | platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); |
---|
932 | matrix[i][j].done = true; |
---|
933 | matrix[i][j+1].done = true; |
---|
934 | matrix[i][j+2].done = true; |
---|
935 | } |
---|
936 | else if (j <= numJ-2 && matrix[i][j+1].type == PlatformType::HMOVE && rand()%2 == 0) |
---|
937 | { |
---|
938 | leftBoundary = randomXPositionLeft(numJ, j); |
---|
939 | rightBoundary = randomXPositionRight(numJ, j+1); |
---|
940 | xPosition = randomPosition(leftBoundary, rightBoundary); |
---|
941 | zPosition = sectionBegin + i*sectionLength/numI; |
---|
942 | platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); |
---|
943 | matrix[i][j].done = true; |
---|
944 | matrix[i][j+1].done = true; |
---|
945 | } |
---|
946 | else |
---|
947 | { |
---|
948 | leftBoundary = randomXPositionLeft(numJ, j); |
---|
949 | rightBoundary = randomXPositionRight(numJ, j); |
---|
950 | xPosition = randomPosition(leftBoundary, rightBoundary); |
---|
951 | zPosition = sectionBegin + i*sectionLength/numI; |
---|
952 | platformList.push_back(addPlatformHMove(xPosition, zPosition, leftBoundary, rightBoundary, xVelocity)); |
---|
953 | matrix[i][j].done = true; |
---|
954 | } |
---|
955 | break; |
---|
956 | case PlatformType::VMOVE: |
---|
957 | zVelocity = randomSpeed(); |
---|
958 | if (i <= numI-3 && matrix[i+1][j].type == PlatformType::VMOVE && matrix[i+2][j].type == PlatformType::VMOVE && rand()%2 == 0) |
---|
959 | { |
---|
960 | lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); |
---|
961 | upperBoundary = randomZPositionUpper(numI, i+2, sectionBegin, sectionEnd); |
---|
962 | zPosition = randomPosition(lowerBoundary, upperBoundary); |
---|
963 | xPosition = randomXPosition(numJ, j); |
---|
964 | platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); |
---|
965 | matrix[i][j].done = true; |
---|
966 | matrix[i+1][j].done = true; |
---|
967 | matrix[i+2][j].done = true; |
---|
968 | } |
---|
969 | else if (i <= numI-2 && matrix[i+1][j].type == PlatformType::VMOVE && rand()%2 == 0) |
---|
970 | { |
---|
971 | lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); |
---|
972 | upperBoundary = randomZPositionUpper(numI, i+1, sectionBegin, sectionEnd); |
---|
973 | zPosition = randomPosition(lowerBoundary, upperBoundary); |
---|
974 | xPosition = randomXPosition(numJ, j); |
---|
975 | platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); |
---|
976 | matrix[i][j].done = true; |
---|
977 | matrix[i+1][j].done = true; |
---|
978 | } |
---|
979 | else |
---|
980 | { |
---|
981 | lowerBoundary = randomZPositionLower(numI, i, sectionBegin, sectionEnd); |
---|
982 | upperBoundary = randomZPositionUpper(numI, i, sectionBegin, sectionEnd); |
---|
983 | zPosition = randomPosition(lowerBoundary, upperBoundary); |
---|
984 | xPosition = randomXPosition(numJ, j); |
---|
985 | platformList.push_back(addPlatformVMove(xPosition, zPosition, lowerBoundary, upperBoundary, zVelocity)); |
---|
986 | matrix[i][j].done = true; |
---|
987 | } |
---|
988 | break; |
---|
989 | default: |
---|
990 | //ERROR |
---|
991 | break; |
---|
992 | |
---|
993 | } |
---|
994 | } |
---|
995 | } |
---|
996 | } |
---|
997 | |
---|
998 | //Add items |
---|
999 | int numNewPlatforms = platformList.size(); |
---|
1000 | |
---|
1001 | if (rand()%4 == 0) |
---|
1002 | { |
---|
1003 | if (rand()%2 == 0) |
---|
1004 | { |
---|
1005 | switch (itemType) |
---|
1006 | { |
---|
1007 | case ItemType::ROCKET: |
---|
1008 | addRocket(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); |
---|
1009 | break; |
---|
1010 | case ItemType::PROPELLER: |
---|
1011 | addPropeller(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); |
---|
1012 | break; |
---|
1013 | case ItemType::BOOTS: |
---|
1014 | addBoots(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); |
---|
1015 | break; |
---|
1016 | case ItemType::SHIELD: |
---|
1017 | addShield(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); |
---|
1018 | break; |
---|
1019 | default: |
---|
1020 | break; |
---|
1021 | } |
---|
1022 | } |
---|
1023 | else |
---|
1024 | { |
---|
1025 | switch (itemType) |
---|
1026 | { |
---|
1027 | case ItemType::ROCKET: |
---|
1028 | addRocket(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); |
---|
1029 | break; |
---|
1030 | case ItemType::PROPELLER: |
---|
1031 | addPropeller(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); |
---|
1032 | break; |
---|
1033 | case ItemType::BOOTS: |
---|
1034 | addBoots(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); |
---|
1035 | break; |
---|
1036 | case ItemType::SHIELD: |
---|
1037 | addShield(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); |
---|
1038 | break; |
---|
1039 | default: |
---|
1040 | break; |
---|
1041 | } |
---|
1042 | } |
---|
1043 | } |
---|
1044 | else |
---|
1045 | { |
---|
1046 | if (numNewPlatforms > 0) |
---|
1047 | { |
---|
1048 | JumpPlatform* itemPlatform = platformList[rand()%numNewPlatforms]; |
---|
1049 | |
---|
1050 | switch (itemType) |
---|
1051 | { |
---|
1052 | case ItemType::SPRING: |
---|
1053 | addSpring(itemPlatform); |
---|
1054 | break; |
---|
1055 | case ItemType::ROCKET: |
---|
1056 | addRocket(itemPlatform); |
---|
1057 | break; |
---|
1058 | case ItemType::PROPELLER: |
---|
1059 | addPropeller(itemPlatform); |
---|
1060 | break; |
---|
1061 | case ItemType::BOOTS: |
---|
1062 | addBoots(itemPlatform); |
---|
1063 | break; |
---|
1064 | case ItemType::SHIELD: |
---|
1065 | addShield(itemPlatform); |
---|
1066 | break; |
---|
1067 | default: |
---|
1068 | break; |
---|
1069 | } |
---|
1070 | } |
---|
1071 | } |
---|
1072 | |
---|
1073 | if (sectionNumber_ >= 5 && rand()%3 == 0) |
---|
1074 | { |
---|
1075 | switch(rand()%4) |
---|
1076 | { |
---|
1077 | case 0: |
---|
1078 | addEnemy(1, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); |
---|
1079 | break; |
---|
1080 | case 1: |
---|
1081 | addEnemy(2, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); |
---|
1082 | break; |
---|
1083 | case 2: |
---|
1084 | addEnemy(3, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); |
---|
1085 | break; |
---|
1086 | case 3: |
---|
1087 | addEnemy(4, randomXPosition(), randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/3*2, fieldWidth/3*2, sectionBegin, sectionBegin + sectionLength, randomSpeed(), 0.0); |
---|
1088 | break; |
---|
1089 | } |
---|
1090 | } |
---|
1091 | ++ sectionNumber_; |
---|
1092 | } |
---|
1093 | |
---|
1094 | bool Jump::addAdventure(int number) |
---|
1095 | { |
---|
1096 | float fieldWidth = center_->getFieldDimension().x; |
---|
1097 | float sectionLength = center_->getSectionLength(); |
---|
1098 | float sectionBegin = sectionNumber_ * sectionLength; |
---|
1099 | sectionLength *= 2; |
---|
1100 | |
---|
1101 | switch(number) |
---|
1102 | { |
---|
1103 | case 0: |
---|
1104 | { |
---|
1105 | int numI = 10; |
---|
1106 | if (rand()%2 == 0) |
---|
1107 | { |
---|
1108 | for (int i = 0; i < numI; ++ i) |
---|
1109 | { |
---|
1110 | addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+i*sectionLength/numI); |
---|
1111 | } |
---|
1112 | } |
---|
1113 | else |
---|
1114 | { |
---|
1115 | for (int i = 0; i < numI; ++ i) |
---|
1116 | { |
---|
1117 | addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+(numI-i)*sectionLength/numI); |
---|
1118 | } |
---|
1119 | } |
---|
1120 | break; |
---|
1121 | } |
---|
1122 | case 1: |
---|
1123 | { |
---|
1124 | int numI = 7; |
---|
1125 | |
---|
1126 | addPlatformStatic(0.0, sectionBegin); |
---|
1127 | if (rand()%2 == 0) |
---|
1128 | { |
---|
1129 | for (int i = 1; i < numI; ++ i) |
---|
1130 | { |
---|
1131 | addPlatformStatic((fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); |
---|
1132 | addPlatformStatic(-(fieldWidth-platformWidth_/2)*i/numI, sectionBegin+i*sectionLength/numI); |
---|
1133 | } |
---|
1134 | } |
---|
1135 | else |
---|
1136 | { |
---|
1137 | for (int i = 1; i < numI; ++ i) |
---|
1138 | { |
---|
1139 | addPlatformStatic((fieldWidth-platformWidth_/2)*i/numI, sectionBegin+(numI-i)*sectionLength/numI); |
---|
1140 | addPlatformStatic(-(fieldWidth-platformWidth_/2)*i/numI, sectionBegin+(numI-i)*sectionLength/numI); |
---|
1141 | } |
---|
1142 | } |
---|
1143 | break; |
---|
1144 | } |
---|
1145 | case 2: |
---|
1146 | { |
---|
1147 | int numI = 5; |
---|
1148 | for (int i = 0; i <= numI; ++ i) |
---|
1149 | { |
---|
1150 | addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin); |
---|
1151 | addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength/5); |
---|
1152 | addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*2/5); |
---|
1153 | addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*3/5); |
---|
1154 | addPlatformStatic((2*fieldWidth-platformWidth_)*i/numI-fieldWidth, sectionBegin+sectionLength*4/5); |
---|
1155 | addEnemy(4, (2*fieldWidth-platformWidth_)*i/numI-fieldWidth+platformWidth_/2, sectionBegin+sectionLength/2, -fieldWidth, fieldWidth, sectionBegin, sectionBegin + sectionLength, 0.0, 0.0); |
---|
1156 | } |
---|
1157 | break; |
---|
1158 | } |
---|
1159 | case 3: |
---|
1160 | { |
---|
1161 | addRocket(addPlatformStatic(0.0, sectionBegin)); |
---|
1162 | addEnemy(2, 0.0, sectionBegin+sectionLength/5, 0.0,0.0, 0.0, 0.0, 0.0, 0.0); |
---|
1163 | break; |
---|
1164 | } |
---|
1165 | case 4: |
---|
1166 | { |
---|
1167 | addPropeller(addPlatformStatic(0.0, sectionBegin)); |
---|
1168 | addPropeller(addPlatformStatic(-fieldWidth/2, sectionBegin)); |
---|
1169 | addPropeller(addPlatformStatic(fieldWidth/2, sectionBegin)); |
---|
1170 | break; |
---|
1171 | } |
---|
1172 | default: |
---|
1173 | return false; |
---|
1174 | } |
---|
1175 | sectionNumber_ +=2; |
---|
1176 | return true; |
---|
1177 | } |
---|
1178 | |
---|
1179 | float Jump::randomXPosition() |
---|
1180 | { |
---|
1181 | float fieldWidth = center_->getFieldDimension().x; |
---|
1182 | |
---|
1183 | return (float)(rand()%(2*(int)fieldWidth)) - fieldWidth; |
---|
1184 | } |
---|
1185 | |
---|
1186 | float Jump::randomXPosition(int totalColumns, int culomn) |
---|
1187 | { |
---|
1188 | float fieldWidth = center_->getFieldDimension().x; |
---|
1189 | |
---|
1190 | float halfWidth = fieldWidth/totalColumns; |
---|
1191 | float leftBound = culomn*halfWidth*2-fieldWidth; |
---|
1192 | float rightBound = leftBound + 2*halfWidth; |
---|
1193 | |
---|
1194 | return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); |
---|
1195 | } |
---|
1196 | |
---|
1197 | float Jump::randomXPositionLeft(int totalColumns, int culomn) |
---|
1198 | { |
---|
1199 | float fieldWidth = center_->getFieldDimension().x; |
---|
1200 | |
---|
1201 | float halfWidth = fieldWidth/totalColumns; |
---|
1202 | float leftBound = culomn*halfWidth*2-fieldWidth; |
---|
1203 | float rightBound = leftBound + 2*halfWidth/3; |
---|
1204 | |
---|
1205 | return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); |
---|
1206 | } |
---|
1207 | |
---|
1208 | float Jump::randomXPositionRight(int totalColumns, int culomn) |
---|
1209 | { |
---|
1210 | float fieldWidth = center_->getFieldDimension().x; |
---|
1211 | |
---|
1212 | float halfWidth = fieldWidth/totalColumns; |
---|
1213 | float rightBound = (culomn+1)*halfWidth*2-fieldWidth; |
---|
1214 | float leftBound = rightBound - 2*halfWidth/3; |
---|
1215 | return randomPosition(leftBound+platformWidth_/2, rightBound-platformWidth_/2); |
---|
1216 | } |
---|
1217 | |
---|
1218 | float Jump::randomZPosition(int totalRows, int row, float sectionBegin, float SectionEnd) |
---|
1219 | { |
---|
1220 | float fieldHeight = SectionEnd - sectionBegin; |
---|
1221 | float halfHeight = fieldHeight/totalRows; |
---|
1222 | float lowerBound = row*halfHeight*2+sectionBegin; |
---|
1223 | float upperBound = lowerBound + 2*halfHeight; |
---|
1224 | |
---|
1225 | return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); |
---|
1226 | } |
---|
1227 | |
---|
1228 | float Jump::randomZPositionLower(int totalRows, int row, float sectionBegin, float SectionEnd) |
---|
1229 | { |
---|
1230 | float fieldHeight = SectionEnd - sectionBegin; |
---|
1231 | float rowHeight = fieldHeight/totalRows; |
---|
1232 | float lowerBound = row*rowHeight+sectionBegin; |
---|
1233 | float upperBound = lowerBound + rowHeight/3; |
---|
1234 | |
---|
1235 | return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); |
---|
1236 | } |
---|
1237 | |
---|
1238 | float Jump::randomZPositionUpper(int totalRows, int row, float sectionBegin, float SectionEnd) |
---|
1239 | { |
---|
1240 | float fieldHeight = SectionEnd - sectionBegin; |
---|
1241 | float rowHeight = fieldHeight/totalRows; |
---|
1242 | float lowerBound = (row+1)*rowHeight+sectionBegin; |
---|
1243 | float upperBound = lowerBound - rowHeight/3; |
---|
1244 | |
---|
1245 | return randomPosition(lowerBound+platformHeight_/2, upperBound-platformHeight_/2); |
---|
1246 | } |
---|
1247 | |
---|
1248 | float Jump::randomPosition(float lowerBoundary, float upperBoundary) |
---|
1249 | { |
---|
1250 | if (lowerBoundary >= upperBoundary) |
---|
1251 | { |
---|
1252 | return (lowerBoundary + upperBoundary)/2; |
---|
1253 | } |
---|
1254 | |
---|
1255 | return (float)(rand()%(int)(100*(upperBoundary - lowerBoundary)))/100 + lowerBoundary; |
---|
1256 | } |
---|
1257 | |
---|
1258 | float Jump::randomSpeed() |
---|
1259 | { |
---|
1260 | float platformSpeed = center_->getPlatformSpeed(); |
---|
1261 | return randomPosition(0.5f*platformSpeed, 1.5f*platformSpeed); |
---|
1262 | } |
---|
1263 | |
---|
1264 | int Jump::getScore(PlayerInfo* player) const |
---|
1265 | { |
---|
1266 | return sectionNumber_ - 2; |
---|
1267 | } |
---|
1268 | |
---|
1269 | float Jump::getFuel() const |
---|
1270 | { |
---|
1271 | if (this->figure_ != nullptr) |
---|
1272 | { |
---|
1273 | if (this->figure_->rocketActive_ != nullptr) |
---|
1274 | { |
---|
1275 | return this->figure_->rocketActive_->getFuelState(); |
---|
1276 | } |
---|
1277 | else if (this->figure_->propellerActive_ != nullptr) |
---|
1278 | { |
---|
1279 | return this->figure_->propellerActive_->getFuelState(); |
---|
1280 | } |
---|
1281 | else if (this->figure_->shieldActive_ != nullptr) |
---|
1282 | { |
---|
1283 | return this->figure_->shieldActive_->getFuelState(); |
---|
1284 | } |
---|
1285 | else if (this->figure_->bootsActive_ != nullptr) |
---|
1286 | { |
---|
1287 | return this->figure_->bootsActive_->getFuelState(); |
---|
1288 | } |
---|
1289 | } |
---|
1290 | |
---|
1291 | return 0.0; |
---|
1292 | } |
---|
1293 | |
---|
1294 | bool Jump::getDead(PlayerInfo* player) const |
---|
1295 | { |
---|
1296 | return figure_->dead_; |
---|
1297 | } |
---|
1298 | |
---|
1299 | void Jump::setCenterpoint(JumpCenterpoint* center) |
---|
1300 | { |
---|
1301 | center_ = center; |
---|
1302 | } |
---|
1303 | |
---|
1304 | } |
---|