Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

distance variation between obejcts\

File size: 9.6 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        roadWidth = 3000;
60
61       
62
63
64
65        // spawn enemy every 3.5 seconds
66        //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&OrxyRoad::spawnEnemy, this)));
67        comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&OrxyRoad::comboControll, this)));
68        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
69        this->center_ = nullptr;
70
71        this->setHUDTemplate("OrxyRoadHUD");
72    }
73
74    void OrxyRoad::levelUp()
75    {
76        level++;
77        if (getPlayer() != nullptr)
78        {
79            for (int i = 0; i < 7; i++)
80            {
81                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
82                chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
83                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
84                chunk5->setScale(10);
85                chunk5->setEffect1("Orxonox/explosion2b");
86                chunk5->setEffect2("Orxonox/smoke6");
87                chunk5->Explode();
88
89            }
90        }
91        addPoints(multiplier * 42);
92        multiplier *= 2;
93        toggleShowLevel();
94        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&OrxyRoad::toggleShowLevel, this)));
95    }
96    int OrxyRoad::generateStreet(int type, OrxyRoadShip* player){
97        int trafficVelocities[]= {200,1400,500, 300};
98        int velocityVariation[] = {40,80,100,20};
99        int numObjects[] = {60,40,30,40}; // default, spaceship, sattellite, asteroid per track
100        int streetSize[] = {3 , 1, 2, 4};
101        int trackWidth = 700;
102     
103        for(int j = 0; j < streetSize[type]; j++)//width of Street
104            {
105                int sign = rand()%2;
106
107                //orxout(internal_error) << sign<< endl;
108               
109               
110
111                for(int i = -numObjects[type]/2; i<numObjects[type]/2; i++)
112                {
113                        OrxyRoadCube* cube = new OrxyRoadCube(this->center_->getContext());
114                        cubeList.push_back(cube);
115                        int templateType = rand()%2;
116                        switch(type)
117                        {
118                        case 0 :
119                            if(templateType >=1){
120                                cube->addTemplate("asteroid1");//default
121                            }else {
122                                cube->addTemplate("satellite");//default
123                            }
124                        break;
125                        case 1:
126                         if(templateType >=1){
127                                cube->addTemplate("spaceshuttle");//spaceship1
128                            }else {
129                                cube->addTemplate("spaceshuttle");//spaceship2
130                            }                       
131                           
132
133                        break;
134                        case 2: 
135                            if(templateType >=1){
136                                cube->addTemplate("satellite");//satellite
137                            }else {
138                                cube->addTemplate("satellite");//satellite
139                            }                     
140
141                           
142                        break;
143                        case 3: 
144                            if(templateType >=1){
145                                cube->addTemplate("asteroid1");//asteroid
146                            }else {
147                                cube->addTemplate("asteroid2");//asteroid
148                            }                     
149
150
151                        }
152
153                        int posVar = rand()%2;
154                        int distance = trafficVelocities[type]*3 +posVar*trafficVelocities[type]/10; //Todo better calculation of distance between objects
155                       
156                        cube->setPosition(player->getWorldPosition() + Vector3(2000.0f+j*trackWidth, 0.0f, i*distance));
157                       
158                        /* experimental */
159                       
160
161                        if(sign>=1){
162                            cube->setVelocity(0,0,trafficVelocities[type]*level+velocityVariation[j%3]);
163                        } else{
164                             cube->setVelocity(0,0,-trafficVelocities[type]*level+velocityVariation[j%3]);
165                        }
166                       
167
168                       
169
170                        /* experimental */
171
172
173                        //stEntity->setScale3D(50,50,50);                   
174                }
175            }
176            return streetSize[type] * trackWidth;
177    }
178       
179
180
181
182    void OrxyRoad::tick(float dt)
183    {
184        SUPER(OrxyRoad, tick, dt);
185       
186        OrxyRoadShip* player = this->getPlayer();
187        if (player != nullptr)
188        {
189            currentPosition = player->getWorldPosition().x;
190            counter = counter + (currentPosition - lastPosition);
191            lastPosition = currentPosition;
192            point = (int) currentPosition;
193            player->speed = 830.0f - (point / 1000);
194
195            for(unsigned int i=0; i < cubeList.size();i++)
196            {
197                if(cubeList.at(i)->getPosition().x < currentPosition-500)
198                {
199                    cubeList.at(i)->destroy();
200                    cubeList.erase(cubeList.begin()+i);
201                }
202            }
203
204           
205
206
207            if(counter >= roadWidth-200)
208            {
209                int type  = rand() % 4;
210                orxout(user_info) << "Random : "<<type<< endl;
211
212                roadWidth = generateStreet(type,player);//Generate street to specific type type = 0 default, type = 1 space ship type  = 2 statellite/cubes, type = 3 asteroids
213                counter = 0;               
214
215                //pattern %= 2;
216                //pattern ++;
217
218            }
219
220        }
221    }
222
223    OrxyRoadShip* OrxyRoad::getPlayer()
224    {
225        for (OrxyRoadShip* ship : ObjectList<OrxyRoadShip>())
226        {
227            return ship;
228        }
229        return nullptr;
230    }
231
232    void OrxyRoad::costLife()
233    {
234        //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this)));
235        lives = 0;
236    };
237
238    void OrxyRoad::comboControll()
239    {
240        if (b_combo)
241            multiplier++;
242        // if no combo was performed before, reset multiplier
243        else
244            multiplier = 1;
245        b_combo = false;
246    }
247
248    void OrxyRoad::start()
249    {
250        orxout() << "start" << endl;
251        for(unsigned int i=0; i< cubeList.size();i++)
252        {
253            cubeList.at(i)->destroy();
254            cubeList.erase(cubeList.begin()+i);
255
256        }
257        cubeList.clear();
258        // Set variable to temporarily force the player to spawn.
259        this->bForceSpawn_ = false;
260
261        if (this->center_ == nullptr)  // abandon mission!
262        {
263            orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl;
264            GSLevel::startMainMenu();
265            return;
266        }
267        Deathmatch::start();
268    }
269
270    void OrxyRoad::playerPreSpawn(PlayerInfo* player)
271    {
272        this->playerInfo_ = player;
273        if(lives <= 0)
274        {
275            this->end();
276        }
277
278        // Reset all the cubes
279        /*
280        orxout() << "prespawn" << endl;
281        for(int i=0; i< cubeList.size();i++)
282        {
283            cubeList.at(i)->destroy();
284            cubeList.erase(cubeList.begin()+i);
285        }
286        cubeList.clear();
287        lives = 1;
288        point = 0;
289        lastPosition = 0;
290        */
291    }
292
293    void OrxyRoad::addPoints(int numPoints)
294    {
295        if (!bEndGame)
296        {
297            point += numPoints * multiplier;
298            b_combo = true;
299        }
300    }
301
302    void OrxyRoad::end()
303    {
304        // DON'T CALL THIS!
305        //      Deathmatch::end();
306        // It will misteriously crash the game!
307        // Instead startMainMenu, this won't crash.
308        if (Highscore::exists())
309        {
310            int score = this->getPoints();
311            Highscore::getInstance().storeScore("Orxy Road ", score, this->playerInfo_);
312        }
313        GSLevel::startMainMenu();
314    }
315}
Note: See TracBrowser for help on using the repository browser.