Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Asteroids2DShip ist 3s immun, nachdem es von einem Asteroiden getroffen wurde. Das Raumschiff hat nun eine Waffe → Richtung der Projektile muss noch angepasst werden

File size: 6.0 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 = 1000;
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(60.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this)));
65    }
66
67
68
69    void Asteroids2D::levelUp()
70    {
71        level++;
72        if (getPlayer() != nullptr)
73        {
74
75            //kann schoener gemacht werden
76            for (int i = 0; i < 7; i++)
77            {
78                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
79                chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
80                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
81                chunk5->setScale(10);
82                chunk5->setEffect1("Orxonox/explosion2b");
83                chunk5->setEffect2("Orxonox/smoke6");
84                chunk5->Explode();
85
86            }
87        }
88        addPoints(multiplier * 20);
89        multiplier *= 2;
90        toggleShowLevel();
91        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this)));
92
93
94        //Nach jedem Level Up werden mehr Steine gespawnt -> abhängig vom Schwierigkeitsgrad
95        for(int i = 0; i < level*2; i++){
96            spawnStone();
97        }
98
99    }
100
101    void Asteroids2D::tick(float dt)
102    {
103        //Do this only for the first tick, generate 5 stones for the beginning
104        if(this->firstTick_)
105        {
106            getPlayer();
107            for(int i = 0; i < 5; ++i)
108            {
109                spawnStone();
110            }
111
112            this->firstTick_ = false;
113        }
114       
115        SUPER(Asteroids2D, tick, dt);
116    }
117
118    void Asteroids2D::spawnStone()
119    {
120        Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext());
121        newStone->setAsteroids2DPlayer(player);
122
123        switch(newStone->getSize()){
124            case 1:
125                newStone->addTemplate("stone1");
126                break;
127            case 2: 
128                newStone->addTemplate("stone2");
129                break;
130            case 3:
131                newStone->addTemplate("stone3");
132                break;
133            default:
134                orxout(internal_error) << "Asteroids2DStone has invalid size and cannot be created" << endl;
135                break;
136
137        }
138    }
139
140    Asteroids2DShip* Asteroids2D::getPlayer()
141    {
142        if (player == nullptr)
143        {
144            for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>())
145            {
146                player = ship;
147            }
148        }
149        return player;
150    }
151
152    void Asteroids2D::costLife()
153    {
154        --lives;
155        if(lives <= 0){
156            endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this)));           
157        }
158    };
159   
160//Funktion wird als erstes im Level aufgerufen
161    void Asteroids2D::start()
162    {
163        orxout() << "start" << endl;
164
165        // Set variable to temporarily force the player to spawn.
166        this->bForceSpawn_ = false;
167
168        if (this->center_ == nullptr)  // abandon mission!
169        {
170            orxout(internal_error) << "Asteroids2D: No Centerpoint specified." << endl;
171            GSLevel::startMainMenu();
172            return;
173        }
174        // Call start for the parent class.
175        Deathmatch::start();
176    }
177
178    void Asteroids2D::playerPreSpawn(PlayerInfo* player)
179    {
180        if(lives <= 0)
181        {
182            this->end();
183        }
184    }
185
186    //wird gerufen, falls man einen Asteroiden trifft->Aufruf durch Schiffklasse
187    void Asteroids2D::addPoints(int numPoints)
188    {
189        if (!bEndGame)
190        {
191            point += numPoints * multiplier;
192            b_combo = true;
193        }
194    }
195
196    void Asteroids2D::end()
197    {
198        // DON'T CALL THIS!
199        //      Deathmatch::end();
200        // It will misteriously crash the game!
201        // Instead startMainMenu, this won't crash.
202        if (Highscore::exists()){
203                    int score = this->getPoints();
204                    if(score > Highscore::getInstance().getHighestScoreOfGame("Asteroids2D")) 
205                        Highscore::getInstance().storeHighscore("Asteroids2D",score);
206
207          }
208        GSLevel::startMainMenu();
209    }
210}
Note: See TracBrowser for help on using the repository browser.