| [10114] | 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 |  *      Florian Zinggeler | 
|---|
 | 24 |  *   Co-authors: | 
|---|
 | 25 |  *      ... | 
|---|
 | 26 |  * | 
|---|
 | 27 |  */ | 
|---|
 | 28 |  | 
|---|
 | 29 | /** | 
|---|
 | 30 |     @file DodgeRace.cc | 
|---|
 | 31 |     @brief Implementation of the DodgeRace class. | 
|---|
 | 32 | */ | 
|---|
 | 33 |  | 
|---|
 | 34 | #include "DodgeRace.h" | 
|---|
| [10118] | 35 | #include "DodgeRaceShip.h" // Necessary for getPlayer function. Do NOT include this in Header! | 
|---|
| [10152] | 36 | #include "DodgeRaceCube.h" | 
|---|
| [10624] | 37 | #include "core/CoreIncludes.h" | 
|---|
| [11356] | 38 | #include "Highscore.h" | 
|---|
| [11783] | 39 | #include "infos/PlayerInfo.h" | 
|---|
| [10114] | 40 |  | 
|---|
 | 41 | namespace orxonox | 
|---|
 | 42 | { | 
|---|
| [10118] | 43 |     RegisterUnloadableClass(DodgeRace); | 
|---|
| [10114] | 44 |  | 
|---|
 | 45 |     DodgeRace::DodgeRace(Context* context) : Deathmatch(context) | 
|---|
 | 46 |     { | 
|---|
 | 47 |         RegisterObject(DodgeRace); | 
|---|
| [10166] | 48 |  | 
|---|
| [10114] | 49 |         bEndGame = false; | 
|---|
| [10166] | 50 |         lives = 1; | 
|---|
| [10114] | 51 |         level = 1; | 
|---|
 | 52 |         point = 0; | 
|---|
 | 53 |         bShowLevel = false; | 
|---|
 | 54 |         multiplier = 1; | 
|---|
 | 55 |         b_combo = false; | 
|---|
| [10166] | 56 |         counter = 5000; | 
|---|
| [10152] | 57 |         pattern = 1; | 
|---|
| [10135] | 58 |         lastPosition = 0; | 
|---|
| [10114] | 59 |         // spawn enemy every 3.5 seconds | 
|---|
 | 60 |         //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this))); | 
|---|
| [10118] | 61 |         comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this))); | 
|---|
| [10624] | 62 |         this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 | 
|---|
| [11071] | 63 |         this->center_ = nullptr; | 
|---|
| [10624] | 64 |  | 
|---|
 | 65 |         this->setHUDTemplate("DodgeRaceHUD"); | 
|---|
| [10114] | 66 |     } | 
|---|
 | 67 |  | 
|---|
 | 68 |     void DodgeRace::levelUp() | 
|---|
 | 69 |     { | 
|---|
| [10117] | 70 |         level++; | 
|---|
| [11071] | 71 |         if (getPlayer() != nullptr) | 
|---|
| [10114] | 72 |         { | 
|---|
 | 73 |             for (int i = 0; i < 7; i++) | 
|---|
 | 74 |             { | 
|---|
| [11052] | 75 |                 WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); | 
|---|
 | 76 |                 chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); | 
|---|
 | 77 |                 chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity() | 
|---|
 | 78 |                 chunk5->setScale(10); | 
|---|
 | 79 |                 chunk5->setEffect1("Orxonox/explosion2b"); | 
|---|
 | 80 |                 chunk5->setEffect2("Orxonox/smoke6"); | 
|---|
 | 81 |                 chunk5->Explode(); | 
|---|
 | 82 |  | 
|---|
| [10114] | 83 |             } | 
|---|
| [10124] | 84 |         } | 
|---|
| [10114] | 85 |         addPoints(multiplier * 42); | 
|---|
 | 86 |         multiplier *= 2; | 
|---|
 | 87 |         toggleShowLevel(); | 
|---|
| [10117] | 88 |         showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this))); | 
|---|
| [10114] | 89 |     } | 
|---|
 | 90 |  | 
