Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11416 was 11416, checked in by jkindle, 7 years ago

Added the animation for the level end (walk into castle), Coins for the blocks, Castleblocks and Flagblocks

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"
[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;
[11412]69       
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;
[11370]146        }
147    }
[11378]148
149    PlayerInfo* SOB::getPlayer() const
[11370]150    {
[11378]151        if (this->figure_ != nullptr)
[11370]152        {
[11378]153            return this->figure_->getPlayer();
[11370]154        }
[11378]155        else
156        {
157            return nullptr;
158        }
[11370]159    }
160
[11412]161    void SOB::tick(float dt)
[11402]162    {
163        SUPER(SOB, tick, dt);
[11370]164
[11416]165        //If player has reached end of level
166        if (this->figure_ != nullptr && figure_->lvlEnded_) {
167            std::stringstream a;
168            a << "Nice! " << getPoints() << " Points. Press <Space> to restart";
169            info_ =a.str();
170
171        //If player has died
172        } else if (this->figure_ != nullptr && figure_->dead_) {
[11412]173            info_ = "Game over. Press <Space> to restart";
174        }
175       
[11405]176
[11416]177        //Kill the player if time is up
178        if (this->figure_ != nullptr && timeLeft_ <= 0)
179            this->figure_->dead_ = true;
180        //The time on the HUD
[11412]181        timeLeft_-=dt*2.5;
[11402]182    }
[11392]183
184
[11370]185}
Note: See TracBrowser for help on using the repository browser.