/* * 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: * Florian Zinggeler * Co-authors: * ... * */ /** @file Invader.cc @brief Implementation of the Invader class. */ #include "Asteroids.h" #include "Highscore.h" #include "core/CoreIncludes.h" #include "core/EventIncludes.h" #include "core/command/Executor.h" #include "core/config/ConfigValueIncludes.h" #include "gamestates/GSLevel.h" #include "chat/ChatManager.h" // ! HACK #include "infos/PlayerInfo.h" #include "AsteroidsCenterPoint.h" #include "AsteroidsShip.h" #include "core/command/ConsoleCommand.h" #include "worldentities/ExplosionPart.h" namespace orxonox { RegisterUnloadableClass(Asteroids); Asteroids::Asteroids(Context* context) : Deathmatch(context) { RegisterObject(Asteroids); this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 this->center_ = nullptr; this->lives = 3; bEndGame = false; lives = 3; point = 0; // Pre-set the timer, but don't start it yet. //this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this))); } //spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird void Asteroids::spawnStone() { if(getPlayer() == nullptr) return; AsteroidsStone* newStone; newStone = new AsteroidsStone(this->center_->getContext()); newStone->addTemplate("asteroidsstone"); newStone->setAsteroidsPlayer(player); } void Asteroids::spawnStone(int newsize) { //no player -> should end game? if(getPlayer() == nullptr) return; //invalid size if(newsize > 3 || newsize < 1) return; AsteroidsStone* newStone; newStone = new AsteroidsStone(this->center_->getContext()); newStone.size = newsize; if(newsize == 1) newStone->addTemplate("asteroidsstone1"); else if(newsize == 2) newStone->addTemplate("asteroidsstone2"); else newStone->addTemplate("asteroidsstone3"); newStone->setAsteroidsPlayer(player); } AsteroidsShip* Asteroids::getPlayer() { if (player == nullptr) { for (Asteroids* ship : ObjectList()) player = ship; } return player; } void Asteroids::setCenterpoint(AsteroidsCenterPoint* center) { this->center_ = center; } void Asteroids::costLife() { lives = 0; } void Asteroids::start() { if (this->center_ == nullptr) // There needs to be a AsteroidsCenterpoint, i.e. the area the game takes place. If no centerpoint was specified, an error is thrown and the level is exited. { orxout(internal_error) << "Asteroids: No Centerpoint specified." << endl; GSLevel::startMainMenu(); return; } // Set variable to temporarily force the player to spawn. bool temp = this->bForceSpawn_; this->bForceSpawn_ = true; // Call start for the parent class. Deathmatch::start(); // Reset the variable. this->bForceSpawn_ = temp; } void Asteroids::addPoints(int numPoints) { if (!bEndGame) { point += numPoints; } } void Asteroids::end() { // DON'T CALL THIS! // Deathmatch::end(); // It will misteriously crash the game! // Instead startMainMenu, this won't crash. GSLevel::startMainMenu(); } }