Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Asteroiden werden generiert und bewegen sich, HUD muss noch angepasst werden, Punkte und Health und Leben anzeigen. Raumschiff kann noch nicht schiessen, evtl auch Schutzfunktion → nachdem ein Leben verloren wurde 2s Immunitaet?

File size: 5.9 KB
RevLine 
[11593]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
[11617]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
[11593]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!
[11616]41#include "Asteroids2DStone.h"
[11593]42#include "core/CoreIncludes.h"
[11608]43#include "Highscore.h"
[11593]44
45namespace orxonox
46{
47    RegisterUnloadableClass(Asteroids2D);
48
49    Asteroids2D::Asteroids2D(Context* context) : Deathmatch(context)
50    {
51        RegisterObject(Asteroids2D);
52
[11608]53        bEndGame = false;
[11637]54        lives = 5;
[11608]55        level = 1;
56        point = 0;
57        bShowLevel = false;
58        multiplier = 1;
59        b_combo = false;
[11616]60        firstTick_ = true;
[11608]61        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
62        this->center_ = nullptr;
63        this->setHUDTemplate("Asteroids2DHUD");
[11637]64        levelupTimer.setTimer(60.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this)));
[11593]65    }
66
[11613]67
68
[11608]69    void Asteroids2D::levelUp()
70    {
71        level++;
72        if (getPlayer() != nullptr)
73        {
[11637]74
75            //kann schoener gemacht werden
[11608]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        }
[11637]88        addPoints(multiplier * 20);
[11608]89        multiplier *= 2;
90        toggleShowLevel();
91        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this)));
[11637]92
93
[11617]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
[11608]99    }
100
[11593]101    void Asteroids2D::tick(float dt)
102    {
[11617]103        //Do this only for the first tick, generate 5 stones for the beginning
[11616]104        if(this->firstTick_)
105        {
[11637]106            getPlayer();
[11616]107            for(int i = 0; i < 5; ++i)
108            {
109                spawnStone();
110            }
[11637]111
[11616]112            this->firstTick_ = false;
113        }
[11608]114       
[11593]115        SUPER(Asteroids2D, tick, dt);
116    }
117
[11616]118    void Asteroids2D::spawnStone()
119    {
120        Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext());
121        newStone->setAsteroids2DPlayer(player);
122
[11617]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        }
[11616]138    }
139
[11593]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
[11608]152    void Asteroids2D::costLife()
153    {
[11617]154        --lives;
[11619]155        if(lives <= 0){
[11617]156            endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this)));           
157        }
[11608]158    };
[11617]159   
[11608]160
[11593]161    void Asteroids2D::start()
162    {
163        orxout() << "start" << endl;
[11608]164
[11593]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
[11608]178    void Asteroids2D::playerPreSpawn(PlayerInfo* player)
179    {
180        if(lives <= 0)
181        {
182            this->end();
183        }
184    }
185
[11617]186    //wird gerufen, falls man einen Asteroiden trifft->Aufruf durch Schiffklasse
[11608]187    void Asteroids2D::addPoints(int numPoints)
188    {
189        if (!bEndGame)
190        {
191            point += numPoints * multiplier;
192            b_combo = true;
193        }
194    }
195
[11593]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.
[11608]202        if (Highscore::exists()){
203                    int score = this->getPoints();
[11616]204                    if(score > Highscore::getInstance().getHighestScoreOfGame("Asteroids2D")) 
205                        Highscore::getInstance().storeHighscore("Asteroids2D",score);
[11608]206
207          }
[11593]208        GSLevel::startMainMenu();
209    }
210}
Note: See TracBrowser for help on using the repository browser.