Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core7/src/modules/invader/Invader.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: 5.2 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 Invader.cc
31    @brief Implementation of the Invader class.
32*/
33
34#include "Invader.h"
35
36#include "core/CoreIncludes.h"
37#include "core/EventIncludes.h"
38#include "core/command/Executor.h"
39#include "core/config/ConfigValueIncludes.h"
40
41#include "gamestates/GSLevel.h"
42#include "chat/ChatManager.h"
43
44// ! HACK
45#include "infos/PlayerInfo.h"
46
47#include "InvaderCenterPoint.h"
48#include "InvaderShip.h"
49#include "InvaderEnemy.h"
50#include "InvaderEnemyShooter.h"
51
52#include "core/command/ConsoleCommand.h"
53#include "worldentities/BigExplosion.h"
54
55namespace orxonox
56{
57    RegisterUnloadableClass(Invader);
58
59    Invader::Invader(Context* context) : Deathmatch(context)
60    {
61        RegisterObject(Invader);
62        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
63        this->center_ = 0;
64        bEndGame = false;
65        lives = 3;
66        level = 1;
67        point = 0;
68        bShowLevel = false;
69        multiplier = 1;
70        b_combo = false;
71        // spawn enemy every 3.5 seconds
72        enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&Invader::spawnEnemy, this)));
73        comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&Invader::comboControll, this)));
74        this->setHUDTemplate("InvaderHUD");
75    }
76
77    void Invader::levelUp()
78    {
79        level++;
80        if (getPlayer() != NULL)
81        {
82            for (int i = 0; i < 7; i++)
83            {
84                BigExplosion* chunk = new BigExplosion(this->center_->getContext());
85                chunk->setPosition(Vector3(600, 0, 100.f * i - 300));
86                chunk->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
87                chunk->setScale(20);
88            }
89        }
90        addPoints(multiplier * 42);
91        multiplier *= 2;
92        toggleShowLevel();
93        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Invader::toggleShowLevel, this)));
94    }
95
96    InvaderShip* Invader::getPlayer()
97    {
98        if (player == NULL)
99        {
100            for (ObjectList<InvaderShip>::iterator it = ObjectList<InvaderShip>::begin(); it != ObjectList<InvaderShip>::end(); ++it)
101                player = *it;
102        }
103        return player;
104    }
105
106    void Invader::spawnEnemy()
107    {
108        if (getPlayer() == NULL)
109            return;
110
111        for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)
112        {
113            InvaderEnemy* newPawn;
114            if (rand() % 42/(1 + level*level) == 0)
115            {
116                newPawn = new InvaderEnemyShooter(this->center_->getContext());
117                newPawn->addTemplate("enemyinvadershooter");
118            }
119            else
120            {
121                newPawn = new InvaderEnemy(this->center_->getContext());
122                newPawn->addTemplate("enemyinvader");
123            }
124            newPawn->setPlayer(player);
125            newPawn->level = level;
126            // spawn enemy at random points in front of player.
127            newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));
128        }
129    }
130
131    void Invader::costLife()
132    {
133        lives--;
134        multiplier = 1;
135        // end the game in 30 seconds.
136        if (lives <= 0)
137            enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&Invader::end, this)));
138    };
139
140    void Invader::comboControll()
141    {
142        if (b_combo)
143            multiplier++;
144        // if no combo was performed before, reset multiplier
145        else
146            multiplier = 1;
147        b_combo = false;
148    }
149
150    void Invader::start()
151    {
152        // Set variable to temporarily force the player to spawn.
153        this->bForceSpawn_ = true;
154
155        if (this->center_ == NULL)  // abandon mission!
156        {
157            orxout(internal_error) << "Invader: No Centerpoint specified." << endl;
158            GSLevel::startMainMenu();
159            return;
160        }
161        // Call start for the parent class.
162        Deathmatch::start();
163    }
164    void Invader::addPoints(int numPoints)
165    {
166        if (!bEndGame)
167        {
168            point += numPoints * multiplier;
169            b_combo = true;
170        }
171    }
172
173    void Invader::end()
174    {
175        // DON'T CALL THIS!
176        //      Deathmatch::end();
177        // It will misteriously crash the game!
178        // Instead startMainMenu, this won't crash.
179        GSLevel::startMainMenu();
180    }
181}
Note: See TracBrowser for help on using the repository browser.