| [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" | 
|---|
| [10114] | 39 |  | 
|---|
 | 40 | namespace orxonox | 
|---|
 | 41 | { | 
|---|
| [10118] | 42 |     RegisterUnloadableClass(DodgeRace); | 
|---|
| [10114] | 43 |  | 
|---|
 | 44 |     DodgeRace::DodgeRace(Context* context) : Deathmatch(context) | 
|---|
 | 45 |     { | 
|---|
 | 46 |         RegisterObject(DodgeRace); | 
|---|
| [10166] | 47 |  | 
|---|
| [10114] | 48 |         bEndGame = false; | 
|---|
| [10166] | 49 |         lives = 1; | 
|---|
| [10114] | 50 |         level = 1; | 
|---|
 | 51 |         point = 0; | 
|---|
 | 52 |         bShowLevel = false; | 
|---|
 | 53 |         multiplier = 1; | 
|---|
 | 54 |         b_combo = false; | 
|---|
| [10166] | 55 |         counter = 5000; | 
|---|
| [10152] | 56 |         pattern = 1; | 
|---|
| [10135] | 57 |         lastPosition = 0; | 
|---|
| [10114] | 58 |         // spawn enemy every 3.5 seconds | 
|---|
 | 59 |         //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this))); | 
|---|
| [10118] | 60 |         comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this))); | 
|---|
| [10624] | 61 |         this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 | 
|---|
| [11071] | 62 |         this->center_ = nullptr; | 
|---|
| [10624] | 63 |  | 
|---|
 | 64 |         this->setHUDTemplate("DodgeRaceHUD"); | 
|---|
| [10114] | 65 |     } | 
|---|
 | 66 |  | 
|---|
 | 67 |     void DodgeRace::levelUp() | 
|---|
 | 68 |     { | 
|---|
| [10117] | 69 |         level++; | 
|---|
| [11071] | 70 |         if (getPlayer() != nullptr) | 
|---|
| [10114] | 71 |         { | 
|---|
 | 72 |             for (int i = 0; i < 7; i++) | 
|---|
 | 73 |             { | 
|---|
| [11052] | 74 |                 WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); | 
|---|
 | 75 |                 chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); | 
|---|
 | 76 |                 chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity() | 
|---|
 | 77 |                 chunk5->setScale(10); | 
|---|
 | 78 |                 chunk5->setEffect1("Orxonox/explosion2b"); | 
|---|
 | 79 |                 chunk5->setEffect2("Orxonox/smoke6"); | 
|---|
 | 80 |                 chunk5->Explode(); | 
|---|
 | 81 |  | 
|---|
| [10114] | 82 |             } | 
|---|
| [10124] | 83 |         } | 
|---|
| [10114] | 84 |         addPoints(multiplier * 42); | 
|---|
 | 85 |         multiplier *= 2; | 
|---|
 | 86 |         toggleShowLevel(); | 
|---|
| [10117] | 87 |         showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this))); | 
|---|
| [10114] | 88 |     } | 
|---|
 | 89 |  | 
|---|
| [10135] | 90 |     void DodgeRace::tick(float dt) | 
|---|
 | 91 |     { | 
|---|
| [11071] | 92 |         if (getPlayer() != nullptr) | 
|---|
| [10236] | 93 |         { | 
|---|
 | 94 |             currentPosition = getPlayer()->getWorldPosition().x; | 
|---|
 | 95 |             counter = counter + (currentPosition - lastPosition); | 
|---|
 | 96 |             lastPosition = currentPosition; | 
|---|
 | 97 |             point = (int) currentPosition; | 
|---|
 | 98 |             getPlayer()->speed = 830.0f - (point / 1000); | 
|---|
| [10135] | 99 |  | 
|---|
| [10236] | 100 |             for(unsigned int i=0; i < cubeList.size();i++) | 
|---|
 | 101 |             { | 
|---|
 | 102 |                 if(cubeList.at(i)->getPosition().x < currentPosition-3000) | 
|---|
 | 103 |                 { | 
|---|
 | 104 |                     cubeList.at(i)->destroy(); | 
|---|
 | 105 |                     cubeList.erase(cubeList.begin()+i); | 
|---|
 | 106 |                 } | 
|---|
 | 107 |             } | 
|---|
| [10152] | 108 |  | 
|---|
| [10236] | 109 |             if(counter >= 3000) | 
|---|
 | 110 |             { | 
|---|
 | 111 |                 counter = 0; | 
|---|
 | 112 |                 for(int i = 0; i<6; i++) | 
|---|
 | 113 |                 { | 
|---|
| [10624] | 114 |                     DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext()); | 
|---|
| [10236] | 115 |                     cubeList.push_back(cube); | 
|---|
 | 116 |                     switch(pattern) | 
|---|
 | 117 |                     { | 
|---|
 | 118 |                     case 1: cube->addTemplate("DodgeRaceCube01"); | 
|---|
 | 119 |                     break; | 
|---|
 | 120 |                     case 2: cube->addTemplate("DodgeRaceCube02"); | 
|---|
 | 121 |                     break; | 
|---|
| [10135] | 122 |  | 
|---|
| [10236] | 123 |                     } | 
|---|
| [10152] | 124 |  | 
|---|
| [10236] | 125 |                     cube->setPosition(getPlayer()->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200))); | 
|---|
 | 126 |                     //stEntity->setScale3D(50,50,50); | 
|---|
 | 127 |                 } | 
