Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11916 was 11916, checked in by jacobsr, 6 years ago

experimental moving cubes 2

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        OrxyRoadShip* player = this->getPlayer();
94        if (player != nullptr)
95        {
96            currentPosition = player->getWorldPosition().x;
97            counter = counter + (currentPosition - lastPosition);
98            lastPosition = currentPosition;
99            point = (int) currentPosition;
100            player->speed = 830.0f - (point / 1000);
101
102            for(unsigned int i=0; i < cubeList.size();i++)
103            {
104                if(cubeList.at(i)->getPosition().x < currentPosition-3000)
105                {
106                    cubeList.at(i)->destroy();
107                    cubeList.erase(cubeList.begin()+i);
108                }
109            }
110
111            if(counter >= 3000)
112            {
113                counter = 0;
114                for(int j = 0; j < 3; j++)//deepth cube
115                {
116                    for(int i = -30; i<30; i++)
117                    {
118                        OrxyRoadCube* cube = new OrxyRoadCube(this->center_->getContext());
119                        cubeList.push_back(cube);
120                        switch(pattern)
121                        {
122                        case 1: cube->addTemplate("OrxyRoadCube01");
123                        break;
124                        case 2: cube->addTemplate("OrxyRoadCube01");
125                        break;
126                        case 3: cube->addTemplate("SingleOrxyRoadCube");
127
128                        }
129
130                        cube->setPosition(player->getWorldPosition() + Vector3(1000.0f+j*800.0f, 0.0f, i*600.0f+j*300));
131                       
132                        /* experimental */
133
134                        cube->setVelocity(0,0,500);
135
136                        /* experimental */
137
138
139                        //stEntity->setScale3D(50,50,50);
140                    }
141                }
142
143
144                //pattern %= 2;
145                //pattern ++;
146
147            }
148
149        }
150        SUPER(OrxyRoad, tick, dt);
151    }
152
153    OrxyRoadShip* OrxyRoad::getPlayer()
154    {
155        for (OrxyRoadShip* ship : ObjectList<OrxyRoadShip>())
156        {
157            return ship;
158        }
159        return nullptr;
160    }
161
162    void OrxyRoad::costLife()
163    {
164        //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this)));
165        lives = 0;
166    };
167
168    void OrxyRoad::comboControll()
169    {
170        if (b_combo)
171            multiplier++;
172        // if no combo was performed before, reset multiplier
173        else
174            multiplier = 1;
175        b_combo = false;
176    }
177
178    void OrxyRoad::start()
179    {
180        orxout() << "start" << endl;
181        for(unsigned int i=0; i< cubeList.size();i++)
182        {
183            cubeList.at(i)->destroy();
184            cubeList.erase(cubeList.begin()+i);
185
186        }
187        cubeList.clear();
188        // Set variable to temporarily force the player to spawn.
189        this->bForceSpawn_ = false;
190
191        if (this->center_ == nullptr)  // abandon mission!
192        {
193            orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl;
194            GSLevel::startMainMenu();
195            return;
196        }
197        Deathmatch::start();
198    }
199
200    void OrxyRoad::playerPreSpawn(PlayerInfo* player)
201    {
202        this->playerInfo_ = player;
203        if(lives <= 0)
204        {
205            this->end();
206        }
207
208        // Reset all the cubes
209        /*
210        orxout() << "prespawn" << endl;
211        for(int i=0; i< cubeList.size();i++)
212        {
213            cubeList.at(i)->destroy();
214            cubeList.erase(cubeList.begin()+i);
215        }
216        cubeList.clear();
217        lives = 1;
218        point = 0;
219        lastPosition = 0;
220        */
221    }
222
223    void OrxyRoad::addPoints(int numPoints)
224    {
225        if (!bEndGame)
226        {
227            point += numPoints * multiplier;
228            b_combo = true;
229        }
230    }
231
232    void OrxyRoad::end()
233    {
234        // DON'T CALL THIS!
235        //      Deathmatch::end();
236        // It will misteriously crash the game!
237        // Instead startMainMenu, this won't crash.
238        if (Highscore::exists())
239        {
240            int score = this->getPoints();
241            Highscore::getInstance().storeScore("Orxy Road ", score, this->playerInfo_);
242        }
243        GSLevel::startMainMenu();
244    }
245}
Note: See TracBrowser for help on using the repository browser.