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