Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxoBlox_FS19/src/modules/superorxobros/SOB.cc @ 12294

Last change on this file since 12294 was 12031, checked in by merholzl, 6 years ago

merged Tubes into SuperOrxoBros

  • Property svn:eol-style set to native
File size: 4.5 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 *      Julien Kindle
24 *   Co-authors:
25 *     
26 *
27 */
28
29/**
30    @file SOB.cc
31    @brief Implementation of the SOB class.
32*/
33
34#include "SOB.h"
35#include "core/CoreIncludes.h"
36#include "core/EventIncludes.h"
37#include "core/command/Executor.h"
38#include "core/config/ConfigValueIncludes.h"
39#include "core/Game.h"
40#include "gamestates/GSLevel.h"
41#include "chat/ChatManager.h"
42#include "infos/PlayerInfo.h"
43#include "SOBCenterpoint.h"
44#include "SOBFigure.h"
45#include "graphics/Camera.h"
46#include "Highscore.h"
47
48
49
50namespace orxonox
51{
52    bool newHighscore=0;
53    RegisterUnloadableClass(SOB);
54
55    /**
56    @brief
57        Constructor. Registers and initializes the object.
58    */
59    SOB::SOB(Context* context) : Deathmatch(context)
60    {
61        RegisterObject(SOB);
62
63        this->center_ = nullptr;
64        figure_ = nullptr;
65        setHUDTemplate("SOBHUD");
66        coins_=0;
67        points_=0;
68        timeLeft_=400.0;
69        done_ = true;
70        newHighscore = false;
71        lvl_ = 1;
72
73    }
74
75    /**
76    @brief
77        Destructor. Cleans up, if initialized.
78    */
79    SOB::~SOB()
80    {
81    }
82
83    void SOB::start()
84    {
85        if (center_ != nullptr) // There needs to be a SOBCenterpoint, i.e. the area the game takes place.
86        {
87            if (figure_ == nullptr)
88            {
89                figure_ = new SOBFigure(center_->getContext());     //add a new instance of a player to the game
90                figure_->addTemplate(center_->getFigureTemplate());
91            }
92
93            figure_->setPosition(0, 0, 0);
94        }
95        else // If no centerpoint was specified, an error is thrown and the level is exited.
96        {
97            orxout(internal_error) << "SOB: No Centerpoint specified." << endl;
98            GSLevel::startMainMenu();
99            return;
100        }
101
102        // Call start for the parent class.
103        Gametype::start();
104
105    }
106
107    void SOB::end()
108    {
109        GSLevel::startMainMenu();
110        Deathmatch::end();
111}
112
113    void SOB::restart() {
114        // HACK - only method I found to simply reload the level
115        Game::getInstance().popState();
116        Game::getInstance().popState();
117        Game::getInstance().requestStates("standalone, level");
118
119       
120    }
121    void SOB::spawnPlayer(PlayerInfo* player)
122    {
123        assert(player);
124
125        if (figure_->getPlayer() == nullptr)
126        {
127            player->startControl(figure_); //Give the control of the instance player to the real person
128            players_[player].state_ = PlayerState::Alive;
129            done_ = false;
130        }
131    }
132
133    PlayerInfo* SOB::getPlayer() const
134    {
135        if (this->figure_ != nullptr)
136        {
137            return this->figure_->getPlayer();
138        }
139        else
140        {
141            return nullptr;
142        }
143    }
144
145    void SOB::tick(float dt)
146    {
147        SUPER(SOB, tick, dt);
148
149        //If player has reached end of level
150        if (this->figure_ != nullptr && figure_->lvlEnded_) {
151            std::stringstream a;setLvl(2);
152            if(!newHighscore){
153                a << "Nice! " << getPoints() << " Points in " << (400-getTimeLeft())/2 <<"s.\n\nPress <Space> to restart";
154            }
155            else{
156                a << "Congrats, new Highscore! " << getPoints() << " Points in " << (400-getTimeLeft())/2 <<"s.\n\nPress <Space> to restart";
157            }
158            info_ =a.str();
159
160        //If player has died
161        } else if (this->figure_ != nullptr && figure_->dead_) {
162            info_ = "Game over. Press <Space> to restart";
163        }
164       
165
166        //Kill the player if time is up
167        if (this->figure_ != nullptr && timeLeft_ <= 0)
168            this->figure_->dead_ = true;
169        //The time on the HUD
170        if (!done_)
171            timeLeft_-=dt*2.5f;
172    }
173
174
175}
Note: See TracBrowser for help on using the repository browser.