Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SOBv2_HS17/src/modules/superorxobros/SOB.cc @ 11601

Last change on this file since 11601 was 11601, checked in by zarron, 6 years ago

with Highscores

File size: 4.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 *      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        camera = nullptr;
63
64        this->center_ = nullptr;
65        figure_ = nullptr;
66        setHUDTemplate("SOBHUD");
67        coins_=0;
68        points_=0;
69        timeLeft_=400.0;
70        done_ = true;
71        lvl_ = 1;
72
73    }
74
75    /**
76    @brief
77        Destructor. Cleans up, if initialized.
78    */
79    SOB::~SOB()
80    {
81        if (this->isInitialized())
82            this->cleanup();
83    }
84
85    void SOB::cleanup()
86    {
87        camera = nullptr;
88    }
89
90
91
92    void SOB::start()
93    {
94        if (center_ != nullptr) // There needs to be a SOBCenterpoint, i.e. the area the game takes place.
95        {
96            if (figure_ == nullptr)
97            {
98                figure_ = new SOBFigure(center_->getContext());     //add a new instance of a player to the game
99                figure_->addTemplate(center_->getFigureTemplate());
100            }
101
102            center_->attach(figure_);
103            figure_->setPosition(0, 0, 0);
104        }
105        else // If no centerpoint was specified, an error is thrown and the level is exited.
106        {
107            orxout(internal_error) << "SOB: No Centerpoint specified." << endl;
108            GSLevel::startMainMenu();
109            return;
110        }
111
112        // Call start for the parent class.
113        Gametype::start();
114
115        if (figure_ != nullptr)
116        {
117            camera = figure_->getCamera();
118        }
119
120    }
121
122    void SOB::end()
123    {
124        cleanup();
125        GSLevel::startMainMenu();
126        Deathmatch::end();
127}
128
129    void SOB::restart() {
130        cleanup();
131
132        // HACK - only method I found to simply reload the level
133        Game::getInstance().popState();
134        Game::getInstance().popState();
135        Game::getInstance().requestStates("standalone, level");
136
137       
138    }
139    void SOB::spawnPlayer(PlayerInfo* player)
140    {
141        assert(player);
142
143        if (figure_->getPlayer() == nullptr)
144        {
145            player->startControl(figure_); //Give the control of the instance player to the real person
146            players_[player].state_ = PlayerState::Alive;
147            done_ = false;
148        }
149    }
150
151    PlayerInfo* SOB::getPlayer() const
152    {
153        if (this->figure_ != nullptr)
154        {
155            return this->figure_->getPlayer();
156        }
157        else
158        {
159            return nullptr;
160        }
161    }
162
163    void SOB::tick(float dt)
164    {
165        SUPER(SOB, tick, dt);
166
167        //If player has reached end of level
168        if (this->figure_ != nullptr && figure_->lvlEnded_) {
169            std::stringstream a;
170            if(newHighscore){
171                a << "Nice! " << getPoints() << " Points in " << (400-getTimeLeft())/2 <<"s.\n\nPress <Space> to restart";
172            }
173            else{
174                a << "Congrats, new Highscore! " << getPoints() << " Points in " << (400-getTimeLeft())/2 <<"s.\n\nPress <Space> to restart";
175            }
176            info_ =a.str();
177
178        //If player has died
179        } else if (this->figure_ != nullptr && figure_->dead_) {
180            info_ = "Game over. Press <Space> to restart";
181        }
182       
183
184        //Kill the player if time is up
185        if (this->figure_ != nullptr && timeLeft_ <= 0)
186            this->figure_->dead_ = true;
187        //The time on the HUD
188        if (!done_)
189            timeLeft_-=dt*2.5;
190    }
191
192
193}
Note: See TracBrowser for help on using the repository browser.