Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10574 was 10574, checked in by landauf, 10 years ago

removed some init() functions, integrated them directly into the constructor (and it's not necessary to call init() again when a gametype starts)

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