Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11/src/modules/invader/Invader.cc @ 10905

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

fixed includes to make it compile without build units

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