Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/modules/dodgerace/DodgeRace.cc @ 10557

Last change on this file since 10557 was 10557, checked in by landauf, 9 years ago

cleanup: no need to pass/return WeakPtrs to/from functions. normal pointers are enough.

  • Property svn:eol-style set to native
File size: 6.4 KB
RevLine 
[10114]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 *      Florian Zinggeler
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file DodgeRace.cc
31    @brief Implementation of the DodgeRace class.
32*/
33
34#include "DodgeRace.h"
[10118]35#include "DodgeRaceShip.h" // Necessary for getPlayer function. Do NOT include this in Header!
[10152]36#include "DodgeRaceCube.h"
[10357]37#include "core/CoreIncludes.h"
[10114]38
39namespace orxonox
40{
[10118]41    RegisterUnloadableClass(DodgeRace);
[10114]42
43    DodgeRace::DodgeRace(Context* context) : Deathmatch(context)
44    {
45        RegisterObject(DodgeRace);
[10118]46        init();
[10114]47        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
[10118]48        this->center_ = 0;
[10166]49
50        this->setHUDTemplate("DodgeRaceHUD");
[10114]51    }
52
53    void DodgeRace::init()
54    {
55        bEndGame = false;
[10166]56        lives = 1;
[10114]57        level = 1;
58        point = 0;
59        bShowLevel = false;
60        multiplier = 1;
61        b_combo = false;
[10166]62        counter = 5000;
[10152]63        pattern = 1;
[10135]64        lastPosition = 0;
[10114]65        // spawn enemy every 3.5 seconds
66        //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this)));
[10118]67        comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this)));
[10114]68    }
69
70    void DodgeRace::levelUp()
71    {
[10117]72        level++;
[10124]73        if (getPlayer() != NULL)
[10114]74        {
75            for (int i = 0; i < 7; i++)
76            {
[10557]77                BigExplosion* chunk = new BigExplosion(this->center_->getContext());
[10114]78                chunk->setPosition(Vector3(600, 0, 100.f * i - 300));
79                chunk->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
80                chunk->setScale(20);
81            }
[10124]82        }
[10114]83        addPoints(multiplier * 42);
84        multiplier *= 2;
85        toggleShowLevel();
[10117]86        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this)));
[10114]87    }
88
[10135]89    void DodgeRace::tick(float dt)
90    {
[10236]91        if (getPlayer() != NULL)
92        {
93            currentPosition = getPlayer()->getWorldPosition().x;
94            counter = counter + (currentPosition - lastPosition);
95            lastPosition = currentPosition;
96            point = (int) currentPosition;
97            getPlayer()->speed = 830.0f - (point / 1000);
[10135]98
[10236]99            for(unsigned int i=0; i < cubeList.size();i++)
100            {
101                if(cubeList.at(i)->getPosition().x < currentPosition-3000)
102                {
103                    cubeList.at(i)->destroy();
104                    cubeList.erase(cubeList.begin()+i);
105                }
106            }
[10152]107
[10236]108            if(counter >= 3000)
109            {
110                counter = 0;
111                for(int i = 0; i<6; i++)
112                {
[10557]113                    DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext());
[10236]114                    cubeList.push_back(cube);
115                    switch(pattern)
116                    {
117                    case 1: cube->addTemplate("DodgeRaceCube01");
118                    break;
119                    case 2: cube->addTemplate("DodgeRaceCube02");
120                    break;
[10135]121
[10236]122                    }
[10152]123
[10236]124                    cube->setPosition(getPlayer()->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200)));
125                    //stEntity->setScale3D(50,50,50);
126                }
[10152]127
128
[10236]129                pattern %= 2;
130                pattern ++;
[10152]131
[10236]132            }
[10152]133
[10236]134        }
135        SUPER(DodgeRace, tick, dt);
[10135]136    }
137
[10557]138    DodgeRaceShip* DodgeRace::getPlayer()
[10114]139    {
140        if (player == NULL)
141        {
[10117]142            for (ObjectList<DodgeRaceShip>::iterator it = ObjectList<DodgeRaceShip>::begin(); it != ObjectList<DodgeRaceShip>::end(); ++it)
143            {
[10236]144                player = *it;
[10117]145            }
[10114]146        }
147        return player;
148    }
149
150    void DodgeRace::costLife()
151    {
[10236]152        //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this)));
153        lives = 0;
[10114]154    };
[10124]155
[10114]156    void DodgeRace::comboControll()
157    {
158        if (b_combo)
159            multiplier++;
160        // if no combo was performed before, reset multiplier
161        else
162            multiplier = 1;
163        b_combo = false;
164    }
165
166    void DodgeRace::start()
167    {
[10236]168        orxout() << "start" << endl;
[10114]169        init();
[10236]170        for(unsigned int i=0; i< cubeList.size();i++)
171        {
172            cubeList.at(i)->destroy();
173            cubeList.erase(cubeList.begin()+i);
[10152]174
[10236]175        }
[10152]176        cubeList.clear();
[10114]177        // Set variable to temporarily force the player to spawn.
[10166]178        this->bForceSpawn_ = false;
[10114]179
[10124]180        if (this->center_ == NULL)  // abandon mission!
[10114]181        {
182            orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl;
183            GSLevel::startMainMenu();
184            return;
[10124]185        }
[10114]186        // Call start for the parent class.
187        Deathmatch::start();
188    }
[10166]189
[10236]190    void DodgeRace::playerPreSpawn(PlayerInfo* player)
191    {
192        if(lives <= 0)
193        {
194            this->end();
195        }
[10166]196
[10236]197        // Reset all the cubes
198        /*
199        orxout() << "prespawn" << endl;
200        init();
201        for(int i=0; i< cubeList.size();i++)
202        {
203            cubeList.at(i)->destroy();
204            cubeList.erase(cubeList.begin()+i);
205        }
206        cubeList.clear();
[10166]207        lives = 1;
208        point = 0;
209        lastPosition = 0;
210        */
[10236]211    }
[10166]212
[10114]213    void DodgeRace::addPoints(int numPoints)
214    {
215        if (!bEndGame)
216        {
217            point += numPoints * multiplier;
218            b_combo = true;
219        }
220    }
[10124]221
[10114]222    void DodgeRace::end()
223    {
224        // DON'T CALL THIS!
225        //      Deathmatch::end();
226        // It will misteriously crash the game!
227        // Instead startMainMenu, this won't crash.
228        GSLevel::startMainMenu();
[10124]229    }
[10114]230}
Note: See TracBrowser for help on using the repository browser.