Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/jump/Jump.cc @ 11071

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

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