Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11662 was 11660, checked in by vyang, 7 years ago

Projektile fliegen in 2D Ebene, jedoch in eine falsche Richtung. Kommentare hinzugefuegt

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