Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoad.cc @ 11934

Last change on this file since 11934 was 11934, checked in by sehirsch, 6 years ago

updated camera and cube pattern

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 *      Florian Zinggeler
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file OrxyRoad.cc
31    @brief Implementation of the OrxyRoad class.
32*/
33
34#include "OrxyRoad.h"
35#include "OrxyRoadShip.h" // Necessary for getPlayer function. Do NOT include this in Header!
36#include "OrxyRoadCube.h"
37#include "core/CoreIncludes.h"
38#include "Highscore.h"
39#include "infos/PlayerInfo.h"
40
41namespace orxonox
42{
43    RegisterUnloadableClass(OrxyRoad);
44
45    OrxyRoad::OrxyRoad(Context* context) : Deathmatch(context)
46    {
47        RegisterObject(OrxyRoad);
48
49        bEndGame = false;
50        lives = 1;
51        level = 1;
52        point = 0;
53        bShowLevel = false;
54        multiplier = 1;
55        b_combo = false;
56        counter = 5000;
57        pattern = 3;
58        lastPosition = 0;
59        // spawn enemy every 3.5 seconds
60        //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&OrxyRoad::spawnEnemy, this)));
61        comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&OrxyRoad::comboControll, this)));
62        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
63        this->center_ = nullptr;
64
65        this->setHUDTemplate("OrxyRoadHUD");
66    }
67
68    void OrxyRoad::levelUp()
69    {
70        level++;
71        if (getPlayer() != nullptr)
72        {
73            for (int i = 0; i < 7; i++)
74            {
75                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
76                chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
77                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
78                chunk5->setScale(10);
79                chunk5->setEffect1("Orxonox/explosion2b");
80                chunk5->setEffect2("Orxonox/smoke6");
81                chunk5->Explode();
82
83            }
84        }
85        addPoints(multiplier * 42);
86        multiplier *= 2;
87        toggleShowLevel();
88        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&OrxyRoad::toggleShowLevel, this)));
89    }
90
91    void OrxyRoad::tick(float dt)
92    {
93        SUPER(OrxyRoad, tick, dt);
94       
95        OrxyRoadShip* player = this->getPlayer();
96        if (player != nullptr)
97        {
98            currentPosition = player->getWorldPosition().x;
99            counter = counter + (currentPosition - lastPosition);
100            lastPosition = currentPosition;
101            point = (int) currentPosition;
102            player->speed = 830.0f - (point / 1000);
103
104            for(unsigned int i=0; i < cubeList.size();i++)
105            {
106                if(cubeList.at(i)->getPosition().x < currentPosition-3000)
107                {
108                    cubeList.at(i)->destroy();
109                    cubeList.erase(cubeList.begin()+i);
110                }
111            }
112
113            if(counter >= 3000)
114            {
115                counter = 0;
116                for(int j = 0; j < 3; j++)//deepth cube
117                {
118                    for(int i = -30; i<30; i++)
119                    {
120                        OrxyRoadCube* cube = new OrxyRoadCube(this->center_->getContext());
121                        cubeList.push_back(cube);
122                        switch(pattern)
123                        {
124                        case 1: cube->addTemplate("OrxyRoadCube01");
125                        break;
126                        case 2: cube->addTemplate("OrxyRoadCube01");
127                        break;
128                        case 3: cube->addTemplate("SingleOrxyRoadCube");
129
130                        }
131
132                        cube->setPosition(player->getWorldPosition() + Vector3(1000.0f+j*800.0f, 0.0f, i*600.0f+j*300));
133                       
134                        /* experimental */
135
136                        cube->setVelocity(0,0,500);
137
138                        /* experimental */
139
140
141                        //stEntity->setScale3D(50,50,50);
142                    }
143                }
144
145
146                //pattern %= 2;
147                //pattern ++;
148
149            }
150
151        }
152    }
153
154    OrxyRoadShip* OrxyRoad::getPlayer()
155    {
156        for (OrxyRoadShip* ship : ObjectList<OrxyRoadShip>())
157        {
158            return ship;
159        }
160        return nullptr;
161    }
162
163    void OrxyRoad::costLife()
164    {
165        //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this)));
166        lives = 0;
167    };
168
169    void OrxyRoad::comboControll()
170    {
171        if (b_combo)
172            multiplier++;
173        // if no combo was performed before, reset multiplier
174        else
175            multiplier = 1;
176        b_combo = false;
177    }
178
179    void OrxyRoad::start()
180    {
181        orxout() << "start" << endl;
182        for(unsigned int i=0; i< cubeList.size();i++)
183        {
184            cubeList.at(i)->destroy();
185            cubeList.erase(cubeList.begin()+i);
186
187        }
188        cubeList.clear();
189        // Set variable to temporarily force the player to spawn.
190        this->bForceSpawn_ = false;
191
192        if (this->center_ == nullptr)  // abandon mission!
193        {
194            orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl;
195            GSLevel::startMainMenu();
196            return;
197        }
198        Deathmatch::start();
199    }
200
201    void OrxyRoad::playerPreSpawn(PlayerInfo* player)
202    {
203        this->playerInfo_ = player;
204        if(lives <= 0)
205        {
206            this->end();
207        }
208
209        // Reset all the cubes
210        /*
211        orxout() << "prespawn" << endl;
212        for(int i=0; i< cubeList.size();i++)
213        {
214            cubeList.at(i)->destroy();
215            cubeList.erase(cubeList.begin()+i);
216        }
217        cubeList.clear();
218        lives = 1;
219        point = 0;
220        lastPosition = 0;
221        */
222    }
223
224    void OrxyRoad::addPoints(int numPoints)
225    {
226        if (!bEndGame)
227        {
228            point += numPoints * multiplier;
229            b_combo = true;
230        }
231    }
232
233    void OrxyRoad::end()
234    {
235        // DON'T CALL THIS!
236        //      Deathmatch::end();
237        // It will misteriously crash the game!
238        // Instead startMainMenu, this won't crash.
239        if (Highscore::exists())
240        {
241            int score = this->getPoints();
242            Highscore::getInstance().storeScore("Orxy Road ", score, this->playerInfo_);
243        }
244        GSLevel::startMainMenu();
245    }
246}
Note: See TracBrowser for help on using the repository browser.