Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11561 was 11555, checked in by vyang, 7 years ago

Level file: korrekte Kameraposition, Raumschiff bewegt sich nicht, schiesst aber → wird AsteroidsShip ueberhaupt geladen? AsteroidsShip: neue Steuerung (vgl Jump, Rotation muss noch angepasst werden)

File size: 4.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        this->lives = 3;
63        bEndGame = false;
64        lives = 3;
65        point = 0;
66
67        // Pre-set the timer, but don't start it yet.
68        //this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
69    }
70
71    //spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird
72    void Asteroids::spawnStone()
73    {
74        if(getPlayer() == nullptr) return;
75
76        AsteroidsStone* newStone;
77        newStone = new AsteroidsStone(this->center_->getContext());
78        newStone->addTemplate("asteroidsstone");
79        newStone->setAsteroidsPlayer(player);
80    }
81
82    void Asteroids::spawnStone(int newsize)
83    {
84        //no player -> should end game?
85        if(getPlayer() == nullptr) return;
86        //invalid size
87        if(newsize > 3 || newsize < 1) return;
88        AsteroidsStone* newStone;
89        newStone = new AsteroidsStone(this->center_->getContext());
90        newStone.size = newsize;
91        if(newsize == 1) newStone->addTemplate("asteroidsstone1");
92        else if(newsize == 2) newStone->addTemplate("asteroidsstone2");
93        else newStone->addTemplate("asteroidsstone3");
94        newStone->setAsteroidsPlayer(player);
95
96    }
97
98    AsteroidsShip* Asteroids::getPlayer()
99    {
100        if (player == nullptr)
101        {
102            for (Asteroids* ship : ObjectList<AsteroidsShip>())
103                player = ship;
104        }
105        return player;
106    }
107
108
109    void Asteroids::setCenterpoint(AsteroidsCenterPoint* center)
110    {
111        this->center_ = center;
112    }
113
114    void Asteroids::costLife()
115    {
116        lives = 0;
117    }
118
119    void Asteroids::start()
120    {
121        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.
122        {
123            orxout(internal_error) << "Asteroids: No Centerpoint specified." << endl;
124            GSLevel::startMainMenu();
125            return;
126        }
127
128        // Set variable to temporarily force the player to spawn.
129        bool temp = this->bForceSpawn_;
130        this->bForceSpawn_ = true;
131
132        // Call start for the parent class.
133        Deathmatch::start();
134
135        // Reset the variable.
136        this->bForceSpawn_ = temp;
137    }
138
139    void Asteroids::addPoints(int numPoints)
140    {
141        if (!bEndGame)
142        {
143            point += numPoints;
144        }
145    }
146
147    void Asteroids::end()
148    {
149        // DON'T CALL THIS!
150        //      Deathmatch::end();
151        // It will misteriously crash the game!
152        // Instead startMainMenu, this won't crash.
153        GSLevel::startMainMenu();
154    }
155}
Note: See TracBrowser for help on using the repository browser.