Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Highscore_HS16/src/modules/invader/Invader.cc @ 11333

Last change on this file since 11333 was 11333, checked in by kappenh, 7 years ago

Finished Project

  • Property svn:eol-style set to native
File size: 5.8 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"
[11326]35#include "Highscore.h"
[9702]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"
[11052]53#include "worldentities/ExplosionPart.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
[11071]63        this->center_ = nullptr;
[9868]64        bEndGame = false;
[9829]65        lives = 3;
66        level = 1;
67        point = 0;
[9874]68        bShowLevel = false;
[9829]69        multiplier = 1;
70        b_combo = false;
[9874]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)));
[10624]74        this->setHUDTemplate("InvaderHUD");
[9702]75    }
76
[9874]77    void Invader::levelUp()
[9777]78    {
[9874]79        level++;
[11071]80        if (getPlayer() != nullptr)
[9956]81        {
[9874]82            for (int i = 0; i < 7; i++)
83            {
[11052]84
85                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
86                chunk5->setPosition(this->center_->getPosition());
87                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
88                chunk5->setScale(10);
89                chunk5->setEffect1("Orxonox/explosion2b");
90                chunk5->setEffect2("Orxonox/smoke6");
91                chunk5->setMinSpeed(0);
92                chunk5->setMaxSpeed(0);
93                chunk5->Explode();
94
[9874]95            }
96        }
97        addPoints(multiplier * 42);
98        multiplier *= 2;
99        toggleShowLevel();
100        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Invader::toggleShowLevel, this)));
101    }
102
[10624]103    InvaderShip* Invader::getPlayer()
[9874]104    {
[11071]105        if (player == nullptr)
[9777]106        {
[11071]107            for (InvaderShip* ship : ObjectList<InvaderShip>())
108                player = ship;
[9777]109        }
[9874]110        return player;
111    }
112
113    void Invader::spawnEnemy()
114    {
[11071]115        if (getPlayer() == nullptr)
[9777]116            return;
[9959]117
[9956]118        for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)
[9837]119        {
[10624]120            InvaderEnemy* newPawn;
[9874]121            if (rand() % 42/(1 + level*level) == 0)
122            {
123                newPawn = new InvaderEnemyShooter(this->center_->getContext());
124                newPawn->addTemplate("enemyinvadershooter");
125            }
126            else
127            {
128                newPawn = new InvaderEnemy(this->center_->getContext());
129                newPawn->addTemplate("enemyinvader");
130            }
[11083]131            newPawn->setInvaderPlayer(player);
[9854]132            newPawn->level = level;
[9868]133            // spawn enemy at random points in front of player.
[9961]134            newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));
[9837]135        }
[9777]136    }
137
[11071]138    void Invader::setCenterpoint(InvaderCenterPoint* center)
139    {
140        this->center_ = center;
141    }
142
[9858]143    void Invader::costLife()
144    {
145        lives--;
[9868]146        multiplier = 1;
147        // end the game in 30 seconds.
148        if (lives <= 0)
149            enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&Invader::end, this)));
[9858]150    };
151
[9829]152    void Invader::comboControll()
153    {
154        if (b_combo)
155            multiplier++;
[9868]156        // if no combo was performed before, reset multiplier
[9829]157        else
158            multiplier = 1;
159        b_combo = false;
160    }
161
[9702]162    void Invader::start()
163    {
164        // Set variable to temporarily force the player to spawn.
165        this->bForceSpawn_ = true;
166
[11071]167        if (this->center_ == nullptr)  // abandon mission!
[9709]168        {
169            orxout(internal_error) << "Invader: No Centerpoint specified." << endl;
170            GSLevel::startMainMenu();
171            return;
172        }
[9702]173        // Call start for the parent class.
174        Deathmatch::start();
175    }
[9874]176    void Invader::addPoints(int numPoints)
177    {
178        if (!bEndGame)
179        {
180            point += numPoints * multiplier;
181            b_combo = true;
182        }
183    }
[9702]184
185    void Invader::end()
186    {
[9868]187        // DON'T CALL THIS!
188        //      Deathmatch::end();
189        // It will misteriously crash the game!
190        // Instead startMainMenu, this won't crash.
[11326]191        if (Highscore::exists()){
192                    int score = this->getPoints();
193                    if(score > Highscore::getInstance().getHighestScoreOfGame("Orxonox Arcade")) 
[11333]194                        Highscore::getInstance().storeHighscore("Orxonox Arcade",score);
[11326]195
196          }
[9868]197        GSLevel::startMainMenu();
[9702]198    }
199}
Note: See TracBrowser for help on using the repository browser.