Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/HUD_HS16/src/modules/superorxobros/SOB.cc @ 11796

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

IMPROVED JUMP ALGORITHM OH GHAD YEES JEES

File size: 4.6 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        done_ = true;
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            done_ = false;
147        }
148    }
149
150    PlayerInfo* SOB::getPlayer() const
151    {
152        if (this->figure_ != nullptr)
153        {
154            return this->figure_->getPlayer();
155        }
156        else
157        {
158            return nullptr;
159        }
160    }
161
162    void SOB::tick(float dt)
163    {
164        SUPER(SOB, tick, dt);
165
166        //If player has reached end of level
167        if (this->figure_ != nullptr && figure_->lvlEnded_) {
168            std::stringstream a;
169            a << "Nice! " << getPoints() << " Points in " << (400-getTimeLeft())/2 <<"s.\n\nPress <Space> to restart";
170            info_ =a.str();
171
172        //If player has died
173        } else if (this->figure_ != nullptr && figure_->dead_) {
174            info_ = "Game over. Press <Space> to restart";
175        }
176       
177
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
182        if (!done_)
183            timeLeft_-=dt*2.5;
184    }
185
186
187}
Note: See TracBrowser for help on using the repository browser.