Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tgidronFS16/src/modules/hover/Hover.cc @ 11196

Last change on this file since 11196 was 11196, checked in by tgidron, 8 years ago

Final Project

  • Property svn:eol-style set to native
File size: 9.1 KB
RevLine 
[10658]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:
[10930]23 *      Manuel Meier
[10658]24 *   Co-authors:
[11036]25 *      Cyrill Burgener
[11196]26 *      Tomer Gidron
[10658]27 *
28 */
29
30/**
31    @file Hover.cc
[10930]32    @brief Implementation of the Hover class. Sets up the whole Minigame
[10658]33*/
34
35#include "Hover.h"
[11151]36#include "chat/ChatManager.h"
[11041]37#include "HoverOrigin.h"
[10708]38#include "HoverWall.h"
[11041]39#include "HoverFlag.h"
[11035]40#include "MazeGenerator.h"
[10658]41#include "core/CoreIncludes.h"
[11151]42#include "gamestates/GSLevel.h"
[11171]43#include "HoverShip.h"
[10658]44
[11163]45#include "pickup/PickupSpawner.h"
46#include "pickup/Pickup.h"
47
[10658]48namespace orxonox
49{
50    RegisterUnloadableClass(Hover);
51
[10664]52    Hover::Hover(Context* context) : Gametype(context)
[10658]53    {
54        RegisterObject(Hover);
[11035]55
[11071]56        this->origin_ = nullptr;
[11043]57        this->numberOfFlags_ = 1;
[11035]58        this->firstTick_ = true;
[11151]59        level = 1; //start at level 1
60        flagsTaken = 0;// took 0 flags in the beginning
[11171]61        lives = 3;
[11035]62
[11151]63        numCells = 0;
64        cellSize = 0;
65        cellHeight = 0;
66
[11196]67        bLevelUpgradeHUD = false;
[11192]68
[11168]69        totFlags = 0;
70
[10895]71        this->setHUDTemplate("HoverHUD");
[11151]72
[10658]73    }
74
[11151]75    void Hover::start()
[10658]76    {
[11151]77        Gametype::start();
[11040]78        if(this->firstTick_ && this->origin_)
[11035]79        {
80            this->firstTick_ = false;
[10787]81
[11151]82            numCells = this->origin_->getNumCells();
83            cellSize = this->origin_->getCellSize();
84            cellHeight = this->origin_->getCellHeight();
[11040]85
[11196]86            //TODO
87            //create boolean array/vector to assert that no two objects are placed in the same way
88           
[11192]89
[11040]90            MazeGenerator generator(numCells);
[11035]91            generator.generateMaze();
92            generator.renderMaze();
[10787]93
[11035]94            int* levelcode = generator.getLevelcode();
[10787]95
[10928]96            //Outer Walls
[11040]97            for(int i = 0; i<numCells; i++){
[11042]98                (new HoverWall(origin_->getContext()))->init(0,        i+1,      cellSize, cellHeight, 1);
99                (new HoverWall(origin_->getContext()))->init(numCells, i+1,      cellSize, cellHeight, 1);
100                (new HoverWall(origin_->getContext()))->init(i+1,      0,        cellSize, cellHeight, 2);
101                (new HoverWall(origin_->getContext()))->init(i+1,      numCells, cellSize, cellHeight, 2);
[10928]102            }
103
[11163]104
[11192]105            //Ground
106            for(int i = 0; i<numCells; i++){
107                for(int j = 0; j<numCells; j++){
108                    StaticEntity* groundCell = new StaticEntity(origin_->getContext());
[11163]109
[11192]110                    groundCell->addTemplate(origin_->getGroundTemplate());
111                    groundCell->setPosition(get3dCoordinates(i,j,-60));
112                }
113
114            }
115
116
117
[10930]118            //Generate inner Walls according to levelcode
[11040]119            for(int y=0; y<numCells; y++){
120                for(int x=0; x<numCells; x++){
[11169]121                    switch(levelcode[ y * numCells + x ])
122                    {
[11042]123                        case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
[11169]124                            break;
[11042]125                        case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
126                        case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0);
[11169]127                        default:
128                            break;
[10787]129                    }
[11169]130                }
[10787]131            }
132
[11192]133            createFlags();
[10900]134
[11182]135            //Generate 3 PickupSpawners randomly (destroy hover pickup)
136            for (int i = 0; i<3; i++)
[11163]137            {
[11169]138                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
139
[11192]140                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f));
[11169]141                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplate());
[11182]142                pickupSpawner->setMaxSpawnedItems(3);
[11169]143                pickupSpawner->setRespawnTime(30);
[11192]144                pickupSpawner->setTriggerDistance(40);
[11169]145                // Add pickup spawner to the pickup spawner list
146                pickupSpawners_.push_back(pickupSpawner);
[11163]147            }
[11177]148           
[11182]149            //Generate 3 PickupSpawners randomly (speed pickup)
150            for (int i = 0; i<3; i++)
[11177]151            {
152                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
153
[11192]154                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f));
[11182]155                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplateSpeed());
156                pickupSpawner->setMaxSpawnedItems(3);
[11177]157                pickupSpawner->setRespawnTime(30);
[11192]158                pickupSpawner->setTriggerDistance(40);
[11177]159                // Add pickup spawner to the pickup spawner list
160                pickupSpawners_.push_back(pickupSpawner);
161            }
162
[11182]163            //Generate 3 PickupSpawners randomly (shrink pickup)
164            for (int i = 0; i<3; i++)
165            {
166                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
167
[11192]168                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f));
[11182]169                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplateShrink());
170                pickupSpawner->setMaxSpawnedItems(3);
171                pickupSpawner->setRespawnTime(30);
[11192]172                pickupSpawner->setTriggerDistance(40);
[11182]173                // Add pickup spawner to the pickup spawner list
174                pickupSpawners_.push_back(pickupSpawner);
175            }
176
[11177]177            //*****************************************************************************
178
[11192]179            //Generate destroyable crates randomly on field
[11182]180
[11192]181            for (int i = 0; i<10; i++){
[11177]182
[11192]183                Pawn* crate = new Pawn(origin_->getContext());
184
185                crate->addTemplate(origin_->getObstacleTemplate()); 
186                crate->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 43.0f));
187
188
189            }   
[11184]190           
[11177]191
192
193
[11171]194             //If no lives are left, end game
[11182]195            if(lives <= 0)
196            {
[11171]197                GSLevel::startMainMenu();
198            }
[11196]199           
[11182]200        }
[11151]201    }
[10930]202
[11151]203
[11196]204    // generate new Flags
[11192]205    void Hover::createFlags()
[11169]206    {
[11196]207        //TODO
208        //Generate flags randomly using bool array
[11192]209
[11196]210        //Generate 5 flags randomly on field
211        for ( int i = 0; i < 5; i++ )
212        {
213            HoverFlag* flag = new HoverFlag(origin_->getContext());
214            flag->init(rand()%numCells, rand()%numCells, cellSize);
215            flags_.push_back(flag);
[11192]216
[11196]217           
[11192]218
[11196]219            if(flags_[i]->getPosition() == get3dCoordinates(0,0,-60))
[11151]220            {
[11196]221                flags_[i]->destroyLater();
222                flags_.erase(flags_.begin()+i);
[11151]223            }
[11196]224        }
[11169]225           
[11151]226    }
227
228    void Hover::tick(float dt)
229    {
230        SUPER(Hover, tick, dt);
231
232
[10930]233        // Check if ship collided with one of the flags
[11169]234        for ( unsigned int i = 0; i < flags_.size(); i++ )
235        {
236            if(flags_[i]->getCollided())
237            {
[11043]238                flags_[i]->destroyLater();
239                flags_.erase (flags_.begin()+i);
[11168]240                totFlags++;
[11151]241                if(flags_.size()<=0){
[11177]242                    //ChatManager::message("Level Up!");
[11151]243                   
244                    levelUp();
245                }
[10894]246            }
[11151]247
[10894]248        }
[11043]249        numberOfFlags_ = flags_.size();
[11171]250
251        if(lives <= 0){
252                GSLevel::startMainMenu();
253            }
[10658]254    }
[11151]255
[11196]256    //start new level - call to create new flags
[11151]257    void Hover::levelUp()
258    {
259        level++;
[11177]260        //increment lives after every 4 levels
261        if(level%4 == 0)
262        {
263            lives++;
264        }
[11192]265        createFlags();
266        toggleShowLevel();
[11196]267        showLevelTimer.setTimer(2.0f, false, createExecutor(createFunctor(&Hover::toggleShowLevel, this)));
[11151]268
[11196]269        //spawn one additional crate randomly
270        Pawn* crate = new Pawn(origin_->getContext());
271        crate->addTemplate(origin_->getObstacleTemplate()); 
272        crate->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 43.0f));
273
[11151]274    }
[11169]275
276    Vector3 Hover::get3dCoordinates(int x, int y, float heightOffset)
277    {
278        return Vector3(x*cellSize*1.0f + cellSize/2, heightOffset, y*cellSize*1.0f + cellSize/2);
279    }
[11171]280
[11196]281    //if killed, subtract number of lives. If lives == 0, end game
[11171]282    void Hover::costLife()
283    {
284        lives--;
285        if (lives <= 0)
286            GSLevel::startMainMenu();
287    }
[10658]288}
Note: See TracBrowser for help on using the repository browser.