Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Asteroids2DStones erstellt, lassen sich ins Level laden, random spawn wenn position nicht als Attribut im XML File angegeben wird. Random Geschwindigkeit funktioniert noch nicht → vllt Einstellungen in Pawn bzw MovableEntity?, Gametype ein wenig aufgeraemt → am Anfang fuenf Asteroiden mit random Geschwindigkeit und Position spawnen

File size: 4.8 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 Asteroids2D.cc
31    @brief Implementation of the Asteroids2D class.
32*/
33
34#include "Asteroids2D.h"
35#include "Asteroids2DShip.h" // Necessary for getPlayer function. Do NOT include this in Header!
36#include "Asteroids2DStone.h"
37#include "core/CoreIncludes.h"
38#include "Highscore.h"
39
40namespace orxonox
41{
42    RegisterUnloadableClass(Asteroids2D);
43
44    Asteroids2D::Asteroids2D(Context* context) : Deathmatch(context)
45    {
46        RegisterObject(Asteroids2D);
47
48        bEndGame = false;
49        lives = 3;
50        level = 1;
51        point = 0;
52        bShowLevel = false;
53        multiplier = 1;
54        b_combo = false;
55        firstTick_ = true;
56        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
57        this->center_ = nullptr;
58        this->setHUDTemplate("Asteroids2DHUD");
59    }
60
61
62
63    void Asteroids2D::levelUp()
64    {
65        level++;
66        if (getPlayer() != nullptr)
67        {
68            for (int i = 0; i < 7; i++)
69            {
70                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
71                chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
72                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
73                chunk5->setScale(10);
74                chunk5->setEffect1("Orxonox/explosion2b");
75                chunk5->setEffect2("Orxonox/smoke6");
76                chunk5->Explode();
77
78            }
79        }
80        addPoints(multiplier * 42);
81        multiplier *= 2;
82        toggleShowLevel();
83        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this)));
84    }
85
86    void Asteroids2D::tick(float dt)
87    {
88        //Do this only for the first tick, generate stones
89        if(this->firstTick_)
90        {
91            for(int i = 0; i < 5; ++i)
92            {
93                spawnStone();
94            }
95            this->firstTick_ = false;
96        }
97       
98        SUPER(Asteroids2D, tick, dt);
99    }
100
101    void Asteroids2D::spawnStone()
102    {
103        if (getPlayer() == nullptr)
104            return;
105        Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext());
106        newStone->setAsteroids2DPlayer(player);
107        //addtemplate
108
109    }
110
111    Asteroids2DShip* Asteroids2D::getPlayer()
112    {
113        if (player == nullptr)
114        {
115            for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>())
116            {
117                player = ship;
118            }
119        }
120        return player;
121    }
122
123    void Asteroids2D::costLife()
124    {
125        //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this)));
126        lives = 0;
127    };
128
129    void Asteroids2D::start()
130    {
131        orxout() << "start" << endl;
132
133        // Set variable to temporarily force the player to spawn.
134        this->bForceSpawn_ = false;
135
136        if (this->center_ == nullptr)  // abandon mission!
137        {
138            orxout(internal_error) << "Asteroids2D: No Centerpoint specified." << endl;
139            GSLevel::startMainMenu();
140            return;
141        }
142        // Call start for the parent class.
143        Deathmatch::start();
144    }
145
146    void Asteroids2D::playerPreSpawn(PlayerInfo* player)
147    {
148        if(lives <= 0)
149        {
150            this->end();
151        }
152    }
153
154    void Asteroids2D::addPoints(int numPoints)
155    {
156        if (!bEndGame)
157        {
158            point += numPoints * multiplier;
159            b_combo = true;
160        }
161    }
162
163    void Asteroids2D::end()
164    {
165        // DON'T CALL THIS!
166        //      Deathmatch::end();
167        // It will misteriously crash the game!
168        // Instead startMainMenu, this won't crash.
169        if (Highscore::exists()){
170                    int score = this->getPoints();
171                    if(score > Highscore::getInstance().getHighestScoreOfGame("Asteroids2D")) 
172                        Highscore::getInstance().storeHighscore("Asteroids2D",score);
173
174          }
175        GSLevel::startMainMenu();
176    }
177}
Note: See TracBrowser for help on using the repository browser.