|---|
| [10152] | 128 |  | 
|---|
 | 129 |  | 
|---|
| [10236] | 130 |                 pattern %= 2; | 
|---|
 | 131 |                 pattern ++; | 
|---|
| [10152] | 132 |  | 
|---|
| [10236] | 133 |             } | 
|---|
| [10152] | 134 |  | 
|---|
| [10236] | 135 |         } | 
|---|
 | 136 |         SUPER(DodgeRace, tick, dt); | 
|---|
| [10135] | 137 |     } | 
|---|
 | 138 |  | 
|---|
| [10624] | 139 |     DodgeRaceShip* DodgeRace::getPlayer() | 
|---|
| [10114] | 140 |     { | 
|---|
| [11071] | 141 |         if (player == nullptr) | 
|---|
| [10114] | 142 |         { | 
|---|
| [11071] | 143 |             for (DodgeRaceShip* ship : ObjectList<DodgeRaceShip>()) | 
|---|
| [10117] | 144 |             { | 
|---|
| [11071] | 145 |                 player = ship; | 
|---|
| [10117] | 146 |             } | 
|---|
| [10114] | 147 |         } | 
|---|
 | 148 |         return player; | 
|---|
 | 149 |     } | 
|---|
 | 150 |  | 
|---|
 | 151 |     void DodgeRace::costLife() | 
|---|
 | 152 |     { | 
|---|
| [10236] | 153 |         //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this))); | 
|---|
 | 154 |         lives = 0; | 
|---|
| [10114] | 155 |     }; | 
|---|
| [10124] | 156 |  | 
|---|
| [10114] | 157 |     void DodgeRace::comboControll() | 
|---|
 | 158 |     { | 
|---|
 | 159 |         if (b_combo) | 
|---|
 | 160 |             multiplier++; | 
|---|
 | 161 |         // if no combo was performed before, reset multiplier | 
|---|
 | 162 |         else | 
|---|
 | 163 |             multiplier = 1; | 
|---|
 | 164 |         b_combo = false; | 
|---|
 | 165 |     } | 
|---|
 | 166 |  | 
|---|
 | 167 |     void DodgeRace::start() | 
|---|
 | 168 |     { | 
|---|
| [10236] | 169 |         orxout() << "start" << endl; | 
|---|
 | 170 |         for(unsigned int i=0; i< cubeList.size();i++) | 
|---|
 | 171 |         { | 
|---|
 | 172 |             cubeList.at(i)->destroy(); | 
|---|
 | 173 |             cubeList.erase(cubeList.begin()+i); | 
|---|
| [10152] | 174 |  | 
|---|
| [10236] | 175 |         } | 
|---|
| [10152] | 176 |         cubeList.clear(); | 
|---|
| [10114] | 177 |         // Set variable to temporarily force the player to spawn. | 
|---|
| [10166] | 178 |         this->bForceSpawn_ = false; | 
|---|
| [10114] | 179 |  | 
|---|
| [11071] | 180 |         if (this->center_ == nullptr)  // abandon mission! | 
|---|
| [10114] | 181 |         { | 
|---|
 | 182 |             orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl; | 
|---|
 | 183 |             GSLevel::startMainMenu(); | 
|---|
 | 184 |             return; | 
|---|
| [10124] | 185 |         } | 
|---|
| [10114] | 186 |         // Call start for the parent class. | 
|---|
 | 187 |         Deathmatch::start(); | 
|---|
 | 188 |     } | 
|---|
| [10166] | 189 |  | 
|---|
| [10236] | 190 |     void DodgeRace::playerPreSpawn(PlayerInfo* player) | 
|---|
 | 191 |     { | 
|---|
 | 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. | 
|---|
| [11356] | 227 |         if (Highscore::exists()){ | 
|---|
 | 228 |                     int score = this->getPoints(); | 
|---|
 | 229 |                     if(score > Highscore::getInstance().getHighestScoreOfGame("Dodge Race"))  | 
|---|
 | 230 |                         Highscore::getInstance().storeHighscore("Dodge Race",score); | 
|---|
 | 231 |  | 
|---|
 | 232 |           } | 
|---|
| [10114] | 233 |         GSLevel::startMainMenu(); | 
|---|
| [10124] | 234 |     } | 
|---|
| [10114] | 235 | } | 
|---|