[11836] | 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 | /** |
---|
[11837] | 30 | @file OrxyRoad.cc |
---|
| 31 | @brief Implementation of the OrxyRoad class. |
---|
[11836] | 32 | */ |
---|
| 33 | |
---|
[11837] | 34 | #include "OrxyRoad.h" |
---|
| 35 | #include "OrxyRoadShip.h" // Necessary for getPlayer function. Do NOT include this in Header! |
---|
| 36 | #include "OrxyRoadCube.h" |
---|
[11836] | 37 | #include "core/CoreIncludes.h" |
---|
| 38 | #include "Highscore.h" |
---|
| 39 | #include "infos/PlayerInfo.h" |
---|
| 40 | |
---|
| 41 | namespace orxonox |
---|
| 42 | { |
---|
[11837] | 43 | RegisterUnloadableClass(OrxyRoad); |
---|
[11836] | 44 | |
---|
[11837] | 45 | OrxyRoad::OrxyRoad(Context* context) : Deathmatch(context) |
---|
[11836] | 46 | { |
---|
[11837] | 47 | RegisterObject(OrxyRoad); |
---|
[11836] | 48 | |
---|
| 49 | bEndGame = false; |
---|
| 50 | lives = 1; |
---|
| 51 | level = 1; |
---|
| 52 | point = 0; |
---|
| 53 | bShowLevel = false; |
---|
| 54 | multiplier = 1; |
---|
| 55 | b_combo = false; |
---|
| 56 | counter = 5000; |
---|
| 57 | pattern = 1; |
---|
| 58 | lastPosition = 0; |
---|
| 59 | // spawn enemy every 3.5 seconds |
---|
[11837] | 60 | //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&OrxyRoad::spawnEnemy, this))); |
---|
| 61 | comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&OrxyRoad::comboControll, this))); |
---|
[11836] | 62 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 63 | this->center_ = nullptr; |
---|
| 64 | |
---|
[11837] | 65 | this->setHUDTemplate("OrxyRoadHUD"); |
---|
[11836] | 66 | } |
---|
| 67 | |
---|
[11837] | 68 | void OrxyRoad::levelUp() |
---|
[11836] | 69 | { |
---|
| 70 | level++; |
---|
| 71 | if (getPlayer() != nullptr) |
---|
| 72 | { |
---|
| 73 | for (int i = 0; i < 7; i++) |
---|
| 74 | { |
---|
| 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 | |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | addPoints(multiplier * 42); |
---|
| 86 | multiplier *= 2; |
---|
| 87 | toggleShowLevel(); |
---|
[11837] | 88 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&OrxyRoad::toggleShowLevel, this))); |
---|
[11836] | 89 | } |
---|
| 90 | |
---|
[11837] | 91 | void OrxyRoad::tick(float dt) |
---|
[11836] | 92 | { |
---|
[11837] | 93 | OrxyRoadShip* player = this->getPlayer(); |
---|
[11836] | 94 | if (player != nullptr) |
---|
| 95 | { |
---|
| 96 | currentPosition = player->getWorldPosition().x; |
---|
| 97 | counter = counter + (currentPosition - lastPosition); |
---|
| 98 | lastPosition = currentPosition; |
---|
| 99 | point = (int) currentPosition; |
---|
| 100 | player->speed = 830.0f - (point / 1000); |
---|
| 101 | |
---|
| 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 | } |
---|
| 110 | |
---|
| 111 | if(counter >= 3000) |
---|
| 112 | { |
---|
| 113 | counter = 0; |
---|
| 114 | for(int i = 0; i<6; i++) |
---|
| 115 | { |
---|
[11837] | 116 | OrxyRoadCube* cube = new OrxyRoadCube(this->center_->getContext()); |
---|
[11836] | 117 | cubeList.push_back(cube); |
---|
| 118 | switch(pattern) |
---|
| 119 | { |
---|
[11837] | 120 | case 1: cube->addTemplate("OrxyRoadCube01"); |
---|
[11836] | 121 | break; |
---|
[11837] | 122 | case 2: cube->addTemplate("OrxyRoadCube02"); |
---|
[11836] | 123 | break; |
---|
| 124 | |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200))); |
---|
| 128 | //stEntity->setScale3D(50,50,50); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | pattern %= 2; |
---|
| 133 | pattern ++; |
---|
| 134 | |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | } |
---|
[11837] | 138 | SUPER(OrxyRoad, tick, dt); |
---|
[11836] | 139 | } |
---|
| 140 | |
---|
[11837] | 141 | OrxyRoadShip* OrxyRoad::getPlayer() |
---|
[11836] | 142 | { |
---|
[11837] | 143 | for (OrxyRoadShip* ship : ObjectList<OrxyRoadShip>()) |
---|
[11836] | 144 | { |
---|
| 145 | return ship; |
---|
| 146 | } |
---|
| 147 | return nullptr; |
---|
| 148 | } |
---|
| 149 | |
---|
[11837] | 150 | void OrxyRoad::costLife() |
---|
[11836] | 151 | { |
---|
[11837] | 152 | //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this))); |
---|
[11836] | 153 | lives = 0; |
---|
| 154 | }; |
---|
| 155 | |
---|
[11837] | 156 | void OrxyRoad::comboControll() |
---|
[11836] | 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 | |
---|
[11837] | 166 | void OrxyRoad::start() |
---|
[11836] | 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_ == nullptr) // abandon mission! |
---|
| 180 | { |
---|
[11837] | 181 | orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl; |
---|
[11836] | 182 | GSLevel::startMainMenu(); |
---|
| 183 | return; |
---|
| 184 | } |
---|
| 185 | // Call start for the parent class. |
---|
| 186 | Deathmatch::start(); |
---|
| 187 | } |
---|
| 188 | |
---|
[11837] | 189 | void OrxyRoad::playerPreSpawn(PlayerInfo* player) |
---|
[11836] | 190 | { |
---|
| 191 | this->playerInfo_ = player; |
---|
| 192 | if(lives <= 0) |
---|
| 193 | { |
---|
| 194 | this->end(); |
---|
| 195 | } |
---|
| 196 | |
---|
| 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(); |
---|
| 206 | lives = 1; |
---|
| 207 | point = 0; |
---|
| 208 | lastPosition = 0; |
---|
| 209 | */ |
---|
| 210 | } |
---|
| 211 | |
---|
[11837] | 212 | void OrxyRoad::addPoints(int numPoints) |
---|
[11836] | 213 | { |
---|
| 214 | if (!bEndGame) |
---|
| 215 | { |
---|
| 216 | point += numPoints * multiplier; |
---|
| 217 | b_combo = true; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | |
---|
[11837] | 221 | void OrxyRoad::end() |
---|
[11836] | 222 | { |
---|
| 223 | // DON'T CALL THIS! |
---|
| 224 | // Deathmatch::end(); |
---|
| 225 | // It will misteriously crash the game! |
---|
| 226 | // Instead startMainMenu, this won't crash. |
---|
| 227 | if (Highscore::exists()) |
---|
| 228 | { |
---|
| 229 | int score = this->getPoints(); |
---|
| 230 | Highscore::getInstance().storeScore("Dodge Race", score, this->playerInfo_); |
---|
| 231 | } |
---|
| 232 | GSLevel::startMainMenu(); |
---|
| 233 | } |
---|
| 234 | } |
---|