Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Pickups work; Lives Counter and Total Flag Counter

  • Property svn:eol-style set to native
File size: 6.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#include "HoverShip.h"
43
44#include "pickup/PickupSpawner.h"
45#include "pickup/Pickup.h"
46
47namespace orxonox
48{
49    RegisterUnloadableClass(Hover);
50
51    Hover::Hover(Context* context) : Gametype(context)
52    {
53        RegisterObject(Hover);
54
55        this->origin_ = nullptr;
56        this->numberOfFlags_ = 1;
57        this->firstTick_ = true;
58        level = 1; //start at level 1
59        flagsTaken = 0;// took 0 flags in the beginning
60        lives = 3;
61
62        numCells = 0;
63        cellSize = 0;
64        cellHeight = 0;
65
66        totFlags = 0;
67
68        this->setHUDTemplate("HoverHUD");
69
70    }
71
72    void Hover::start()
73    {
74        Gametype::start();
75        if(this->firstTick_ && this->origin_)
76        {
77            this->firstTick_ = false;
78
79            numCells = this->origin_->getNumCells();
80            cellSize = this->origin_->getCellSize();
81            cellHeight = this->origin_->getCellHeight();
82
83            MazeGenerator generator(numCells);
84            generator.generateMaze();
85            generator.renderMaze();
86
87            int* levelcode = generator.getLevelcode();
88
89            //Outer Walls
90            for(int i = 0; i<numCells; i++){
91                (new HoverWall(origin_->getContext()))->init(0,        i+1,      cellSize, cellHeight, 1);
92                (new HoverWall(origin_->getContext()))->init(numCells, i+1,      cellSize, cellHeight, 1);
93                (new HoverWall(origin_->getContext()))->init(i+1,      0,        cellSize, cellHeight, 2);
94                (new HoverWall(origin_->getContext()))->init(i+1,      numCells, cellSize, cellHeight, 2);
95            }
96
97
98
99            //Generate inner Walls according to levelcode
100            for(int y=0; y<numCells; y++){
101                for(int x=0; x<numCells; x++){
102                    switch(levelcode[ y * numCells + x ])
103                    {
104                        case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
105                            break;
106                        case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1);
107                        case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0);
108                        default:
109                            break;
110                    }
111                }
112            }
113
114            //Generate 5 flags randomly (test only 1 flag)
115            for ( int i = 0; i < 5; i++ )
116            {
117                HoverFlag* flag = new HoverFlag(origin_->getContext());
118                flag->init(rand()%numCells, rand()%numCells, cellSize);
119                flags_.push_back(flag);
120            }
121           
122
123            //Generate 5 PickupSpawners randomly
124            for (int i = 0; i<5; i++)
125            {
126                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
127
128                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 10.0f));
129                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplate());
130                pickupSpawner->setMaxSpawnedItems(5);
131                pickupSpawner->setRespawnTime(30);
132                pickupSpawner->setTriggerDistance(5);
133                // Add pickup spawner to the pickup spawner list
134                pickupSpawners_.push_back(pickupSpawner);
135            }
136             //If no lives are left, end game
137            if(lives <= 0){
138                GSLevel::startMainMenu();
139            }
140
141            orxout() << this->origin_->getPickupTemplate() << endl;
142            orxout() << this->origin_->getPickupRepresentationTemplate() << endl;
143        } 
144    }
145
146
147    // Rename/delete this function.
148    void Hover::startLevel()
149    {
150        //Generate 5 flags randomly (test only 1 flag)
151            for ( int i = 0; i < 5; i++ )
152            {
153                HoverFlag* flag = new HoverFlag(origin_->getContext());
154                flag->init(rand()%numCells, rand()%numCells, cellSize);
155                flags_.push_back(flag);
156            }
157
158        //Generate 5 PickupSpawners randomly
159            for (int i = 0; i<5; i++)
160            {
161                PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext());
162
163                pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 10.0f));
164                pickupSpawner->setPickupTemplateName(origin_->getPickupTemplate());
165                pickupSpawner->setMaxSpawnedItems(5);
166                pickupSpawner->setRespawnTime(30);
167                pickupSpawner->setTriggerDistance(5);
168                // Add pickup spawner to the pickup spawner list
169                pickupSpawners_.push_back(pickupSpawner);
170            }
171
172           
173    }
174
175    void Hover::tick(float dt)
176    {
177        SUPER(Hover, tick, dt);
178
179
180        // Check if ship collided with one of the flags
181        for ( unsigned int i = 0; i < flags_.size(); i++ )
182        {
183            if(flags_[i]->getCollided())
184            {
185                flags_[i]->destroyLater();
186                flags_.erase (flags_.begin()+i);
187                totFlags++;
188                if(flags_.size()<=0){
189                    ChatManager::message("Level Up!");
190                   
191                    levelUp();
192                    //GSLevel::startMainMenu();
193                }
194            }
195
196        }
197        numberOfFlags_ = flags_.size();
198
199        if(lives <= 0){
200                GSLevel::startMainMenu();
201            }
202    }
203
204    void Hover::levelUp()
205    {
206        level++;
207        startLevel();
208
209    }
210
211    Vector3 Hover::get3dCoordinates(int x, int y, float heightOffset)
212    {
213        return Vector3(x*cellSize*1.0f + cellSize/2, heightOffset, y*cellSize*1.0f + cellSize/2);
214    }
215
216    void Hover::costLife()
217    {
218        lives--;
219        if (lives <= 0)
220            GSLevel::startMainMenu();
221    }
222}
Note: See TracBrowser for help on using the repository browser.