Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationFS14/src/modules/jump/Jump.cc @ 10078

Last change on this file since 10078 was 10078, checked in by smerkli, 10 years ago

Merged Jump minigame, tested, works.

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