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
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
47
48
49namespace orxonox
50{
51
52    RegisterUnloadableClass(SOB);
53
54    /**
55    @brief
56        Constructor. Registers and initializes the object.
57    */
58    SOB::SOB(Context* context) : Deathmatch(context)
59    {
60        RegisterObject(SOB);
61        camera = nullptr;
62
63        this->center_ = nullptr;
64        figure_ = nullptr;
65        setHUDTemplate("SOBHUD");
66        coins_=0;
67        points_=0;
68        timeLeft_=400.0;
69       
70        lvl_ = 1;
71
72    }
73
74    /**
75    @brief
76        Destructor. Cleans up, if initialized.
77    */
78    SOB::~SOB()
79    {
80        if (this->isInitialized())
81            this->cleanup();
82    }
83
84    void SOB::cleanup()
85    {
86        camera = nullptr;
87    }
88
89
90
91    void SOB::start()
92    {
93        if (center_ != nullptr) // There needs to be a SOBCenterpoint, i.e. the area the game takes place.
94        {
95            if (figure_ == nullptr)
96            {
97                figure_ = new SOBFigure(center_->getContext());     //add a new instance of a player to the game
98                figure_->addTemplate(center_->getFigureTemplate());
99            }
100
101            center_->attach(figure_);
102            figure_->setPosition(0, 0, 0);
103        }
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();
108            return;
109        }
110
111        // Call start for the parent class.
112        Gametype::start();
113
114        if (figure_ != nullptr)
115        {
116            camera = figure_->getCamera();
117        }
118
119    }
120
121    void SOB::end()
122    {
123        cleanup();
124        GSLevel::startMainMenu();
125        Deathmatch::end();
126    }
127
128    void SOB::restart() {
129        cleanup();
130
131        // HACK - only method I found to simply reload the level
132        Game::getInstance().popState();
133        Game::getInstance().popState();
134        Game::getInstance().requestStates("standalone, level");
135
136       
137    }
138    void SOB::spawnPlayer(PlayerInfo* player)
139    {
140        assert(player);
141
142        if (figure_->getPlayer() == nullptr)
143        {
144            player->startControl(figure_); //Give the control of the instance player to the real person
145            players_[player].state_ = PlayerState::Alive;
146        }
147    }
148
149    PlayerInfo* SOB::getPlayer() const
150    {
151        if (this->figure_ != nullptr)
152        {
153            return this->figure_->getPlayer();
154        }
155        else
156        {
157            return nullptr;
158        }
159    }
160
161    void SOB::tick(float dt)
162    {
163        SUPER(SOB, tick, dt);
164
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_) {
173            info_ = "Game over. Press <Space> to restart";
174        }
175       
176
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
181        timeLeft_-=dt*2.5;
182    }
183
184
185}
Note: See TracBrowser for help on using the repository browser.