/* * 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 FlappyOrx.cc @brief Implementation of the FlappyOrx class. */ #include "FlappyOrx.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 "FlappyOrxCenterPoint.h" #include "FlappyOrxShip.h" #include "FlappyOrxAsteroid.h" #include "core/command/ConsoleCommand.h" #include "worldentities/ExplosionPart.h" namespace orxonox { RegisterUnloadableClass(FlappyOrx); FlappyOrx::FlappyOrx(Context* context) : Deathmatch(context) { RegisterObject(FlappyOrx); this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 this->center_ = nullptr; bEndGame = false; lives = 1; level = 0; point = 0; bShowLevel = false; sDeathMessage = "Welcome to FlappyOrx\nPress Space to start!"; bIsDead = true; multiplier = 1; b_combo = false; this->spawnDistance=200; this->tubeOffsetX=500; this->setHUDTemplate("FlappyOrxHUD"); } void FlappyOrx::updatePlayerPos(int x){ if(this->tubes.size()==0||x-tubes.back()+tubeOffsetX>spawnDistance){ spawnTube(); this->tubes.push(x+tubeOffsetX); } if(this->tubes.size()!=0&&x>this->tubes.front()){ this->tubes.pop(); levelUp(); } while((this->asteroids.front())->getPosition().xdestroy(); } } void FlappyOrx::levelUp() { point++; spawnDistance = 300-3*point; getPlayer()->setSpeed(100+.5*point); toggleShowLevel(); //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this))); } FlappyOrxShip* FlappyOrx::getPlayer() { if (player == nullptr) { for (FlappyOrxShip* ship : ObjectList()) { player = ship; } } return player; } void FlappyOrx::spawnTube() { int space = 120; int height = (float(rand())/RAND_MAX-0.5)*(280-space); if (getPlayer() == nullptr) return; Vector3 pos = player->getPosition(); asteroidField(pos.x+tubeOffsetX,height-space/2,0.8); asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8); } void FlappyOrx::asteroidField(int x, int y, float slope){ int r = 20; int noadd = 0; ClearAsteroids(); Circle newAsteroid = Circle(); newAsteroid.x=x; newAsteroid.y=y; newAsteroid.r=r; addIfPossible(newAsteroid); while(r>0){ if(slope>0) newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150; else newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y; newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope; newAsteroid.r=r; int i = addIfPossible(newAsteroid); if(i==0) noadd++; else if(i==2) r=0; if(noadd>=5){ noadd=0; r-=5; } } } void deleteAsteroid(MovableEntity* asteroid){ //center_->getContext().getObjectList().removeElement(asteroid); } void FlappyOrx::createAsteroid(Circle &c){ MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext()); if(c.r<=5) newAsteroid->addTemplate(Asteroid5[rand()%6]); else if(c.r<=10) newAsteroid->addTemplate(Asteroid10[rand()%6]); else if(c.r<=15) newAsteroid->addTemplate(Asteroid15[rand()%6]); else newAsteroid->addTemplate(Asteroid20[rand()%6]); newAsteroid->setPosition(Vector3(c.x, 0, c.y)); newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360)); newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360)); asteroids.push(newAsteroid); } void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center) { this->center_ = center; } void FlappyOrx::costLife() { }; bool FlappyOrx::isDead(){ return bIsDead; } std::string FlappyOrx::getDeathMessage(){ return sDeathMessage; } void FlappyOrx::comboControll() { if (b_combo) multiplier++; // if no combo was performed before, reset multiplier else multiplier = 1; b_combo = false; } void FlappyOrx::start() { // Set variable to temporarily force the player to spawn. this->bForceSpawn_ = true; if (this->center_ == nullptr) // abandon mission! { orxout(internal_error) << "FlappyOrx: No Centerpoint specified." << endl; GSLevel::startMainMenu(); return; } // Call start for the parent class. Deathmatch::start(); } void FlappyOrx::addPoints(int numPoints) { if (!bEndGame) { point += numPoints * multiplier; b_combo = true; } } void FlappyOrx::death(){ bIsDead = true; sDeathMessage = "GameOver"; if (Highscore::exists()){ int score = this->getPoints(); if(score > Highscore::getInstance().getHighestScoreOfGame("Flappy Orx")) Highscore::getInstance().storeHighscore("Flappy Orx",score); } point = -1; level=-1; levelUp(); while (!tubes.empty()) { tubes.pop(); } while (!asteroids.empty()) { MovableEntity* deleteMe = asteroids.front(); asteroids.pop(); deleteMe->destroy(); } } void FlappyOrx::end() { // DON'T CALL THIS! // Deathmatch::end(); // It will misteriously crash the game! // Instead startMainMenu, this won't crash. if (Highscore::exists()){ int score = this->getPoints(); if(score > Highscore::getInstance().getHighestScoreOfGame("Orxonox Arcade")) Highscore::getInstance().storeHighscore("Orxonox Arcade",score); } GSLevel::startMainMenu(); } }