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 | |
---|
37 | #include "JumpCenterpoint.h" |
---|
38 | #include "JumpPlatform.h" |
---|
39 | #include "JumpPlatformStatic.h" |
---|
40 | #include "JumpPlatformHMove.h" |
---|
41 | #include "JumpPlatformVMove.h" |
---|
42 | #include "JumpPlatformDisappear.h" |
---|
43 | #include "JumpPlatformTimer.h" |
---|
44 | #include "JumpPlatformFake.h" |
---|
45 | #include "JumpProjectile.h" |
---|
46 | #include "JumpEnemy.h" |
---|
47 | #include "JumpFigure.h" |
---|
48 | #include "JumpItem.h" |
---|
49 | #include "JumpSpring.h" |
---|
50 | #include "JumpRocket.h" |
---|
51 | #include "JumpPropeller.h" |
---|
52 | #include "JumpBoots.h" |
---|
53 | #include "JumpShield.h" |
---|
54 | |
---|
55 | #include "gamestates/GSLevel.h" |
---|
56 | #include "infos/PlayerInfo.h" |
---|
57 | #include "graphics/Camera.h" |
---|
58 | |
---|
59 | namespace orxonox |
---|
60 | { |
---|
61 | RegisterUnloadableClass(Jump); |
---|
62 | |
---|
63 | Jump::Jump(Context* context) : Deathmatch(context) |
---|
64 | { |
---|
65 | RegisterObject(Jump); |
---|
66 | |
---|
67 | center_ = 0; |
---|
68 | figure_ = 0; |
---|
69 | camera = 0; |
---|
70 | setHUDTemplate("JumpHUD"); |
---|
71 | } |
---|
72 | |
---|
73 | Jump::~Jump() |
---|
74 | { |
---|
75 | if (isInitialized()) |
---|
76 | { |
---|
77 | cleanup(); |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | void Jump::tick(float dt) |
---|
82 | { |
---|
83 | SUPER(Jump, tick, dt); |
---|
84 | |
---|
85 | if (figure_ != NULL) |
---|
86 | { |
---|
87 | Vector3 figurePosition = figure_->getPosition(); |
---|
88 | Vector3 figureVelocity = figure_->getVelocity(); |
---|
89 | |
---|
90 | float boundary = totalScreenShift_+center_->getCameraOffset(); |
---|
91 | |
---|
92 | if (figurePosition.z > boundary) |
---|
93 | { |
---|
94 | screenShiftSinceLastUpdate_ += figurePosition.z - boundary; |
---|
95 | totalScreenShift_ = figurePosition.z - center_->getCameraOffset(); |
---|
96 | |
---|
97 | // Create new platforms if needed |
---|
98 | if (screenShiftSinceLastUpdate_ > center_->getSectionLength()) |
---|
99 | { |
---|
100 | if (sectionNumber_ > 2 && sectionNumber_%4 == 0 && rand()%2 == 0 && figure_->propellerActive_ == false && figure_->rocketActive_ == false && addAdventure(adventureNumber_) == true) |
---|
101 | { |
---|
102 | screenShiftSinceLastUpdate_ -= 2*center_->getSectionLength(); |
---|
103 | ++ adventureNumber_; |
---|
104 | } |
---|
105 | else |
---|
106 | { |
---|
107 | screenShiftSinceLastUpdate_ -= center_->getSectionLength(); |
---|
108 | addSection(); |
---|
109 | } |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | if (figurePosition.z < totalScreenShift_ - center_->getFieldDimension().y + platformHeight_ && figureVelocity.z < 0) |
---|
114 | { |
---|
115 | figure_->dead_ = true; |
---|
116 | } |
---|
117 | |
---|
118 | if (figure_->fireSignal_ == true) |
---|
119 | { |
---|
120 | if (figure_->dead_ == true) |
---|
121 | { |
---|
122 | end(); |
---|
123 | } |
---|
124 | else |
---|
125 | { |
---|
126 | figure_->fireSignal_ = false; |
---|
127 | addProjectile(figurePosition.x, figurePosition.z + figure_->getPropellerPos()); |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | if (camera != NULL) |
---|
133 | { |
---|
134 | Vector3 cameraPosition = Vector3(0, totalScreenShift_, 0); |
---|
135 | camera->setPosition(cameraPosition); |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | orxout() << "No camera found." << endl; |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | ObjectList<JumpPlatform>::iterator beginPlatform = ObjectList<JumpPlatform>::begin(); |
---|
144 | ObjectList<JumpPlatform>::iterator endPlatform = ObjectList<JumpPlatform>::end(); |
---|
145 | ObjectList<JumpPlatform>::iterator itPlatform = beginPlatform; |
---|
146 | Vector3 platformPosition; |
---|
147 | |
---|
148 | while (itPlatform != endPlatform) |
---|
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>::iterator beginDisappear = ObjectList<JumpPlatformDisappear>::begin(); |
---|
166 | ObjectList<JumpPlatformDisappear>::iterator endDisappear = ObjectList<JumpPlatformDisappear>::end(); |
---|
167 | ObjectList<JumpPlatformDisappear>::iterator itDisappear = beginDisappear; |
---|
168 | |
---|
169 | while (itDisappear != endDisappear) |
---|
170 | { |
---|
171 | if (!itDisappear->isActive()) |
---|
172 | { |
---|
173 | ObjectList<JumpPlatformDisappear>::iterator temp = itDisappear; |
---|
174 | ++ itDisappear; |
---|
175 | center_->detach(*temp); |
---|
176 | temp->destroy(); |
---|
177 | } |
---|
178 | else |
---|
179 | { |
---|
180 | ++ itDisappear; |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | ObjectList<JumpPlatformTimer>::iterator beginTimer = ObjectList<JumpPlatformTimer>::begin(); |
---|
185 | ObjectList<JumpPlatformTimer>::iterator endTimer = ObjectList<JumpPlatformTimer>::end(); |
---|
186 | ObjectList<JumpPlatformTimer>::iterator itTimer = beginTimer; |
---|
187 | |
---|
188 | while (itTimer != endTimer) |
---|
189 | { |
---|
190 | if (!itTimer->isActive()) |
---|
191 | { |
---|
192 | ObjectList<JumpPlatformTimer>::iterator temp = itTimer; |
---|
193 | ++ itTimer; |
---|
194 | center_->detach(*temp); |
---|
195 | temp->destroy(); |
---|
196 | } |
---|
197 | else |
---|
198 | { |
---|
199 | ++ itTimer; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | ObjectList<JumpProjectile>::iterator beginProjectile = ObjectList<JumpProjectile>::begin(); |
---|
204 | ObjectList<JumpProjectile>::iterator endProjectile = ObjectList<JumpProjectile>::end(); |
---|
205 | ObjectList<JumpProjectile>::iterator itProjectile = beginProjectile; |
---|
206 | Vector3 projectilePosition; |
---|
207 | |
---|
208 | while (itProjectile != endProjectile) |
---|
209 | { |
---|
210 | projectilePosition = itProjectile->getPosition(); |
---|
211 | if (projectilePosition.z > totalScreenShift_ + 5*center_->getFieldDimension().y) |
---|
212 | { |
---|
213 | ObjectList<JumpProjectile>::iterator temp = itProjectile; |
---|
214 | ++ itProjectile; |
---|
215 | center_->detach(*temp); |
---|
216 | temp->destroy(); |
---|
217 | } |
---|
218 | else |
---|
219 | { |
---|
220 | ++ itProjectile; |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | ObjectList<JumpEnemy>::iterator beginEnemy = ObjectList<JumpEnemy>::begin(); |
---|
225 | ObjectList<JumpEnemy>::iterator endEnemy = ObjectList<JumpEnemy>::end(); |
---|
226 | ObjectList<JumpEnemy>::iterator itEnemy = beginEnemy; |
---|
227 | Vector3 enemyPosition; |
---|
228 | |
---|
229 | while (itEnemy != endEnemy) |
---|
230 | { |
---|
231 | enemyPosition = itEnemy->getPosition(); |
---|
232 | if (enemyPosition.z < totalScreenShift_ - center_->getFieldDimension().y || itEnemy->dead_ == true) |
---|
233 | { |
---|
234 | ObjectList<JumpEnemy>::iterator temp = itEnemy; |
---|
235 | ++ itEnemy; |
---|
236 | center_->detach(*temp); |
---|
237 | temp->destroy(); |
---|
238 | } |
---|
239 | else |
---|
240 | { |
---|
241 | ++ itEnemy; |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | ObjectList<JumpItem>::iterator beginItem = ObjectList<JumpItem>::begin(); |
---|
246 | ObjectList<JumpItem>::iterator endItem = ObjectList<JumpItem>::end(); |
---|
247 | ObjectList<JumpItem>::iterator itItem = beginItem; |
---|
248 | Vector3 itemPosition; |
---|
249 | |
---|
250 | while (itItem != endItem) |
---|
251 | { |
---|
252 | itemPosition = itItem->getPosition(); |
---|
253 | |
---|
254 | WorldEntity* parent = itItem->getParent(); |
---|
255 | |
---|
256 | if (itItem->attachedToFigure_ == false && itemPosition.z < totalScreenShift_ - center_->getFieldDimension().y && parent == center_) |
---|
257 | { |
---|
258 | ObjectList<JumpItem>::iterator temp = itItem; |
---|
259 | ++ itItem; |
---|
260 | center_->detach(*temp); |
---|
261 | temp->destroy(); |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | ++ itItem; |
---|
266 | } |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | void Jump::cleanup() |
---|
271 | { |
---|
272 | camera = 0; |
---|
273 | } |
---|
274 | |
---|
275 | void Jump::start() |
---|
276 | { |
---|
277 | if (center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place. |
---|
278 | { |
---|
279 | if (figure_ == NULL) |
---|
280 | { |
---|
281 | figure_ = new JumpFigure(center_->getContext()); |
---|
282 | figure_->addTemplate(center_->getFigureTemplate()); |
---|
283 | figure_->InitializeAnimation(center_->getContext()); |
---|
284 | } |
---|
285 | |
---|
286 | center_->attach(figure_); |
---|
287 | figure_->setPosition(0, 0, 0); |
---|
288 | figure_->setFieldDimension(center_->getFieldDimension()); |
---|
289 | } |
---|
290 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
291 | { |
---|
292 | orxout(internal_error) << "Jump: No Centerpoint specified." << endl; |
---|
293 | GSLevel::startMainMenu(); |
---|
294 | return; |
---|
295 | } |
---|
296 | |
---|
297 | // Call start for the parent class. |
---|
298 | Deathmatch::start(); |
---|
299 | |
---|
300 | if (figure_ != NULL) |
---|
301 | { |
---|
302 | camera = figure_->getCamera(); |
---|
303 | } |
---|
304 | |
---|
305 | totalScreenShift_ = 0.0; |
---|
306 | screenShiftSinceLastUpdate_ = 0.0; |
---|
307 | sectionNumber_ = 0; |
---|
308 | adventureNumber_ = 0; |
---|
309 | |
---|
310 | addStartSection(); |
---|
311 | addSection(); |
---|
312 | addSection(); |
---|
313 | } |
---|
314 | |
---|
315 | void Jump::end() |
---|
316 | { |
---|
317 | cleanup(); |
---|
318 | GSLevel::startMainMenu(); |
---|
319 | |
---|
320 | Deathmatch::end(); |
---|
321 | } |
---|
322 | |
---|
323 | void Jump::spawnPlayer(PlayerInfo* player) |
---|
324 | { |
---|
325 | assert(player); |
---|
326 | |
---|
327 | if (figure_->getPlayer() == NULL) |
---|
328 | { |
---|
329 | player->startControl(figure_); |
---|
330 | players_[player].state_ = PlayerState::Alive; |
---|
331 | } |
---|
332 | } |
---|
333 | |
---|
334 | PlayerInfo* Jump::getPlayer() const |
---|
335 | { |
---|
336 | if (this->figure_ != NULL) |
---|
337 | { |
---|
338 | return this->figure_->getPlayer(); |
---|
339 | } |
---|
340 | else |
---|
341 | { |
---|
342 | return 0; |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | void Jump::addPlatform(JumpPlatform* newPlatform, std::string platformTemplate, float xPosition, float zPosition) |
---|
347 | { |
---|
348 | if (newPlatform != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 != NULL && center_ != NULL) |
---|
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 PlatformType |
---|
619 | { |
---|
620 | PLATFORM_EMPTY, PLATFORM_STATIC, PLATFORM_HMOVE, PLATFORM_VMOVE, PLATFORM_DISAPPEAR, PLATFORM_TIMER, PLATFORM_FAKE |
---|
621 | }; |
---|
622 | |
---|
623 | enum ItemType |
---|
624 | { |
---|
625 | ITEM_NOTHING, ITEM_SPRING, ITEM_PROPELLER, ITEM_ROCKET, ITEM_BOOTS, ITEM_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 = PLATFORM_EMPTY; |
---|
640 | matrix[i][j].done = false; |
---|
641 | } |
---|
642 | } |
---|
643 | PlatformType platformtype1; |
---|
644 | PlatformType platformtype2; |
---|
645 | ItemType itemType = ITEM_NOTHING; |
---|
646 | |
---|
647 | if (rand()%2 == 0) |
---|
648 | { |
---|
649 | itemType = ITEM_SPRING; |
---|
650 | } |
---|
651 | else if (rand()%2 == 0 && sectionNumber_ > 3) |
---|
652 | { |
---|
653 | switch(rand()%4) |
---|
654 | { |
---|
655 | case 0: |
---|
656 | itemType = ITEM_PROPELLER; |
---|
657 | break; |
---|
658 | case 1: |
---|
659 | itemType = ITEM_ROCKET; |
---|
660 | break; |
---|
661 | case 2: |
---|
662 | itemType = ITEM_BOOTS; |
---|
663 | break; |
---|
664 | case 3: |
---|
665 | itemType = ITEM_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 = PLATFORM_STATIC; |
---|
676 | platformtype2 = PLATFORM_STATIC; |
---|
677 | break; |
---|
678 | case 1: |
---|
679 | platformtype1 = PLATFORM_STATIC; |
---|
680 | platformtype2 = PLATFORM_STATIC; |
---|
681 | break; |
---|
682 | case 2: |
---|
683 | platformtype1 = PLATFORM_STATIC; |
---|
684 | platformtype2 = PLATFORM_HMOVE; |
---|
685 | break; |
---|
686 | case 3: |
---|
687 | platformtype1 = PLATFORM_STATIC; |
---|
688 | platformtype2 = PLATFORM_DISAPPEAR; |
---|
689 | break; |
---|
690 | case 4: |
---|
691 | platformtype1 = PLATFORM_STATIC; |
---|
692 | platformtype2 = PLATFORM_VMOVE; |
---|
693 | break; |
---|
694 | case 5: |
---|
695 | platformtype1 = PLATFORM_STATIC; |
---|
696 | platformtype2 = PLATFORM_TIMER; |
---|
697 | break; |
---|
698 | case 6: |
---|
699 | platformtype1 = PLATFORM_HMOVE; |
---|
700 | platformtype2 = PLATFORM_STATIC; |
---|
701 | break; |
---|
702 | case 7: |
---|
703 | platformtype1 = PLATFORM_HMOVE; |
---|
704 | platformtype2 = PLATFORM_HMOVE; |
---|
705 | break; |
---|
706 | case 8: |
---|
707 | platformtype1 = PLATFORM_HMOVE; |
---|
708 | platformtype2 = PLATFORM_HMOVE; |
---|
709 | break; |
---|
710 | case 9: |
---|
711 | platformtype1 = PLATFORM_HMOVE; |
---|
712 | platformtype2 = PLATFORM_DISAPPEAR; |
---|
713 | break; |
---|
714 | case 10: |
---|
715 | platformtype1 = PLATFORM_HMOVE; |
---|
716 | platformtype2 = PLATFORM_VMOVE; |
---|
717 | break; |
---|
718 | case 11: |
---|
719 | platformtype1 = PLATFORM_HMOVE; |
---|
720 | platformtype2 = PLATFORM_TIMER; |
---|
721 | break; |
---|
722 | case 12: |
---|
723 | platformtype1 = PLATFORM_DISAPPEAR; |
---|
724 | platformtype2 = PLATFORM_STATIC; |
---|
725 | break; |
---|
726 | case 13: |
---|
727 | platformtype1 = PLATFORM_DISAPPEAR; |
---|
728 | platformtype2 = PLATFORM_HMOVE; |
---|
729 | break; |
---|
730 | case 14: |
---|
731 | platformtype1 = PLATFORM_DISAPPEAR; |
---|
732 | platformtype2 = PLATFORM_DISAPPEAR; |
---|
733 | break; |
---|
734 | case 15: |
---|
735 | platformtype1 = PLATFORM_DISAPPEAR; |
---|
736 | platformtype2 = PLATFORM_DISAPPEAR; |
---|
737 | break; |
---|
738 | case 16: |
---|
739 | platformtype1 = PLATFORM_DISAPPEAR; |
---|
740 | platformtype2 = PLATFORM_VMOVE; |
---|
741 | break; |
---|
742 | case 17: |
---|
743 | platformtype1 = PLATFORM_DISAPPEAR; |
---|
744 | platformtype2 = PLATFORM_TIMER; |
---|
745 | break; |
---|
746 | case 18: |
---|
747 | platformtype1 = PLATFORM_VMOVE; |
---|
748 | platformtype2 = PLATFORM_STATIC; |
---|
749 | break; |
---|
750 | case 19: |
---|
751 | platformtype1 = PLATFORM_VMOVE; |
---|
752 | platformtype2 = PLATFORM_HMOVE; |
---|
753 | break; |
---|
754 | case 20: |
---|
755 | platformtype1 = PLATFORM_VMOVE; |
---|
756 | platformtype2 = PLATFORM_DISAPPEAR; |
---|
757 | break; |
---|
758 | case 21: |
---|
759 | platformtype1 = PLATFORM_VMOVE; |
---|
760 | platformtype2 = PLATFORM_VMOVE; |
---|
761 | break; |
---|
762 | case 22: |
---|
763 | platformtype1 = PLATFORM_VMOVE; |
---|
764 | platformtype2 = PLATFORM_VMOVE; |
---|
765 | break; |
---|
766 | case 23: |
---|
767 | platformtype1 = PLATFORM_VMOVE; |
---|
768 | platformtype2 = PLATFORM_TIMER; |
---|
769 | break; |
---|
770 | case 24: |
---|
771 | platformtype1 = PLATFORM_TIMER; |
---|
772 | platformtype2 = PLATFORM_STATIC; |
---|
773 | break; |
---|
774 | case 25: |
---|
775 | platformtype1 = PLATFORM_TIMER; |
---|
776 | platformtype2 = PLATFORM_HMOVE; |
---|
777 | break; |
---|
778 | case 26: |
---|
779 | platformtype1 = PLATFORM_TIMER; |
---|
780 | platformtype2 = PLATFORM_DISAPPEAR; |
---|
781 | break; |
---|
782 | case 27: |
---|
783 | platformtype1 = PLATFORM_TIMER; |
---|
784 | platformtype2 = PLATFORM_VMOVE; |
---|
785 | break; |
---|
786 | case 28: |
---|
787 | platformtype1 = PLATFORM_TIMER; |
---|
788 | platformtype2 = PLATFORM_TIMER; |
---|
789 | break; |
---|
790 | default: |
---|
791 | platformtype1 = PLATFORM_TIMER; |
---|
792 | platformtype2 = PLATFORM_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 = PLATFORM_EMPTY; |
---|
816 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_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 = PLATFORM_EMPTY; |
---|
825 | } |
---|
826 | else |
---|
827 | { |
---|
828 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; |
---|
829 | } |
---|
830 | } |
---|
831 | else if (sectionNumber_ > 10) |
---|
832 | { |
---|
833 | if (rand()%2 == 0) |
---|
834 | { |
---|
835 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; |
---|
836 | } |
---|
837 | else |
---|
838 | { |
---|
839 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; |
---|
840 | } |
---|
841 | if (rand()%2 == 0) |
---|
842 | { |
---|
843 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; |
---|
844 | } |
---|
845 | else |
---|
846 | { |
---|
847 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; |
---|
848 | } |
---|
849 | } |
---|
850 | else if (sectionNumber_ > 15) |
---|
851 | { |
---|
852 | if (rand()%2 == 0) |
---|
853 | { |
---|
854 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; |
---|
855 | } |
---|
856 | else |
---|
857 | { |
---|
858 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; |
---|
859 | } |
---|
860 | if (rand()%2 == 0) |
---|
861 | { |
---|
862 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; |
---|
863 | } |
---|
864 | else |
---|
865 | { |
---|
866 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_FAKE; |
---|
867 | } |
---|
868 | if (rand()%2 == 0) |
---|
869 | { |
---|
870 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_EMPTY; |
---|
871 | } |
---|
872 | else |
---|
873 | { |
---|
874 | matrix[rand()%numI][rand()%numJ].type = PLATFORM_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 PLATFORM_EMPTY: |
---|
898 | matrix[i][j].done = true; |
---|
899 | break; |
---|
900 | case PLATFORM_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 PLATFORM_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 PLATFORM_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 PLATFORM_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 PLATFORM_HMOVE: |
---|
925 | xVelocity = randomSpeed(); |
---|
926 | if (j <= numJ-3 && matrix[i][j+1].type == PLATFORM_HMOVE && matrix[i][j+2].type == PLATFORM_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 == PLATFORM_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 PLATFORM_VMOVE: |
---|
958 | zVelocity = randomSpeed(); |
---|
959 | if (i <= numI-3 && matrix[i+1][j].type == PLATFORM_VMOVE && matrix[i+2][j].type == PLATFORM_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 == PLATFORM_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 ITEM_ROCKET: |
---|
1009 | addRocket(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); |
---|
1010 | break; |
---|
1011 | case ITEM_PROPELLER: |
---|
1012 | addPropeller(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); |
---|
1013 | break; |
---|
1014 | case ITEM_BOOTS: |
---|
1015 | addBoots(0.0, randomPosition(sectionBegin, sectionBegin + sectionLength), -fieldWidth/2, fieldWidth/2, 0.0, 0.0, randomSpeed(), 0.0); |
---|
1016 | break; |
---|
1017 | case ITEM_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 ITEM_ROCKET: |
---|
1029 | addRocket(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); |
---|
1030 | break; |
---|
1031 | case ITEM_PROPELLER: |
---|
1032 | addPropeller(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); |
---|
1033 | break; |
---|
1034 | case ITEM_BOOTS: |
---|
1035 | addBoots(randomPosition(-fieldWidth/2, fieldWidth/2), sectionBegin + sectionLength/2, 0.0, 0.0, sectionBegin, sectionEnd, 0.0, randomSpeed()); |
---|
1036 | break; |
---|
1037 | case ITEM_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 ITEM_SPRING: |
---|
1054 | addSpring(itemPlatform); |
---|
1055 | break; |
---|
1056 | case ITEM_ROCKET: |
---|
1057 | addRocket(itemPlatform); |
---|
1058 | break; |
---|
1059 | case ITEM_PROPELLER: |
---|
1060 | addPropeller(itemPlatform); |
---|
1061 | break; |
---|
1062 | case ITEM_BOOTS: |
---|
1063 | addBoots(itemPlatform); |
---|
1064 | break; |
---|
1065 | case ITEM_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_ != NULL) |
---|
1273 | { |
---|
1274 | if (this->figure_->rocketActive_ != NULL) |
---|
1275 | { |
---|
1276 | return this->figure_->rocketActive_->getFuelState(); |
---|
1277 | } |
---|
1278 | else if (this->figure_->propellerActive_ != NULL) |
---|
1279 | { |
---|
1280 | return this->figure_->propellerActive_->getFuelState(); |
---|
1281 | } |
---|
1282 | else if (this->figure_->shieldActive_ != NULL) |
---|
1283 | { |
---|
1284 | return this->figure_->shieldActive_->getFuelState(); |
---|
1285 | } |
---|
1286 | else if (this->figure_->bootsActive_ != NULL) |
---|
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 | } |
---|