Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.cc @ 11617

Last change on this file since 11617 was 11617, checked in by vyang, 6 years ago

spawnEnemy und Templates für die 3 Grössen der Asteroiden geschrieben.

File size: 5.9 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/*TODO: Punktesystem aufbauen -> in HUD anzeigen
30        Schwierigkeitsgrad mit jedem levelup erhöhen -> mehr Steine spawnen?
31        spawnStone Methode schreiben
32        templates für die drei Grössen von Asteroiden erstellen
33
34/**
35    @file Asteroids2D.cc
36    @brief Implementation of the Asteroids2D class.
37*/
38
39#include "Asteroids2D.h"
40#include "Asteroids2DShip.h" // Necessary for getPlayer function. Do NOT include this in Header!
41#include "Asteroids2DStone.h"
42#include "core/CoreIncludes.h"
43#include "Highscore.h"
44
45namespace orxonox
46{
47    RegisterUnloadableClass(Asteroids2D);
48
49    Asteroids2D::Asteroids2D(Context* context) : Deathmatch(context)
50    {
51        RegisterObject(Asteroids2D);
52
53        bEndGame = false;
54        lives = 3;
55        level = 1;
56        point = 0;
57        bShowLevel = false;
58        multiplier = 1;
59        b_combo = false;
60        firstTick_ = true;
61        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
62        this->center_ = nullptr;
63        this->setHUDTemplate("Asteroids2DHUD");
64        levelupTimer.setTimer(100.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this)));
65    }
66
67
68
69    void Asteroids2D::levelUp()
70    {
71        level++;
72        if (getPlayer() != nullptr)
73        {
74            for (int i = 0; i < 7; i++)
75            {
76                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
77                chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
78                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
79                chunk5->setScale(10);
80                chunk5->setEffect1("Orxonox/explosion2b");
81                chunk5->setEffect2("Orxonox/smoke6");
82                chunk5->Explode();
83
84            }
85        }
86        addPoints(multiplier * 42);
87        multiplier *= 2;
88        toggleShowLevel();
89        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this)));
90        //Nach jedem Level Up werden mehr Steine gespawnt -> abhängig vom Schwierigkeitsgrad
91        for(int i = 0; i < level*2; i++){
92            spawnStone();
93        }
94
95    }
96
97    void Asteroids2D::tick(float dt)
98    {
99        //Do this only for the first tick, generate 5 stones for the beginning
100        if(this->firstTick_)
101        {
102            for(int i = 0; i < 5; ++i)
103            {
104                spawnStone();
105            }
106            this->firstTick_ = false;
107        }
108       
109        SUPER(Asteroids2D, tick, dt);
110    }
111
112    void Asteroids2D::spawnStone()
113    {
114        if (getPlayer() == nullptr)
115            return;
116        Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext());
117        newStone->setAsteroids2DPlayer(player);
118
119        switch(newStone->getSize()){
120            case 1:
121                newStone->addTemplate("stone1");
122                break;
123            case 2: 
124                newStone->addTemplate("stone2");
125                break;
126            case 3:
127                newStone->addTemplate("stone3");
128                break;
129            default:
130                orxout(internal_error) << "Asteroids2DStone has invalid size and cannot be created" << endl;
131                break;
132
133        }
134
135
136    }
137
138    Asteroids2DShip* Asteroids2D::getPlayer()
139    {
140        if (player == nullptr)
141        {
142            for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>())
143            {
144                player = ship;
145            }
146        }
147        return player;
148    }
149
150    void Asteroids2D::costLife()
151    {
152        --lives;
153        if(live <= 0){
154            endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this)));           
155        }
156    };
157   
158
159    void Asteroids2D::start()
160    {
161        orxout() << "start" << endl;
162
163        // Set variable to temporarily force the player to spawn.
164        this->bForceSpawn_ = false;
165
166        if (this->center_ == nullptr)  // abandon mission!
167        {
168            orxout(internal_error) << "Asteroids2D: No Centerpoint specified." << endl;
169            GSLevel::startMainMenu();
170            return;
171        }
172        // Call start for the parent class.
173        Deathmatch::start();
174    }
175
176    void Asteroids2D::playerPreSpawn(PlayerInfo* player)
177    {
178        if(lives <= 0)
179        {
180            this->end();
181        }
182    }
183
184    //wird gerufen, falls man einen Asteroiden trifft->Aufruf durch Schiffklasse
185    void Asteroids2D::addPoints(int numPoints)
186    {
187        if (!bEndGame)
188        {
189            point += numPoints * multiplier;
190            b_combo = true;
191        }
192    }
193
194    void Asteroids2D::end()
195    {
196        // DON'T CALL THIS!
197        //      Deathmatch::end();
198        // It will misteriously crash the game!
199        // Instead startMainMenu, this won't crash.
200        if (Highscore::exists()){
201                    int score = this->getPoints();
202                    if(score > Highscore::getInstance().getHighestScoreOfGame("Asteroids2D")) 
203                        Highscore::getInstance().storeHighscore("Asteroids2D",score);
204
205          }
206        GSLevel::startMainMenu();
207    }
208}
Note: See TracBrowser for help on using the repository browser.