Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/mergeFS18/src/modules/superorxobros/SOB.cc @ 12398

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