/* * 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: * Sebastian Hirsch * Robin Jacobs * Co-authors: * */ /** @file OrxyRoad.cc @brief Implementation of the OrxyRoad class. */ #include "OrxyRoad.h" #include "OrxyRoadShip.h" // Necessary for getPlayer function. Do NOT include this in Header! #include "OrxyRoadCube.h" #include "core/CoreIncludes.h" #include "Highscore.h" #include "infos/PlayerInfo.h" namespace orxonox { RegisterUnloadableClass(OrxyRoad); OrxyRoad::OrxyRoad(Context* context) : Deathmatch(context) { RegisterObject(OrxyRoad); bEndGame = false; lives = 1; level = 1; point = 0; bShowLevel = false; multiplier = 1; b_combo = false; counter = 5000; pattern = 3; lastPosition = 0; roadWidth = 3000; // spawn enemy every 3.5 seconds //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&OrxyRoad::spawnEnemy, this))); comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&OrxyRoad::comboControll, this))); this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 this->center_ = nullptr; this->setHUDTemplate("OrxyRoadHUD"); } void OrxyRoad::levelUp() { level++; if (getPlayer() != nullptr) { for (int i = 0; i < 7; i++) { WeakPtr chunk5 = new ExplosionPart(this->center_->getContext()); chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() chunk5->setScale(10); chunk5->setEffect1("Orxonox/explosion2b"); chunk5->setEffect2("Orxonox/smoke6"); chunk5->Explode(); } } addPoints(multiplier * 42); multiplier *= 2; toggleShowLevel(); showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&OrxyRoad::toggleShowLevel, this))); } int OrxyRoad::generateStreet(int type, OrxyRoadShip* player){ int trafficVelocities[]= {200,1400,500, 300}; int velocityVariation[] = {40,80,100,20}; int numObjects[] = {30,30,30,30}; // default, spaceship, satellite, asteroid per track int streetSize[] = {3 , 1, 2, 4}; int trackWidth = 700; for(int j = 0; j < streetSize[type]; j++)//width of Street { int sign = rand()%2; //orxout(internal_error) << sign<< endl; for(int i = -numObjects[type]/2; icenter_->getContext()); cubeList.push_back(cube); int templateType = rand()%2; switch(type) { case 0 : if(templateType >=1){ cube->addTemplate("asteroid1");//default }else { cube->addTemplate("satellite");//default } break; case 1: if(templateType >=1){ cube->addTemplate("spaceshuttle");//spaceship1 }else { cube->addTemplate("spaceshuttle");//spaceship2 } break; case 2: if(templateType >=1){ cube->addTemplate("satellite");//satellite }else { cube->addTemplate("satellite");//satellite } break; case 3: if(templateType >=1){ cube->addTemplate("asteroid1");//asteroid }else { cube->addTemplate("asteroid2");//asteroid } } int posVar = rand()%2; int distance = trafficVelocities[type]*3 +posVar*trafficVelocities[type]/10; //Todo better calculation of distance between objects cube->setPosition(player->getWorldPosition() + Vector3(2000.0f+j*trackWidth, 0.0f, i*distance)); /* experimental */ if(sign>=1){ cube->setVelocity(0,0,trafficVelocities[type]*level+velocityVariation[j%3]); } else{ cube->setVelocity(0,0,-trafficVelocities[type]*level+velocityVariation[j%3]); } /* experimental */ //stEntity->setScale3D(50,50,50); } } return streetSize[type] * trackWidth; } void OrxyRoad::tick(float dt) { SUPER(OrxyRoad, tick, dt); OrxyRoadShip* player = this->getPlayer(); if (player != nullptr) { currentPosition = player->getWorldPosition().x; counter = counter + (currentPosition - lastPosition); lastPosition = currentPosition; point = (int) currentPosition; player->speed = 830.0f - (point / 1000); for(unsigned int i=0; i < cubeList.size();i++) { if(cubeList.at(i)->getPosition().x < currentPosition-500) { cubeList.at(i)->destroy(); cubeList.erase(cubeList.begin()+i); } } if(counter >= roadWidth-200) { int type = rand() % 4; //orxout(user_info) << "Random : "<()) { return ship; } return nullptr; } void OrxyRoad::costLife() { //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this))); lives = 0; }; void OrxyRoad::comboControll() { if (b_combo) multiplier++; // if no combo was performed before, reset multiplier else multiplier = 1; b_combo = false; } void OrxyRoad::start() { orxout() << "start" << endl; for(unsigned int i=0; i< cubeList.size();i++) { cubeList.at(i)->destroy(); cubeList.erase(cubeList.begin()+i); } cubeList.clear(); // Set variable to temporarily force the player to spawn. this->bForceSpawn_ = false; if (this->center_ == nullptr) // abandon mission! { orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl; GSLevel::startMainMenu(); return; } Deathmatch::start(); } void OrxyRoad::playerPreSpawn(PlayerInfo* player) { this->playerInfo_ = player; if(lives <= 0) { this->end(); } // Reset all the cubes /* orxout() << "prespawn" << endl; for(int i=0; i< cubeList.size();i++) { cubeList.at(i)->destroy(); cubeList.erase(cubeList.begin()+i); } cubeList.clear(); lives = 1; point = 0; lastPosition = 0; */ } void OrxyRoad::addPoints(int numPoints) { if (!bEndGame) { point += numPoints * multiplier; b_combo = true; } } void OrxyRoad::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(); Highscore::getInstance().storeScore("Orxy Road ", score, this->playerInfo_); } GSLevel::startMainMenu(); } }