Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationHS15/src/modules/hover/Hover.cc @ 11035

Last change on this file since 11035 was 11035, checked in by landauf, 8 years ago

moved maze-generator-code into separate class. made all static variables private members. this fixes a number of issues when reloading the hover game.

  • Property svn:eol-style set to native
File size: 3.8 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 Muskelprotz
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
36#include "HoverWall.h"
37#include "HoverFlag.h" 
38#include "MazeGenerator.h"
39#include "core/CoreIncludes.h"
40
41namespace orxonox
42{
43    RegisterUnloadableClass(Hover);
44
45    Hover::Hover(Context* context) : Gametype(context)
46    {
47       
48        RegisterObject(Hover);
49
50        this->origin_ = NULL;
51        this->flags_ = 1;
52        this->firstTick_ = true;
53
54        this->setHUDTemplate("HoverHUD");
55    }
56
57    void Hover::tick(float dt)
58    {
59        SUPER(Hover, tick, dt);
60
61        if(this->firstTick_)
62        {
63            this->firstTick_ = false;
64
65            MazeGenerator generator;
66            generator.generateMaze();
67            generator.renderMaze();
68
69            const int NUM_CELLS = generator.getNumCells();
70            int* levelcode = generator.getLevelcode();
71
72            //Outer Walls
73            for(int i = 0; i<NUM_CELLS; i++){
74                new HoverWall(origin_->getContext(), 0, i+1, 1);
75                new HoverWall(origin_->getContext(), NUM_CELLS, i+1, 1);
76                new HoverWall(origin_->getContext(), i+1, 0, 2);
77                new HoverWall(origin_->getContext(), i+1, NUM_CELLS, 2);
78            }
79
80            //Generate inner Walls according to levelcode
81            for(int y=0; y<NUM_CELLS; y++){
82                for(int x=0; x<NUM_CELLS; x++){
83                    switch(levelcode[ y * NUM_CELLS + x ]){
84                        case 1: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
85                                break;
86                        case 3: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 1);
87                        case 2: new HoverWall(origin_->getContext(), x+1, NUM_CELLS-y, 0);
88                        default: break;
89                    }
90                }   
91            }
92
93            //Generate 5 flags randomly
94            for ( int i = 0; i < 5; i++ )
95                flagVector_.push_back(new HoverFlag(origin_->getContext(), rand()%NUM_CELLS, rand()%NUM_CELLS));
96
97            flags_ = flagVector_.size();
98
99        }//firsttick end
100
101        // Check if ship collided with one of the flags
102        for ( unsigned int i = 0; i < flagVector_.size(); i++ ){
103            if(flagVector_[i]->getCollided()){
104                flagVector_[i]->destroyLater();
105                flagVector_.erase (flagVector_.begin()+i);
106            }
107        }
108        flags_ = flagVector_.size();
109    }
110
111    int Hover::getFlags()
112    {
113        // Call start for the parent class.
114        return flags_;
115    }   
116
117    void Hover::start()
118    {
119        // Call start for the parent class.
120        Gametype::start();
121    }
122
123    void Hover::end()
124    {
125        // DON'T CALL THIS!
126        //      Deathmatch::end();
127        // It will misteriously crash the game!
128        // Instead startMainMenu, this won't crash.
129        GSLevel::startMainMenu();
130    }
131}
Note: See TracBrowser for help on using the repository browser.