Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_FS17/src/modules/superorxobros/SOB.cc @ 11441

Last change on this file since 11441 was 11418, checked in by jkindle, 8 years ago

IMPROVED JUMP ALGORITHM OH GHAD YEES JEES

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