Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc @ 11529

Last change on this file since 11529 was 11529, checked in by pascscha, 7 years ago

Asteroid Clusters

File size: 6.3 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 FlappyOrx.cc
31    @brief Implementation of the FlappyOrx class.
32*/
33
34#include "FlappyOrx.h"
35#include "Highscore.h"
36#include "core/CoreIncludes.h"
37#include "core/EventIncludes.h"
38#include "core/command/Executor.h"
39#include "core/config/ConfigValueIncludes.h"
40
41#include "gamestates/GSLevel.h"
42#include "chat/ChatManager.h"
43
44// ! HACK
45#include "infos/PlayerInfo.h"
46
47#include "FlappyOrxCenterPoint.h"
48#include "FlappyOrxShip.h"
49#include "FlappyOrxAsteroid.h"
50
51#include "core/command/ConsoleCommand.h"
52#include "worldentities/ExplosionPart.h"
53
54namespace orxonox
55{
56    RegisterUnloadableClass(FlappyOrx);
57
58    FlappyOrx::FlappyOrx(Context* context) : Deathmatch(context)
59    {
60        RegisterObject(FlappyOrx);
61        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
62        this->center_ = nullptr;
63        bEndGame = false;
64        lives = 1;
65        level = 1;
66        point = 0;
67        bShowLevel = false;
68        multiplier = 1;
69        b_combo = false;
70        this->spawnDistance=300;
71        this->tubeOffsetX=500;
72        this->setHUDTemplate("FlappyOrxHUD");
73    }
74
75    void FlappyOrx::updatePlayerPos(int x){
76        if(this->tubes.size()==0||x-this->tubes.back()-tubeOffsetX>spawnDistance){
77            spawnTube();
78            this->tubes.push(x+tubeOffsetX);
79        }
80        if(this->tubes.size()!=0&&x>this->tubes.front()){
81            this->tubes.pop();
82            levelUp();
83        }
84    }
85
86    void FlappyOrx::levelUp()
87    {
88        level++;
89        //toggleShowLevel();
90        //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this)));
91    }
92
93    FlappyOrxShip* FlappyOrx::getPlayer()
94    {
95        if (player == nullptr)
96        {
97            for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) {
98                player = ship;
99            }
100        }
101        return player;
102    }
103
104    void FlappyOrx::spawnTube()
105    {
106        int space = 90;
107        int height = (float(rand())/RAND_MAX-0.5)*(280-space);
108           
109        if (getPlayer() == nullptr)
110            return;
111
112        Vector3 pos = player->getPosition();
113
114        asteroidField(pos.x+tubeOffsetX,height-space/2,0.8);
115        asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8);   
116    }
117
118    void FlappyOrx::asteroidField(int x, int y, float slope){
119        int r = 20;
120        int noadd = 0;
121
122        ClearAsteroids();
123        Circle newAsteroid = Circle();
124        while(r>0){
125            if(slope>0)
126                newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150;
127            else
128                newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y;
129           
130            newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope;
131            newAsteroid.r=r;
132           
133            int i = addIfPossible(newAsteroid);
134            if(i==0)
135                noadd++;
136            else if(i==2)
137                r=0;
138            if(noadd>=5){
139                noadd=0;
140                r-=5;
141            }
142        }
143    }
144
145    void FlappyOrx::createAsteroid(Circle &c){
146        orxout() << "created Asteroid at x="<<c.x<<" y="<<c.y << std::endl;
147        MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext());
148        if(c.r<=5)
149            newAsteroid->addTemplate(Asteroid5[rand()%6]);
150        else if(c.r<=10)
151            newAsteroid->addTemplate(Asteroid10[rand()%6]);
152        else if(c.r<=15)
153            newAsteroid->addTemplate(Asteroid15[rand()%6]);
154        else
155            newAsteroid->addTemplate(Asteroid20[rand()%6]);
156       
157        newAsteroid->setPosition(Vector3(c.x, 0, c.y));
158        newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360));
159        newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360));
160
161    }
162
163    void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center)
164    {
165        this->center_ = center;
166    }
167
168    void FlappyOrx::costLife()
169    {
170        lives--;
171        multiplier = 1;
172        // end the game in 30 seconds.
173        if (lives <= 0)
174            enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&FlappyOrx::end, this)));
175    };
176
177    void FlappyOrx::comboControll()
178    {
179        if (b_combo)
180            multiplier++;
181        // if no combo was performed before, reset multiplier
182        else
183            multiplier = 1;
184        b_combo = false;
185    }
186
187    void FlappyOrx::start()
188    {
189        // Set variable to temporarily force the player to spawn.
190        this->bForceSpawn_ = true;
191
192        if (this->center_ == nullptr)  // abandon mission!
193        {
194            orxout(internal_error) << "FlappyOrx: No Centerpoint specified." << endl;
195            GSLevel::startMainMenu();
196            return;
197        }
198        // Call start for the parent class.
199        Deathmatch::start();
200    }
201    void FlappyOrx::addPoints(int numPoints)
202    {
203        if (!bEndGame)
204        {
205            point += numPoints * multiplier;
206            b_combo = true;
207        }
208    }
209
210    void FlappyOrx::end()
211    {
212        // DON'T CALL THIS!
213        //      Deathmatch::end();
214        // It will misteriously crash the game!
215        // Instead startMainMenu, this won't crash.
216        if (Highscore::exists()){
217                    int score = this->getPoints();
218                    if(score > Highscore::getInstance().getHighestScoreOfGame("Orxonox Arcade")) 
219                        Highscore::getInstance().storeHighscore("Orxonox Arcade",score);
220
221          }
222        GSLevel::startMainMenu();
223    }
224}
Note: See TracBrowser for help on using the repository browser.