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