Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/surfaceraceHS14/src/modules/dodgerace2/DodgeRace.cc @ 10121

Last change on this file since 10121 was 10118, checked in by sriedel, 10 years ago

Working atm. including function after function.

File size: 5.1 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
37namespace orxonox
38{
39    RegisterUnloadableClass(DodgeRace);
40
41    DodgeRace::DodgeRace(Context* context) : Deathmatch(context)
42    {
43        RegisterObject(DodgeRace);
44        init();
45        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
46        this->center_ = 0;
47        /*
48        this->setHUDTemplate("DodgeRaceHUD"); // !!!!!!!!!!!!!!!        change later*/
49    }
50
51    void DodgeRace::init()
52    {
53        bEndGame = false;
54        lives = 3;
55        level = 1;
56        point = 0;
57        bShowLevel = false;
58        multiplier = 1;
59        b_combo = false;
60
61        // spawn enemy every 3.5 seconds
62        //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this)));
63        comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this)));
64    }
65
66    void DodgeRace::levelUp()
67    {
68        level++;
69       /* if (getPlayer() != NULL)
70        {
71            for (int i = 0; i < 7; i++)
72            {
73                WeakPtr<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    WeakPtr<DodgeRaceShip> DodgeRace::getPlayer()
86    {
87        if (player == NULL)
88        {
89            for (ObjectList<DodgeRaceShip>::iterator it = ObjectList<DodgeRaceShip>::begin(); it != ObjectList<DodgeRaceShip>::end(); ++it)
90            {
91                player = *it;
92            }
93        }
94        return player;
95    }
96/*
97    void DodgeRace::spawnEnemy()
98    {
99        if (getPlayer() == NULL)
100            return;
101
102        for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)
103        {
104            WeakPtr<DodgeRaceEnemy> newPawn;
105            if (rand() % 42/(1 + level*level) == 0)
106            {
107                newPawn = new DodgeRaceEnemyShooter(this->center_->getContext());
108                newPawn->addTemplate("enemyinvadershooter");
109            }
110            else
111            {
112                newPawn = new DodgeRaceEnemy(this->center_->getContext());
113                newPawn->addTemplate("enemyinvader");
114            }
115            newPawn->setPlayer(player);
116            newPawn->level = level;
117            // spawn enemy at random points in front of player.
118            newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));
119        }
120    }
121
122    void DodgeRace::costLife()
123    {
124        lives--;
125        multiplier = 1;
126        // end the game in 30 seconds.
127       // if (lives <= 0)
128         //   enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&DodgeRace::end, this)));
129    };
130*/
131    void DodgeRace::comboControll()
132    {
133        if (b_combo)
134            multiplier++;
135        // if no combo was performed before, reset multiplier
136        else
137            multiplier = 1;
138        b_combo = false;
139    }
140
141    void DodgeRace::start()
142    {
143        init();
144        // Set variable to temporarily force the player to spawn.
145        this->bForceSpawn_ = true;
146
147        /*if (this->center_ == NULL)  // abandon mission!
148        {
149            orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl;
150            GSLevel::startMainMenu();
151            return;
152        }*/
153        // Call start for the parent class.
154        Deathmatch::start();
155    }
156    void DodgeRace::addPoints(int numPoints)
157    {
158        if (!bEndGame)
159        {
160            point += numPoints * multiplier;
161            b_combo = true;
162        }
163    }
164/*
165    void DodgeRace::end()
166    {
167        // DON'T CALL THIS!
168        //      Deathmatch::end();
169        // It will misteriously crash the game!
170        // Instead startMainMenu, this won't crash.
171        GSLevel::startMainMenu();
172    }*/
173}
Note: See TracBrowser for help on using the repository browser.