Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Pickups + Flags HUD

  • Property svn:eol-style set to native
File size: 5.9 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 *      Manuel Meier
24 *   Co-authors:
25 *      Cyrill Burgener
26 *
27 */
28
29/**
30    @file Hover.cc
31    @brief Implementation of the Hover class. Sets up the whole Minigame
32*/
33
34#include "Hover.h"
35#include "chat/ChatManager.h"
36#include "HoverOrigin.h"
37#include "HoverWall.h"
38#include "HoverFlag.h"
39#include "MazeGenerator.h"
40#include "core/CoreIncludes.h"
41#include "gamestates/GSLevel.h"
42
43#include "pickup/PickupSpawner.h"
44#include "pickup/Pickup.h"
45
46namespace orxonox
47{
48    RegisterUnloadableClass(Hover);
49
50    Hover::Hover(Context* context) : Gametype(context)
51    {
52        RegisterObject(Hover);
53
54        this->origin_ = nullptr;
55        this->numberOfFlags_ = 1;
56        this->firstTick_ = true;
57        level = 1; //start at level 1
58        flagsTaken = 0;// took 0 flags in the beginning
59
60        numCells = 0;
61        cellSize = 0;
62        cellHeight = 0;
63
64        totFlags = 0;
65
66        this->setHUDTemplate("HoverHUD");
67
68    }
69
70    void Hover::start()
71    {
72        Gametype::start();
73        if(this->firstTick_ && this->origin_)
74        {
75            this->firstTick_ = false;
76
77            numCells = this->origin_->getNumCells();
78            cellSize = this->origin_->getCellSize();
79            cellHeight = this->origin_->getCellHeight();
80
81            MazeGenerator generator(numCells);
82            generator.generateMaze();
83            generator.renderMaze();
84
85            int* levelcode = generator.getLevelcode();
86
87            //Outer Walls
88            for(int i = 0; i<numCells; i++){
89                (new HoverWall(origin_->getContext()))->init(0,        i+1,      cellSize, cellHeight, 1);
90                (new HoverWall(origin_->getContext()))->init(numCells, i+1,      cellSize, cellHeight, 1);
91                (new HoverWall(origin_->getContext()))->init(i+1,      0,        cellSize, cellHeight, 2);
92                (new HoverWall(origin_->getContext()))->init(i+1,      numCells, cellSize, cellHeight, 2);
93            }
94
95
96
97            //Generate inner Walls according to levelcode
98            for(int y=0; y<numCells; y++){
99                for(int x=0; x<numCells; x++){
100                    switch(levelcode[ y * numCells + x ]){
101                        case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
102                                break;
103                        case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
104                        case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0);
105                        default: break;
106                    }
107                }   
108            }
109
110            //Generate 5 flags randomly (test only 1 flag)
111            for ( int i = 0; i < 5; i++ )
112            {
113                HoverFlag* flag = new HoverFlag(origin_->getContext());
114                flag->init(rand()%numCells, rand()%numCells, cellSize);
115                flags_.push_back(flag);
116            }
117           
118
119            //Generate 5 PickupSpawners randomly
120            for (int i = 0; i<5; i++)
121            {
122                PickupSpawner* pickup = new PickupSpawner(origin_->getContext());
123                pickup->setPosition(rand()%numCells, rand()%numCells, cellSize);
124                //pickup->setPickupTemplateName(origin_->getPickupMeta());
125                //pickup->setPickupTemplateName("destroymetapickup");
126                pickup->setMaxSpawnedItems(5);
127                pickup->setRespawnTime(30);
128                pickup->setTriggerDistance(5);
129                //pickup->createDroppedPickup(this->getContext(), pickup , this, 5);
130                pickups_.push_back(pickup);
131            }
132
133
134        } 
135    }
136
137
138
139    void Hover::startLevel(){
140        //Generate 5 flags randomly (test only 1 flag)
141            for ( int i = 0; i < 5; i++ )
142            {
143                HoverFlag* flag = new HoverFlag(origin_->getContext());
144                flag->init(rand()%numCells, rand()%numCells, cellSize);
145                flags_.push_back(flag);
146            }
147
148        //Generate 5 PickupSpawners randomly
149            for (int i = 0; i<5; i++)
150            {
151                PickupSpawner* pickup = new PickupSpawner(origin_->getContext());
152                //PickupSpawner->setPosition(rand()%numCells, rand()%numCells, cellSize);
153                //pickup->createDroppedPickup(this->getContext(), pickup , this, 5);
154                pickups_.push_back(pickup);
155            }
156
157    }
158
159    void Hover::tick(float dt)
160    {
161        SUPER(Hover, tick, dt);
162
163
164        // Check if ship collided with one of the flags
165        for ( unsigned int i = 0; i < flags_.size(); i++ ){
166            if(flags_[i]->getCollided()){
167                flags_[i]->destroyLater();
168                flags_.erase (flags_.begin()+i);
169                totFlags++;
170                if(flags_.size()<=0){
171                    ChatManager::message("Level Up!");
172                   
173                    levelUp();
174                    //GSLevel::startMainMenu();
175                }
176            }
177
178        }
179        numberOfFlags_ = flags_.size();
180    }
181
182    void Hover::levelUp()
183    {
184        level++;
185        startLevel();
186
187    }
188}
Note: See TracBrowser for help on using the repository browser.