/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Julien Kindle * Co-authors: * * */ /** @file SOB.cc @brief Implementation of the SOB class. */ #include "SOB.h" #include "core/CoreIncludes.h" #include "core/EventIncludes.h" #include "core/command/Executor.h" #include "core/config/ConfigValueIncludes.h" #include "core/Game.h" #include "gamestates/GSLevel.h" #include "chat/ChatManager.h" #include "infos/PlayerInfo.h" #include "SOBCenterpoint.h" #include "SOBFigure.h" #include "graphics/Camera.h" #include "Highscore.h" namespace orxonox { bool newHighscore=0; RegisterUnloadableClass(SOB); /** @brief Constructor. Registers and initializes the object. */ SOB::SOB(Context* context) : Deathmatch(context) { RegisterObject(SOB); this->center_ = nullptr; figure_ = nullptr; setHUDTemplate("SOBHUD"); coins_=0; points_=0; timeLeft_=400.0; done_ = true; newHighscore = false; lvl_ = 1; } /** @brief Destructor. Cleans up, if initialized. */ SOB::~SOB() { } void SOB::start() { if (center_ != nullptr) // There needs to be a SOBCenterpoint, i.e. the area the game takes place. { if (figure_ == nullptr) { figure_ = new SOBFigure(center_->getContext()); //add a new instance of a player to the game figure_->addTemplate(center_->getFigureTemplate()); } figure_->setPosition(0, 0, 0); } else // If no centerpoint was specified, an error is thrown and the level is exited. { orxout(internal_error) << "SOB: No Centerpoint specified." << endl; GSLevel::startMainMenu(); return; } // Call start for the parent class. Gametype::start(); } void SOB::end() { GSLevel::startMainMenu(); Deathmatch::end(); } void SOB::restart() { // HACK - only method I found to simply reload the level Game::getInstance().popState(); Game::getInstance().popState(); Game::getInstance().requestStates("standalone, level"); } void SOB::spawnPlayer(PlayerInfo* player) { assert(player); if (figure_->getPlayer() == nullptr) { player->startControl(figure_); //Give the control of the instance player to the real person players_[player].state_ = PlayerState::Alive; done_ = false; } } PlayerInfo* SOB::getPlayer() const { if (this->figure_ != nullptr) { return this->figure_->getPlayer(); } else { return nullptr; } } void SOB::tick(float dt) { SUPER(SOB, tick, dt); //If player has reached end of level if (this->figure_ != nullptr && figure_->lvlEnded_) { std::stringstream a;setLvl(2); if(!newHighscore){ a << "Nice! " << getPoints() << " Points in " << (400-getTimeLeft())/2 <<"s.\n\nPress to restart"; } else{ a << "Congrats, new Highscore! " << getPoints() << " Points in " << (400-getTimeLeft())/2 <<"s.\n\nPress to restart"; } info_ =a.str(); //If player has died } else if (this->figure_ != nullptr && figure_->dead_) { info_ = "Game over. Press to restart"; } //Kill the player if time is up if (this->figure_ != nullptr && timeLeft_ <= 0) this->figure_->dead_ = true; //The time on the HUD if (!done_) timeLeft_-=dt*2.5f; } }