Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc @ 11534

Last change on this file since 11534 was 11528, checked in by vyang, 7 years ago

Spawn Funktion fuer die Asteroiden veraendert

File size: 5.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 Invader.cc
31    @brief Implementation of the Invader class.
32*/
33
34#include "Asteroids.h"
35#include "Highscore.h"
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 "AsteroidsCenterPoint.h"
48#include "AsteroidsShip.h"
49
50#include "core/command/ConsoleCommand.h"
51#include "worldentities/ExplosionPart.h"
52
53namespace orxonox
54{
55    RegisterUnloadableClass(Asteroids);
56
57    Asteroids::Asteroids(Context* context) : Deathmatch(context)
58    {
59        RegisterObject(Asteroids);
60        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
61        this->center_ = nullptr;
62        bEndGame = false;
63        lives = 3;
64        point = 0;
65
66        // Pre-set the timer, but don't start it yet.
67        this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
68    }
69
70    //spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird
71    Asteroids::spawnStone(){
72        if(getPlayer() == nullptr){
73            return;
74        }
75
76        AsteroidsStone* newStone;
77        newStone = new AsteroidsStone(this->center_->getContext());
78        newStone->addTemplate("asteroidsstone");
79        newStone->setAsteroidsPlayer(player);
80    }
81
82        void Invader::spawnEnemy()
83    {
84        if (getPlayer() == nullptr)
85            return;
86
87        for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++)
88        {
89            InvaderEnemy* newPawn;
90            if (rand() % 42/(1 + level*level) == 0)
91            {
92                newPawn = new InvaderEnemyShooter(this->center_->getContext());
93                newPawn->addTemplate("enemyinvadershooter");
94            }
95            else
96            {
97                newPawn = new InvaderEnemy(this->center_->getContext());
98                newPawn->addTemplate("enemyinvader");
99            }
100            newPawn->setInvaderPlayer(player);
101            newPawn->level = level;
102            // spawn enemy at random points in front of player.
103            newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200));
104        }
105    }
106
107    /**
108    @brief
109        Destructor. Cleans up, if initialized.
110    */
111    Asteroids::~Asteroids()
112    {
113        if (this->isInitialized())
114            this->cleanup();
115    }
116
117    /**
118    @brief
119        Cleans up the Gametype by destroying all of the objects in the game - spaceship and asteroids.
120    */
121    void Asteroids::cleanup()
122    {
123        if (this->stones_ != nullptr) // Destroy the ball, if present.
124        {
125            this->stones_->destroy();
126            this->stones_ = nullptr;
127        }
128
129        // Destroy AsteroidsShip
130
131        if (this->player != nullptr)
132        {
133            this->player->destroy();
134            this->player = nullptr;
135        }
136    }
137
138    AsteroidsShip* Asteroids::getPlayer()
139    {
140        if (player == nullptr)
141        {
142            for (Asteroids* ship : ObjectList<AsteroidsShip>())
143                player = ship;
144        }
145        return player;
146    }
147
148
149    void Asteroids::setCenterpoint(AsteroidsCenterPoint* center)
150    {
151        this->center_ = center;
152    }
153
154    void Asteroids::costLife()
155    {
156        lives = 0;
157    };
158    void Asteroids::start()
159    {
160        if (this->center_ == nullptr) // There needs to be a AsteroidsCenterpoint, i.e. the area the game takes place. If no centerpoint was specified, an error is thrown and the level is exited.
161        {
162            orxout(internal_error) << "Asteroids: No Centerpoint specified." << endl;
163            GSLevel::startMainMenu();
164            return;
165        }
166
167        // Set variable to temporarily force the player to spawn.
168        bool temp = this->bForceSpawn_;
169        this->bForceSpawn_ = true;
170
171        // Call start for the parent class.
172        Deathmatch::start();
173
174        // Reset the variable.
175        this->bForceSpawn_ = temp;
176    }
177
178    void Asteroids::addPoints(int numPoints)
179    {
180        if (!bEndGame)
181        {
182            point += numPoints;
183        }
184    }
185
186    void Asteroids::end()
187    {
188        // DON'T CALL THIS!
189        //      Deathmatch::end();
190        // It will misteriously crash the game!
191        // Instead startMainMenu, this won't crash.
192        GSLevel::startMainMenu();
193    }
194}
Note: See TracBrowser for help on using the repository browser.