Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Presentation_HS17/src/modules/superorxobros/SOB.cc @ 11680

Last change on this file since 11680 was 11678, checked in by patricwi, 7 years ago

merged FlappyOrx and SOBv2

File size: 4.8 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"
[11678]46#include "Highscore.h"
[11370]47
[11416]48
49
[11370]50namespace orxonox
51{
[11678]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);
[11381]62        camera = nullptr;
[11378]63
[11370]64        this->center_ = nullptr;
[11381]65        figure_ = nullptr;
[11405]66        setHUDTemplate("SOBHUD");
67        coins_=0;
68        points_=0;
69        timeLeft_=400.0;
[11418]70        done_ = true;
[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        if (this->isInitialized())
82            this->cleanup();
83    }
[11370]84
[11381]85    void SOB::cleanup()
86    {
87        camera = nullptr;
88    }
[11370]89
[11416]90
91
[11412]92    void SOB::start()
[11370]93    {
[11378]94        if (center_ != nullptr) // There needs to be a SOBCenterpoint, i.e. the area the game takes place.
[11370]95        {
[11378]96            if (figure_ == nullptr)
97            {
[11416]98                figure_ = new SOBFigure(center_->getContext());     //add a new instance of a player to the game
[11392]99                figure_->addTemplate(center_->getFigureTemplate());
[11378]100            }
101
[11392]102            center_->attach(figure_);
[11378]103            figure_->setPosition(0, 0, 0);
[11370]104        }
[11378]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();
[11370]109            return;
[11378]110        }
[11370]111
[11378]112        // Call start for the parent class.
[11405]113        Gametype::start();
[11378]114
115        if (figure_ != nullptr)
[11370]116        {
[11378]117            camera = figure_->getCamera();
[11370]118        }
119
120    }
121
[11378]122    void SOB::end()
[11370]123    {
[11378]124        cleanup();
125        GSLevel::startMainMenu();
126        Deathmatch::end();
[11678]127}
[11370]128
[11412]129    void SOB::restart() {
130        cleanup();
131
[11416]132        // HACK - only method I found to simply reload the level
[11412]133        Game::getInstance().popState();
134        Game::getInstance().popState();
135        Game::getInstance().requestStates("standalone, level");
136
137       
138    }
[11378]139    void SOB::spawnPlayer(PlayerInfo* player)
[11370]140    {
[11378]141        assert(player);
[11370]142
[11378]143        if (figure_->getPlayer() == nullptr)
[11370]144        {
[11416]145            player->startControl(figure_); //Give the control of the instance player to the real person
[11378]146            players_[player].state_ = PlayerState::Alive;
[11418]147            done_ = false;
[11370]148        }
149    }
[11378]150
151    PlayerInfo* SOB::getPlayer() const
[11370]152    {
[11378]153        if (this->figure_ != nullptr)
[11370]154        {
[11378]155            return this->figure_->getPlayer();
[11370]156        }
[11378]157        else
158        {
159            return nullptr;
160        }
[11370]161    }
162
[11412]163    void SOB::tick(float dt)
[11402]164    {
165        SUPER(SOB, tick, dt);
[11370]166
[11416]167        //If player has reached end of level
168        if (this->figure_ != nullptr && figure_->lvlEnded_) {
169            std::stringstream a;
[11678]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            }
[11416]176            info_ =a.str();
177
178        //If player has died
179        } else if (this->figure_ != nullptr && figure_->dead_) {
[11412]180            info_ = "Game over. Press <Space> to restart";
181        }
182       
[11405]183
[11416]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
[11418]188        if (!done_)
189            timeLeft_-=dt*2.5;
[11402]190    }
[11392]191
192
[11370]193}
Note: See TracBrowser for help on using the repository browser.