Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/asteroids2D/Asteroids2D.cc @ 12218

Last change on this file since 12218 was 11781, checked in by landauf, 7 years ago

eol-style native (no changes in code)

  • Property svn:eol-style set to native
File size: 7.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 *      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        - Problem: The asteroids spawn randomly on the playing field.
39            During spawn or level up, there is the possibility that they pawn at the position of the ship.
40            ->spawn somewhere with a safty distance/radius
41        - look over collisionshapes of the stones ->  sometimes collison with stone is not triggered for bigger stones
42        - modify parameters in data/levels/templates/spaceshipAsteroids2D.oxt for a better playing experience -> mass, damping, rotation etc.
43
44    IDEAS:
45        - make Asteroids more beautiful! (setting, ship, explosion particles, stones)
46        - particle effect after you got hit -> during bImmune is true
47        - implement shield -> object that can be triggered
48        - Projectiles should also move over the boarders and appear on the other side
49            -> they can also hurt the player
50
51*/
52
53#include "Asteroids2D.h"
54#include "Asteroids2DShip.h" // Necessary for getPlayer function. Do NOT include this in Header!
55#include "Asteroids2DStone.h"
56#include "Asteroids2DCenterPoint.h"
57#include "Asteroids2DHUDinfo.h"
58#include "core/CoreIncludes.h"
59#include "Highscore.h"
60#include "gamestates/GSLevel.h"
61#include "infos/PlayerInfo.h"
62
63namespace orxonox
64{
65    RegisterUnloadableClass(Asteroids2D);
66
67    Asteroids2D::Asteroids2D(Context* context) : Deathmatch(context)
68    {
69        RegisterObject(Asteroids2D);
70
71        bEndGame = false;
72        lives = 3; 
73        level = 1;
74        point = 0;
75        bShowLevel = false;
76        multiplier = 1;
77        b_combo = false;
78        firstTick_ = true;
79        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
80        this->center_ = nullptr;
81        this->setHUDTemplate("Asteroids2DHUD");
82        levelupTimer.setTimer(30.0f, true, createExecutor(createFunctor(&Asteroids2D::levelUp, this))); //level up every 30s
83    }
84
85    void Asteroids2D::setCenterpoint(Asteroids2DCenterPoint* center)
86    {
87        this->center_ = center;
88    }
89
90    void Asteroids2D::levelUp()
91    {
92        level++;
93        if (getPlayer() != nullptr)
94        {
95
96            //Do something that indicates a level up
97            for (int i = 0; i < 7; i++)
98            {
99                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
100                chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
101                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
102                chunk5->setScale(10);
103                chunk5->setEffect1("Orxonox/explosion2b");
104                chunk5->setEffect2("Orxonox/smoke6");
105                chunk5->Explode();
106
107            }
108        }
109        addPoints(multiplier * 20);
110        multiplier *= 2;
111        toggleShowLevel();
112        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this)));
113
114
115        //After level up -> spawn stones. Modify for different difficulty level
116        for(int i = 0; i < level*2; i++){
117            spawnStone();
118        }
119
120    }
121
122    void Asteroids2D::tick(float dt)
123    {
124        //Do this only for the first tick, generate 5 stones in the beginning
125        if(this->firstTick_)
126        {
127            for(int i = 0; i < 5; ++i)
128            {
129                spawnStone();
130            }
131            //after first tick, firstTick_ will remain false
132            this->firstTick_ = false;
133        }
134       
135        SUPER(Asteroids2D, tick, dt);
136    }
137
138    void Asteroids2D::spawnStone()
139    {
140
141        //stones are created with a size -> second constructor in Asteroids2DStone class
142        Asteroids2DStone* newStone = new Asteroids2DStone(this->center_->getContext());
143
144        //look at templates in data/levels/templates/asteroidsAsteroids2D.oxt
145        switch(newStone->getSize()){
146            case 1:
147                newStone->addTemplate("stone1");
148                break;
149            case 2: 
150                newStone->addTemplate("stone2");
151                break;
152            case 3:
153                newStone->addTemplate("stone3");
154                break;
155            default:
156                orxout(internal_error) << "Asteroids2DStone has invalid size and cannot be created" << endl;
157                break;
158
159        }
160    }
161
162    Asteroids2DShip* Asteroids2D::getPlayer()
163    {
164        for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>())
165        {
166            return ship;
167        }
168        return nullptr;
169    }
170
171    void Asteroids2D::costLife()
172    {
173        --lives;
174        if(lives <= 0){
175            endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this)));           
176        }
177    };
178   
179    //The first function that will be called
180    void Asteroids2D::start()
181    {
182        //orxout() << "start" << endl;
183
184        // Set variable to temporarily force the player to spawn.
185        this->bForceSpawn_ = false;
186
187        if (this->center_ == nullptr)  // abandon mission!
188        {
189            orxout(internal_error) << "Asteroids2D: No Centerpoint specified." << endl;
190            GSLevel::startMainMenu();
191            return;
192        }
193        // Call start for the parent class.
194        Deathmatch::start();
195    }
196
197    void Asteroids2D::playerPreSpawn(PlayerInfo* player)
198    {
199        this->playerInfo_ = player;
200        if(lives <= 0)
201        {
202            this->end();
203        }
204    }
205
206    //This function will be called from the ship or the stone class (if the stone was hit)
207    void Asteroids2D::addPoints(int numPoints)
208    {
209        if (!bEndGame)
210        {
211            point += numPoints * multiplier;
212            b_combo = true;
213        }
214    }
215
216    void Asteroids2D::end()
217    {
218        // DON'T CALL THIS!
219        //      Deathmatch::end();
220        // It will misteriously crash the game!
221        // Instead startMainMenu, this won't crash.
222        if (Highscore::exists())
223        {
224            int score = this->getPoints();
225            Highscore::getInstance().storeScore("Asteroids2D", score, this->playerInfo_);
226        }
227        GSLevel::startMainMenu();
228    }
229}
Note: See TracBrowser for help on using the repository browser.