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 | * Fabian 'x3n' Landau |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file Jump.cc |
---|
31 | @brief Implementation of the Jump class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "Jump.h" |
---|
35 | |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "core/EventIncludes.h" |
---|
38 | #include "core/command/Executor.h" |
---|
39 | #include "core/config/ConfigValueIncludes.h" |
---|
40 | |
---|
41 | #include "gamestates/GSLevel.h" |
---|
42 | #include "chat/ChatManager.h" |
---|
43 | |
---|
44 | #include "JumpCenterpoint.h" |
---|
45 | #include "JumpPlatform.h" |
---|
46 | #include "JumpPlatformStatic.h" |
---|
47 | #include "JumpPlatformHMove.h" |
---|
48 | #include "JumpPlatformVMove.h" |
---|
49 | #include "JumpPlatformDisappear.h" |
---|
50 | #include "JumpPlatformTimer.h" |
---|
51 | #include "JumpPlatformFake.h" |
---|
52 | #include "JumpProjectile.h" |
---|
53 | #include "JumpEnemy.h" |
---|
54 | #include "JumpFigure.h" |
---|
55 | |
---|
56 | #include "infos/PlayerInfo.h" |
---|
57 | |
---|
58 | namespace orxonox |
---|
59 | { |
---|
60 | // Events to allow to react to scoring of a player, in the level-file. |
---|
61 | CreateEventName(JumpCenterpoint, right); |
---|
62 | CreateEventName(JumpCenterpoint, left); |
---|
63 | |
---|
64 | RegisterUnloadableClass(Jump); |
---|
65 | |
---|
66 | /** |
---|
67 | @brief |
---|
68 | Constructor. Registers and initializes the object. |
---|
69 | */ |
---|
70 | Jump::Jump(Context* context) : Deathmatch(context) |
---|
71 | { |
---|
72 | RegisterObject(Jump); |
---|
73 | |
---|
74 | this->center_ = 0; |
---|
75 | this->figure_ = 0; |
---|
76 | this->camera = 0; |
---|
77 | this->fakeAdded_ = false; |
---|
78 | |
---|
79 | this->setHUDTemplate("JumpHUD"); |
---|
80 | |
---|
81 | // Pre-set the timer, but don't start it yet. |
---|
82 | this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&Jump::startBall, this))); |
---|
83 | this->starttimer_.stopTimer(); |
---|
84 | |
---|
85 | this->scoreLimit_ = 10; |
---|
86 | this->setConfigValues(); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | @brief |
---|
91 | Destructor. Cleans up, if initialized. |
---|
92 | */ |
---|
93 | Jump::~Jump() |
---|
94 | { |
---|
95 | if (this->isInitialized()) |
---|
96 | { |
---|
97 | this->cleanup(); |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | void Jump::tick(float dt) |
---|
102 | { |
---|
103 | SUPER(Jump, tick, dt); |
---|
104 | |
---|
105 | if (figure_ != NULL) |
---|
106 | { |
---|
107 | Vector3 figurePosition = figure_->getPosition(); |
---|
108 | Vector3 figureVelocity = figure_->getVelocity(); |
---|
109 | |
---|
110 | if (figurePosition.z > totalScreenShift) |
---|
111 | { |
---|
112 | screenShiftSinceLastUpdate += figurePosition.z - totalScreenShift; |
---|
113 | totalScreenShift = figurePosition.z; |
---|
114 | |
---|
115 | // Falls noetig neue Platformen im neuen Bereich einfuegen |
---|
116 | if (screenShiftSinceLastUpdate > center_->getSectionLength()) |
---|
117 | { |
---|
118 | screenShiftSinceLastUpdate -= center_->getSectionLength(); |
---|
119 | addSection(); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | // Spiel verloren wegen Ansturz? |
---|
124 | if (figurePosition.z < totalScreenShift - center_->getFieldDimension().y && figureVelocity.z < 0) |
---|
125 | { |
---|
126 | end(); |
---|
127 | } |
---|
128 | |
---|
129 | // Schiessen |
---|
130 | if (figure_->fireSignal) |
---|
131 | { |
---|
132 | figure_->fireSignal = false; |
---|
133 | addProjectile(figurePosition.x, figurePosition.z, 0.0, 150.0); |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | if (this->camera != NULL) |
---|
138 | { |
---|
139 | Vector3 cameraPosition = Vector3(0, totalScreenShift, 0); |
---|
140 | camera->setPosition(cameraPosition); |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | orxout() << "No camera found." << endl; |
---|
145 | //camera = figure_->getCamera(); |
---|
146 | } |
---|
147 | } |
---|
148 | else |
---|
149 | { |
---|
150 | //orxout() << "No figure found." << endl; |
---|
151 | } |
---|
152 | |
---|
153 | // Platformen, die zu weit unten sind entfernen |
---|
154 | ObjectList<JumpPlatform>::iterator beginPlatform = ObjectList<JumpPlatform>::begin(); |
---|
155 | ObjectList<JumpPlatform>::iterator endPlatform = ObjectList<JumpPlatform>::end(); |
---|
156 | ObjectList<JumpPlatform>::iterator itPlatform = beginPlatform; |
---|
157 | Vector3 platformPosition; |
---|
158 | |
---|
159 | while (itPlatform != endPlatform) |
---|
160 | { |
---|
161 | platformPosition = itPlatform->getPosition(); |
---|
162 | if (platformPosition.z < totalScreenShift - center_->getFieldDimension().y) |
---|
163 | { |
---|
164 | ObjectList<JumpPlatform>::iterator temp = itPlatform; |
---|
165 | ++ itPlatform; |
---|
166 | center_->detach(*temp); |
---|
167 | temp->destroy(); |
---|
168 | } |
---|
169 | else |
---|
170 | { |
---|
171 | ++ itPlatform; |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | // DAS GEHT NICHT!!! it++ funktioniert nicht, falls eine Platform geloescht wurde -> Segmentation Error |
---|
176 | /* |
---|
177 | for (ObjectList<JumpPlatformDisappear>::iterator it = ObjectList<JumpPlatformDisappear>::begin(); orxout() << "E" << endl, it != ObjectList<JumpPlatformDisappear>::end(); orxout() << "F" << endl, ++it) |
---|
178 | { |
---|
179 | if (!it->isActive()) |
---|
180 | { |
---|
181 | // Entferne Platform |
---|
182 | center_->detach(*it); |
---|
183 | it->destroy(); |
---|
184 | } |
---|
185 | } |
---|
186 | */ |
---|
187 | |
---|
188 | // Deaktivierte Platformen entfernen |
---|
189 | ObjectList<JumpPlatformDisappear>::iterator beginDisappear = ObjectList<JumpPlatformDisappear>::begin(); |
---|
190 | ObjectList<JumpPlatformDisappear>::iterator endDisappear = ObjectList<JumpPlatformDisappear>::end(); |
---|
191 | ObjectList<JumpPlatformDisappear>::iterator itDisappear = beginDisappear; |
---|
192 | |
---|
193 | while (itDisappear != endDisappear) |
---|
194 | { |
---|
195 | if (!itDisappear->isActive()) |
---|
196 | { |
---|
197 | ObjectList<JumpPlatformDisappear>::iterator temp = itDisappear; |
---|
198 | ++ itDisappear; |
---|
199 | center_->detach(*temp); |
---|
200 | temp->destroy(); |
---|
201 | } |
---|
202 | else |
---|
203 | { |
---|
204 | ++ itDisappear; |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | // Abgelaufene Timer-Platformen entfernen |
---|
209 | ObjectList<JumpPlatformTimer>::iterator beginTimer = ObjectList<JumpPlatformTimer>::begin(); |
---|
210 | ObjectList<JumpPlatformTimer>::iterator endTimer = ObjectList<JumpPlatformTimer>::end(); |
---|
211 | ObjectList<JumpPlatformTimer>::iterator itTimer = beginTimer; |
---|
212 | |
---|
213 | while (itTimer != endTimer) |
---|
214 | { |
---|
215 | if (!itTimer->isActive()) |
---|
216 | { |
---|
217 | ObjectList<JumpPlatformTimer>::iterator temp = itTimer; |
---|
218 | ++ itTimer; |
---|
219 | center_->detach(*temp); |
---|
220 | temp->destroy(); |
---|
221 | } |
---|
222 | else |
---|
223 | { |
---|
224 | ++ itTimer; |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | // Projektile, die zu weit oben sind entfernen |
---|
229 | ObjectList<JumpProjectile>::iterator beginProjectile = ObjectList<JumpProjectile>::begin(); |
---|
230 | ObjectList<JumpProjectile>::iterator endProjectile = ObjectList<JumpProjectile>::end(); |
---|
231 | ObjectList<JumpProjectile>::iterator itProjectile = beginProjectile; |
---|
232 | Vector3 projectilePosition; |
---|
233 | |
---|
234 | while (itProjectile != endProjectile) |
---|
235 | { |
---|
236 | projectilePosition = itProjectile->getPosition(); |
---|
237 | if (projectilePosition.z > totalScreenShift + 5*center_->getFieldDimension().y) |
---|
238 | { |
---|
239 | ObjectList<JumpProjectile>::iterator temp = itProjectile; |
---|
240 | ++ itProjectile; |
---|
241 | center_->detach(*temp); |
---|
242 | temp->destroy(); |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | ++ itProjectile; |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | } |
---|
253 | |
---|
254 | void Jump::setConfigValues() |
---|
255 | { |
---|
256 | SetConfigValue(scoreLimit_, 10).description("The player first reaching those points wins."); |
---|
257 | } |
---|
258 | |
---|
259 | /** |
---|
260 | @brief |
---|
261 | Cleans up the Gametype by destroying the ball and the bats. |
---|
262 | */ |
---|
263 | void Jump::cleanup() |
---|
264 | { |
---|
265 | if (this->figure_ != NULL) |
---|
266 | { |
---|
267 | //this->figure_->destroy(); |
---|
268 | //this->figure_ = 0; |
---|
269 | } |
---|
270 | this->camera = 0; |
---|
271 | } |
---|
272 | |
---|
273 | /** |
---|
274 | @brief |
---|
275 | Starts the Jump minigame. |
---|
276 | */ |
---|
277 | void Jump::start() |
---|
278 | { |
---|
279 | if (this->center_ != NULL) // There needs to be a JumpCenterpoint, i.e. the area the game takes place. |
---|
280 | { |
---|
281 | |
---|
282 | |
---|
283 | // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. |
---|
284 | /*this->center_->attach(this->ball_); |
---|
285 | this->ball_->setPosition(0, 0, 0); |
---|
286 | this->ball_->setFieldDimension(this->center_->getFieldDimension()); |
---|
287 | |
---|
288 | // Set the bats for the ball. |
---|
289 | this->ball_->setFigure(this->figure_); |
---|
290 | */ |
---|
291 | |
---|
292 | // If one of the bats is missing, create it. Apply the template for the bats as specified in the centerpoint. |
---|
293 | if (this->figure_ == NULL) |
---|
294 | { |
---|
295 | this->figure_ = new JumpFigure(this->center_->getContext()); |
---|
296 | this->figure_->addTemplate(this->center_->getFigureTemplate()); |
---|
297 | } |
---|
298 | |
---|
299 | // Attach the bats to the centerpoint and set the parameters as specified in the centerpoint, the bats are attached to. |
---|
300 | this->center_->attach(this->figure_); |
---|
301 | this->figure_->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); |
---|
302 | this->figure_->setFieldDimension(this->center_->getFieldDimension()); |
---|
303 | } |
---|
304 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
305 | { |
---|
306 | orxout(internal_error) << "Jump: No Centerpoint specified." << endl; |
---|
307 | GSLevel::startMainMenu(); |
---|
308 | return; |
---|
309 | } |
---|
310 | |
---|
311 | // Start the timer. After it has expired the ball is started. |
---|
312 | this->starttimer_.startTimer(); |
---|
313 | |
---|
314 | // Set variable to temporarily force the player to spawn. |
---|
315 | bool temp = this->bForceSpawn_; |
---|
316 | this->bForceSpawn_ = true; |
---|
317 | |
---|
318 | // Call start for the parent class. |
---|
319 | Deathmatch::start(); |
---|
320 | |
---|
321 | // Reset the variable. |
---|
322 | this->bForceSpawn_ = temp; |
---|
323 | |
---|
324 | if (this->figure_ != NULL) |
---|
325 | { |
---|
326 | this->camera = this->figure_->getCamera(); |
---|
327 | } |
---|
328 | |
---|
329 | totalScreenShift = 0.0; |
---|
330 | screenShiftSinceLastUpdate = 0.0; |
---|
331 | sectionNumber = 0; |
---|
332 | |
---|
333 | addStartSection(); |
---|
334 | addSection(); |
---|
335 | addSection(); |
---|
336 | } |
---|
337 | |
---|
338 | /** |
---|
339 | @brief |
---|
340 | Ends the Jump minigame. |
---|
341 | */ |
---|
342 | void Jump::end() |
---|
343 | { |
---|
344 | cleanup(); |
---|
345 | GSLevel::startMainMenu(); |
---|
346 | |
---|
347 | // Call end for the parent class. |
---|
348 | Deathmatch::end(); |
---|
349 | } |
---|
350 | |
---|
351 | /** |
---|
352 | @brief |
---|
353 | Spawns players, and fills the rest up with bots. |
---|
354 | */ |
---|
355 | void Jump::spawnPlayersIfRequested() |
---|
356 | { |
---|
357 | |
---|
358 | // first spawn human players to assign always the left bat to the player in singleplayer |
---|
359 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
360 | if (it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_)) |
---|
361 | this->spawnPlayer(it->first); |
---|
362 | // now spawn bots |
---|
363 | /* |
---|
364 | for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it) |
---|
365 | if (!it->first->isHumanPlayer() && (it->first->isReadyToSpawn() || this->bForceSpawn_)) |
---|
366 | this->spawnPlayer(it->first); |
---|
367 | */ |
---|
368 | } |
---|
369 | |
---|
370 | /** |
---|
371 | @brief |
---|
372 | Spawns the input player. |
---|
373 | @param player |
---|
374 | The player to be spawned. |
---|
375 | */ |
---|
376 | void Jump::spawnPlayer(PlayerInfo* player) |
---|
377 | { |
---|
378 | assert(player); |
---|
379 | |
---|
380 | // If the first (left) bat has no player. |
---|
381 | if (this->figure_->getPlayer() == NULL) |
---|
382 | { |
---|
383 | player->startControl(this->figure_); |
---|
384 | this->players_[player].state_ = PlayerState::Alive; |
---|
385 | } |
---|
386 | // If both bats are taken. |
---|
387 | else |
---|
388 | { |
---|
389 | return; |
---|
390 | } |
---|
391 | |
---|
392 | } |
---|
393 | |
---|
394 | /** |
---|
395 | @brief |
---|
396 | Is called when the player scored. |
---|
397 | */ |
---|
398 | void Jump::playerScored(PlayerInfo* player, int score) |
---|
399 | { |
---|
400 | /* |
---|
401 | Deathmatch::playerScored(player, score); |
---|
402 | if (this->center_ != NULL) // If there is a centerpoint. |
---|
403 | { |
---|
404 | // Fire an event for the player that has scored, to be able to react to it in the level, e.g. by displaying fireworks. |
---|
405 | if (player == this->getRightPlayer()) |
---|
406 | this->center_->fireEvent(FireEventName(JumpCenterpoint, right)); |
---|
407 | else if (player == this->getLeftPlayer()) |
---|
408 | this->center_->fireEvent(FireEventName(JumpCenterpoint, left)); |
---|
409 | |
---|
410 | // Also announce, that the player has scored. |
---|
411 | if (player != NULL) |
---|
412 | this->gtinfo_->sendAnnounceMessage(player->getName() + " scored"); |
---|
413 | } |
---|
414 | |
---|
415 | // If there is a ball present, reset its position, velocity and acceleration. |
---|
416 | if (this->ball_ != NULL) |
---|
417 | { |
---|
418 | this->ball_->setPosition(Vector3::ZERO); |
---|
419 | this->ball_->setVelocity(Vector3::ZERO); |
---|
420 | this->ball_->setAcceleration(Vector3::ZERO); |
---|
421 | this->ball_->setSpeed(0); |
---|
422 | } |
---|
423 | |
---|
424 | // If there are bats reset them to the middle position. |
---|
425 | if (this->figure_[0] != NULL && this->figure_[1] != NULL) |
---|
426 | { |
---|
427 | this->figure_[0]->setPosition(-this->center_->getFieldDimension().x / 2, 0, 0); |
---|
428 | this->figure_[1]->setPosition( this->center_->getFieldDimension().x / 2, 0, 0); |
---|
429 | } |
---|
430 | |
---|
431 | // If a player gets enough points, he won the game -> end of game |
---|
432 | PlayerInfo* winningPlayer = NULL; |
---|
433 | if (this->getLeftPlayer() && this->getScore(this->getLeftPlayer()) >= scoreLimit_) |
---|
434 | winningPlayer = this->getLeftPlayer(); |
---|
435 | else if (this->getRightPlayer() && this->getScore(this->getRightPlayer()) >= scoreLimit_) |
---|
436 | winningPlayer = getLeftPlayerthis->getRightPlayer(); |
---|
437 | |
---|
438 | if (winningPlayer) |
---|
439 | { |
---|
440 | ChatManager::message(winningPlayer->getName() + " has won!"); |
---|
441 | this->end(); |
---|
442 | } |
---|
443 | |
---|
444 | // Restart the timer to start the ball. |
---|
445 | this->starttimer_.startTimer(); |
---|
446 | |
---|
447 | */ |
---|
448 | } |
---|
449 | |
---|
450 | /** |
---|
451 | @brief |
---|
452 | Starts the ball with some default speed. |
---|
453 | */ |
---|
454 | void Jump::startBall() |
---|
455 | { |
---|
456 | |
---|
457 | } |
---|
458 | |
---|
459 | /** |
---|
460 | @brief |
---|
461 | Get the left player. |
---|
462 | @return |
---|
463 | Returns a pointer to the player playing on the left. If there is no left player, NULL is returned. |
---|
464 | */ |
---|
465 | PlayerInfo* Jump::getPlayer() const |
---|
466 | { |
---|
467 | if (this->figure_ != NULL) |
---|
468 | { |
---|
469 | return this->figure_->getPlayer(); |
---|
470 | } |
---|
471 | else |
---|
472 | { |
---|
473 | return 0; |
---|
474 | } |
---|
475 | } |
---|
476 | |
---|
477 | void Jump::addPlatform(JumpPlatform* newPlatform, std::string platformTemplate, float xPosition, float zPosition) |
---|
478 | { |
---|
479 | if (newPlatform != NULL && center_ != NULL) |
---|
480 | { |
---|
481 | newPlatform->addTemplate(platformTemplate); |
---|
482 | newPlatform->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
483 | newPlatform->setFieldDimension(center_->getFieldDimension()); |
---|
484 | newPlatform->setFigure(this->figure_); |
---|
485 | center_->attach(newPlatform); |
---|
486 | } |
---|
487 | } |
---|
488 | |
---|
489 | void Jump::addPlatformStatic(float xPosition, float zPosition) |
---|
490 | { |
---|
491 | if (fakeAdded_ == false && rand()%5 == 0) |
---|
492 | { |
---|
493 | addPlatformFake(xPosition, zPosition); |
---|
494 | } |
---|
495 | else |
---|
496 | { |
---|
497 | JumpPlatformStatic* newPlatform = new JumpPlatformStatic(center_->getContext()); |
---|
498 | addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, zPosition); |
---|
499 | } |
---|
500 | } |
---|
501 | |
---|
502 | void Jump::addPlatformHMove(float xPosition, float zPosition, float leftBoundary, float rightBoundary, float speed) |
---|
503 | { |
---|
504 | JumpPlatformHMove* newPlatform = new JumpPlatformHMove(center_->getContext()); |
---|
505 | newPlatform->setProperties(leftBoundary, rightBoundary, speed); |
---|
506 | addPlatform(newPlatform, center_->getPlatformHMoveTemplate(), xPosition, zPosition); |
---|
507 | } |
---|
508 | |
---|
509 | void Jump::addPlatformVMove(float xPosition, float zPosition, float lowerBoundary, float upperBoundary, float speed) |
---|
510 | { |
---|
511 | JumpPlatformVMove* newPlatform = new JumpPlatformVMove(center_->getContext()); |
---|
512 | newPlatform->setProperties(lowerBoundary, upperBoundary, speed); |
---|
513 | addPlatform(newPlatform, center_->getPlatformVMoveTemplate(), xPosition, zPosition); |
---|
514 | } |
---|
515 | |
---|
516 | void Jump::addPlatformDisappear(float xPosition, float zPosition) |
---|
517 | { |
---|
518 | JumpPlatformDisappear* newPlatform = new JumpPlatformDisappear(center_->getContext()); |
---|
519 | newPlatform->setProperties(true); |
---|
520 | addPlatform(newPlatform, center_->getPlatformDisappearTemplate(), xPosition, zPosition); |
---|
521 | } |
---|
522 | |
---|
523 | void Jump::addPlatformTimer(float xPosition, float zPosition, float time, float variance) |
---|
524 | { |
---|
525 | float additionalTime = (float)(rand()%100)/(100*variance) - variance/2; |
---|
526 | |
---|
527 | JumpPlatformTimer* newPlatform = new JumpPlatformTimer(center_->getContext()); |
---|
528 | newPlatform->setProperties(time + additionalTime); |
---|
529 | addPlatform(newPlatform, center_->getPlatformTimerTemplate(), xPosition, zPosition); |
---|
530 | } |
---|
531 | |
---|
532 | void Jump::addPlatformFake(float xPosition, float zPosition) |
---|
533 | { |
---|
534 | fakeAdded_ = true; |
---|
535 | |
---|
536 | JumpPlatformFake* newPlatform = new JumpPlatformFake(center_->getContext()); |
---|
537 | addPlatform(newPlatform, center_->getPlatformFakeTemplate(), xPosition, zPosition); |
---|
538 | newPlatform->setAngularVelocity(Vector3(0, 0, 2.0)); |
---|
539 | } |
---|
540 | |
---|
541 | |
---|
542 | void Jump::addProjectile(float xPosition, float zPosition, float xVelocity, float zVelocity) |
---|
543 | { |
---|
544 | JumpProjectile* newProjectile = new JumpProjectile(center_->getContext()); |
---|
545 | if (newProjectile != NULL && center_ != NULL) |
---|
546 | { |
---|
547 | newProjectile->addTemplate(center_->getProjectileTemplate()); |
---|
548 | newProjectile->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
549 | newProjectile->setVelocity(Vector3(xVelocity, 0.0, zVelocity)); |
---|
550 | newProjectile->setFieldDimension(center_->getFieldDimension()); |
---|
551 | newProjectile->setFigure(this->figure_); |
---|
552 | center_->attach(newProjectile); |
---|
553 | } |
---|
554 | } |
---|
555 | |
---|
556 | void Jump::addEnemy1(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 | newEnemy->addTemplate(center_->getEnemy1Template()); |
---|
562 | newEnemy->setPosition(Vector3(xPosition, 0.0, zPosition)); |
---|
563 | newEnemy->setProperties(leftBoundary, rightBoundary, lowerBoundary, upperBoundary, xVelocity, zVelocity); |
---|
564 | newEnemy->setFieldDimension(center_->getFieldDimension()); |
---|
565 | newEnemy->setFigure(this->figure_); |
---|
566 | center_->attach(newEnemy); |
---|
567 | } |
---|
568 | } |
---|
569 | |
---|
570 | void Jump::addStartSection() |
---|
571 | { |
---|
572 | JumpPlatform* newPlatform; |
---|
573 | |
---|
574 | float sectionLength = center_->getSectionLength(); |
---|
575 | float platformLength = center_->getPlatformLength(); |
---|
576 | |
---|
577 | for (float xPosition = -center_->getFieldDimension().x; xPosition <= center_->getFieldDimension().x; xPosition += platformLength) |
---|
578 | { |
---|
579 | newPlatform = new JumpPlatformStatic(center_->getContext()); |
---|
580 | addPlatform(newPlatform, center_->getPlatformStaticTemplate(), xPosition, -0.05*sectionLength); |
---|
581 | } |
---|
582 | } |
---|
583 | |
---|
584 | void Jump::addSection() |
---|
585 | { |
---|
586 | float fieldWidth = center_->getFieldDimension().x; |
---|
587 | float sectionLength = center_->getSectionLength(); |
---|
588 | float platformLength = center_->getPlatformLength(); |
---|
589 | |
---|
590 | float sectionBegin = sectionNumber * sectionLength; |
---|
591 | float sectionEnd = (1.0 + sectionNumber) * sectionLength; |
---|
592 | |
---|
593 | int randPos1 = rand()%10; |
---|
594 | int randPos2 = rand()%10; |
---|
595 | int randPos3 = rand()%10; |
---|
596 | int randPos4 = rand()%10; |
---|
597 | |
---|
598 | if (rand()%5 == 0) |
---|
599 | { |
---|
600 | addEnemy1(randomXPosition(), sectionBegin + sectionLength/10, -fieldWidth, fieldWidth, sectionBegin + sectionLength/10, sectionBegin + sectionLength/10, 5.0, 0.0); |
---|
601 | } |
---|
602 | |
---|
603 | switch (rand()%12) |
---|
604 | { |
---|
605 | case 0: |
---|
606 | // Doppelt statisch |
---|
607 | for (int i = 0; i < 10; ++i) |
---|
608 | { |
---|
609 | for (int j = 0; j < 2; ++j) |
---|
610 | { |
---|
611 | addPlatformStatic(randomXPosition(2, j), sectionBegin + i*sectionLength/10); |
---|
612 | } |
---|
613 | } |
---|
614 | break; |
---|
615 | case 1: |
---|
616 | // Dreifach statisch |
---|
617 | for (int i = 0; i < 10; ++i) |
---|
618 | { |
---|
619 | for (int j = 0; j < 3; ++j) |
---|
620 | { |
---|
621 | addPlatformStatic(randomXPosition(3, j), sectionBegin + i*sectionLength/10); |
---|
622 | } |
---|
623 | } |
---|
624 | break; |
---|
625 | case 2: |
---|
626 | // statisch mit 1 horizontal |
---|
627 | for (int i = 0; i < 10; ++i) |
---|
628 | { |
---|
629 | if (i == randPos1) |
---|
630 | { |
---|
631 | addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10); |
---|
636 | } |
---|
637 | } |
---|
638 | break; |
---|
639 | case 3: |
---|
640 | // statisch mit 2 horizontal |
---|
641 | for (int i = 0; i < 10; ++i) |
---|
642 | { |
---|
643 | if (i == randPos1 || i == randPos2) |
---|
644 | { |
---|
645 | addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10); |
---|
650 | } |
---|
651 | } |
---|
652 | break; |
---|
653 | case 4: |
---|
654 | // statisch mit 3 horizontal |
---|
655 | for (int i = 0; i < 10; ++i) |
---|
656 | { |
---|
657 | if (i == randPos1 || i == randPos2 || i == randPos3) |
---|
658 | { |
---|
659 | addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); |
---|
660 | } |
---|
661 | else |
---|
662 | { |
---|
663 | addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10); |
---|
664 | } |
---|
665 | } |
---|
666 | break; |
---|
667 | case 5: |
---|
668 | // statisch mit 4 horizontal |
---|
669 | for (int i = 0; i < 10; ++i) |
---|
670 | { |
---|
671 | if (i == randPos1 || i == randPos2 || i == randPos3 || i == randPos4) |
---|
672 | { |
---|
673 | addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); |
---|
674 | } |
---|
675 | else |
---|
676 | { |
---|
677 | addPlatformStatic(randomXPosition(), sectionBegin + i*sectionLength/10); |
---|
678 | } |
---|
679 | } |
---|
680 | break; |
---|
681 | // Einfach horizontal |
---|
682 | case 6: |
---|
683 | for (int i = 0; i < 10; ++i) |
---|
684 | { |
---|
685 | addPlatformHMove(randomXPosition(), sectionBegin + i*sectionLength/10, -fieldWidth, fieldWidth, 30.0); |
---|
686 | } |
---|
687 | break; |
---|
688 | // Doppelt horizontal |
---|
689 | case 7: |
---|
690 | for (int i = 0; i < 10; ++i) |
---|
691 | { |
---|
692 | float mediumPos = randomXPosition(3, 1); |
---|
693 | addPlatformHMove(randomXPosition(3, 0), sectionBegin + i*sectionLength/10, -fieldWidth, mediumPos - platformLength/2, 30.0); |
---|
694 | addPlatformHMove(randomXPosition(3, 2), sectionBegin + i*sectionLength/10, mediumPos+platformLength/2, fieldWidth, 30.0); |
---|
695 | } |
---|
696 | break; |
---|
697 | // Einfach vertikal |
---|
698 | case 8: |
---|
699 | for (int i = 0; i < 7; ++i) |
---|
700 | { |
---|
701 | addPlatformVMove(-fieldWidth + i*fieldWidth*2/10, randomYPosition(sectionBegin, sectionEnd), sectionBegin, sectionEnd, 20.0); |
---|
702 | } |
---|
703 | break; |
---|
704 | // Doppelt vertikal |
---|
705 | case 9: |
---|
706 | for (int i = 0; i < 14; ++i) |
---|
707 | { |
---|
708 | addPlatformVMove(-fieldWidth + i*fieldWidth*2/10, randomYPosition(sectionBegin, sectionEnd), sectionBegin, sectionEnd, 20.0); |
---|
709 | } |
---|
710 | break; |
---|
711 | // Doppelt verschwindend |
---|
712 | case 10: |
---|
713 | for (int i = 0; i < 10; ++i) |
---|
714 | { |
---|
715 | for (int j = 0; j < 2; ++j) |
---|
716 | { |
---|
717 | addPlatformDisappear(randomXPosition(2, j), randomYPosition(sectionBegin, sectionEnd)); |
---|
718 | } |
---|
719 | } |
---|
720 | break; |
---|
721 | // Doppelt Timer |
---|
722 | case 11: |
---|
723 | for (int i = 0; i < 10; ++i) |
---|
724 | { |
---|
725 | for (int j = 0; j < 2; ++j) |
---|
726 | { |
---|
727 | addPlatformTimer(randomXPosition(2, j), randomYPosition(sectionBegin, sectionEnd), 6.0, 1.5); |
---|
728 | } |
---|
729 | } |
---|
730 | break; |
---|
731 | } |
---|
732 | orxout() << "new section added with number "<< sectionNumber << endl; |
---|
733 | |
---|
734 | fakeAdded_ = false; |
---|
735 | |
---|
736 | ++ sectionNumber; |
---|
737 | } |
---|
738 | |
---|
739 | float Jump::randomXPosition() |
---|
740 | { |
---|
741 | float fieldWidth = center_->getFieldDimension().x; |
---|
742 | |
---|
743 | return (float)(rand()%(2*(int)fieldWidth)) - fieldWidth; |
---|
744 | } |
---|
745 | |
---|
746 | float Jump::randomXPosition(int totalColumns, int culomn) |
---|
747 | { |
---|
748 | float fieldWidth = center_->getFieldDimension().x; |
---|
749 | |
---|
750 | float width = 2*fieldWidth/totalColumns; |
---|
751 | float leftBound = culomn*width-fieldWidth; |
---|
752 | float platformLength = center_->getPlatformLength(); |
---|
753 | |
---|
754 | return (float)(rand()%(int)(width-platformLength)) + leftBound + platformLength/2; |
---|
755 | } |
---|
756 | |
---|
757 | float Jump::randomYPosition(float lowerBoundary, float upperBoundary) |
---|
758 | { |
---|
759 | return (float)(rand()%(int)(100*(upperBoundary - lowerBoundary)))/100 + lowerBoundary; |
---|
760 | } |
---|
761 | |
---|
762 | int Jump::getScore(PlayerInfo* player) const |
---|
763 | { |
---|
764 | return sectionNumber - 2; |
---|
765 | } |
---|
766 | |
---|
767 | } |
---|