|---|
| [10135] | 91 |     void DodgeRace::tick(float dt) | 
|---|
 | 92 |     { | 
|---|
| [11783] | 93 |         DodgeRaceShip* player = this->getPlayer(); | 
|---|
 | 94 |         if (player != nullptr) | 
|---|
| [10236] | 95 |         { | 
|---|
| [11783] | 96 |             currentPosition = player->getWorldPosition().x; | 
|---|
| [10236] | 97 |             counter = counter + (currentPosition - lastPosition); | 
|---|
 | 98 |             lastPosition = currentPosition; | 
|---|
 | 99 |             point = (int) currentPosition; | 
|---|
| [11783] | 100 |             player->speed = 830.0f - (point / 1000); | 
|---|
| [10135] | 101 |  | 
|---|
| [10236] | 102 |             for(unsigned int i=0; i < cubeList.size();i++) | 
|---|
 | 103 |             { | 
|---|
 | 104 |                 if(cubeList.at(i)->getPosition().x < currentPosition-3000) | 
|---|
 | 105 |                 { | 
|---|
 | 106 |                     cubeList.at(i)->destroy(); | 
|---|
 | 107 |                     cubeList.erase(cubeList.begin()+i); | 
|---|
 | 108 |                 } | 
|---|
 | 109 |             } | 
|---|
| [10152] | 110 |  | 
|---|
| [10236] | 111 |             if(counter >= 3000) | 
|---|
 | 112 |             { | 
|---|
 | 113 |                 counter = 0; | 
|---|
 | 114 |                 for(int i = 0; i<6; i++) | 
|---|
 | 115 |                 { | 
|---|
| [10624] | 116 |                     DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext()); | 
|---|
| [10236] | 117 |                     cubeList.push_back(cube); | 
|---|
 | 118 |                     switch(pattern) | 
|---|
 | 119 |                     { | 
|---|
 | 120 |                     case 1: cube->addTemplate("DodgeRaceCube01"); | 
|---|
 | 121 |                     break; | 
|---|
 | 122 |                     case 2: cube->addTemplate("DodgeRaceCube02"); | 
|---|
 | 123 |                     break; | 
|---|
| [10135] | 124 |  | 
|---|
| [10236] | 125 |                     } | 
|---|
| [10152] | 126 |  | 
|---|
| [11783] | 127 |                     cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200))); | 
|---|
| [10236] | 128 |                     //stEntity->setScale3D(50,50,50); | 
|---|
 | 129 |                 } | 
|---|
| [10152] | 130 |  | 
|---|
 | 131 |  | 
|---|
| [10236] | 132 |                 pattern %= 2; | 
|---|
 | 133 |                 pattern ++; | 
|---|
| [10152] | 134 |  | 
|---|
| [10236] | 135 |             } | 
|---|
| [10152] | 136 |  | 
|---|
| [10236] | 137 |         } | 
|---|
 | 138 |         SUPER(DodgeRace, tick, dt); | 
|---|
| [10135] | 139 |     } | 
|---|
 | 140 |  | 
|---|
| [10624] | 141 |     DodgeRaceShip* DodgeRace::getPlayer() | 
|---|
| [10114] | 142 |     { | 
|---|
| [11783] | 143 |         for (DodgeRaceShip* ship : ObjectList<DodgeRaceShip>()) | 
|---|
| [10114] | 144 |         { | 
|---|
| [11783] | 145 |             return ship; | 
|---|
| [10114] | 146 |         } | 
|---|
| [11783] | 147 |         return nullptr; | 
|---|
| [10114] | 148 |     } | 
|---|
 | 149 |  | 
|---|
 | 150 |     void DodgeRace::costLife() | 
|---|
 | 151 |     { | 
|---|
| [10236] | 152 |         //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this))); | 
|---|
 | 153 |         lives = 0; | 
|---|
| [10114] | 154 |     }; | 
|---|
| [10124] | 155 |  | 
|---|
| [10114] | 156 |     void DodgeRace::comboControll() | 
|---|
 | 157 |     { | 
|---|
 | 158 |         if (b_combo) | 
|---|
 | 159 |             multiplier++; | 
|---|
 | 160 |         // if no combo was performed before, reset multiplier | 
|---|
 | 161 |         else | 
|---|
 | 162 |             multiplier = 1; | 
|---|
 | 163 |         b_combo = false; | 
|---|
 | 164 |     } | 
