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