|---|
 | 165 |  | 
|---|
 | 166 |     void DodgeRace::start() | 
|---|
 | 167 |     { | 
|---|
| [10236] | 168 |         orxout() << "start" << endl; | 
|---|
 | 169 |         for(unsigned int i=0; i< cubeList.size();i++) | 
|---|
 | 170 |         { | 
|---|
 | 171 |             cubeList.at(i)->destroy(); | 
|---|
 | 172 |             cubeList.erase(cubeList.begin()+i); | 
|---|
| [10152] | 173 |  | 
|---|
| [10236] | 174 |         } | 
|---|
| [10152] | 175 |         cubeList.clear(); | 
|---|
| [10114] | 176 |         // Set variable to temporarily force the player to spawn. | 
|---|
| [10166] | 177 |         this->bForceSpawn_ = false; | 
|---|
| [10114] | 178 |  | 
|---|
| [11071] | 179 |         if (this->center_ == nullptr)  // abandon mission! | 
|---|
| [10114] | 180 |         { | 
|---|
 | 181 |             orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl; | 
|---|
 | 182 |             GSLevel::startMainMenu(); | 
|---|
 | 183 |             return; | 
|---|
| [10124] | 184 |         } | 
|---|
| [10114] | 185 |         // Call start for the parent class. | 
|---|
 | 186 |         Deathmatch::start(); | 
|---|
 | 187 |     } | 
|---|
| [10166] | 188 |  | 
|---|
| [10236] | 189 |     void DodgeRace::playerPreSpawn(PlayerInfo* player) | 
|---|
 | 190 |     { | 
|---|
| [11783] | 191 |         this->playerInfo_ = player; | 
|---|
| [10236] | 192 |         if(lives <= 0) | 
|---|
 | 193 |         { | 
|---|
 | 194 |             this->end(); | 
|---|
 | 195 |         } | 
|---|
| [10166] | 196 |  | 
|---|
| [10236] | 197 |         // Reset all the cubes | 
|---|
 | 198 |         /* | 
|---|
 | 199 |         orxout() << "prespawn" << endl; | 
|---|
 | 200 |         for(int i=0; i< cubeList.size();i++) | 
|---|
 | 201 |         { | 
|---|
 | 202 |             cubeList.at(i)->destroy(); | 
|---|
 | 203 |             cubeList.erase(cubeList.begin()+i); | 
|---|
 | 204 |         } | 
|---|
 | 205 |         cubeList.clear(); | 
|---|
| [10166] | 206 |         lives = 1; | 
|---|
 | 207 |         point = 0; | 
|---|
 | 208 |         lastPosition = 0; | 
|---|
 | 209 |         */ | 
|---|
| [10236] | 210 |     } | 
|---|
| [10166] | 211 |  | 
|---|
| [10114] | 212 |     void DodgeRace::addPoints(int numPoints) | 
|---|
 | 213 |     { | 
|---|
 | 214 |         if (!bEndGame) | 
|---|
 | 215 |         { | 
|---|
 | 216 |             point += numPoints * multiplier; | 
|---|
 | 217 |             b_combo = true; | 
|---|
 | 218 |         } | 
|---|
 | 219 |     } | 
|---|
| [10124] | 220 |  | 
|---|
| [10114] | 221 |     void DodgeRace::end() | 
|---|
 | 222 |     { | 
|---|
 | 223 |         // DON'T CALL THIS! | 
|---|
 | 224 |         //      Deathmatch::end(); | 
|---|
 | 225 |         // It will misteriously crash the game! | 
|---|
 | 226 |         // Instead startMainMenu, this won't crash. | 
|---|
| [11716] | 227 |         if (Highscore::exists()) | 
|---|
 | 228 |         { | 
|---|
 | 229 |             int score = this->getPoints(); | 
|---|
| [11783] | 230 |             Highscore::getInstance().storeScore("Dodge Race", score, this->playerInfo_); | 
|---|
| [11716] | 231 |         } | 
|---|
| [10114] | 232 |         GSLevel::startMainMenu(); | 
|---|
| [10124] | 233 |     } | 
|---|
| [10114] | 234 | } | 
|---|