[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 | |
---|
[11899] | 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; |
---|
[11914] | 57 | pattern = 3; |
---|
[11836] | 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 | { |
---|
[11934] | 93 | SUPER(OrxyRoad, tick, dt); |
---|
| 94 | |
---|
[11837] | 95 | OrxyRoadShip* player = this->getPlayer(); |
---|
[11836] | 96 | if (player != nullptr) |
---|
| 97 | { |
---|
| 98 | currentPosition = player->getWorldPosition().x; |
---|
| 99 | counter = counter + (currentPosition - lastPosition); |
---|
| 100 | lastPosition = currentPosition; |
---|
| 101 | point = (int) currentPosition; |
---|
| 102 | player->speed = 830.0f - (point / 1000); |
---|
| 103 | |
---|
| 104 | for(unsigned int i=0; i < cubeList.size();i++) |
---|
| 105 | { |
---|
| 106 | if(cubeList.at(i)->getPosition().x < currentPosition-3000) |
---|
| 107 | { |
---|
| 108 | cubeList.at(i)->destroy(); |
---|
| 109 | cubeList.erase(cubeList.begin()+i); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | if(counter >= 3000) |
---|
| 114 | { |
---|
| 115 | counter = 0; |
---|
[11916] | 116 | for(int j = 0; j < 3; j++)//deepth cube |
---|
[11836] | 117 | { |
---|
[11914] | 118 | for(int i = -30; i<30; i++) |
---|
[11836] | 119 | { |
---|
[11914] | 120 | OrxyRoadCube* cube = new OrxyRoadCube(this->center_->getContext()); |
---|
| 121 | cubeList.push_back(cube); |
---|
| 122 | switch(pattern) |
---|
| 123 | { |
---|
| 124 | case 1: cube->addTemplate("OrxyRoadCube01"); |
---|
| 125 | break; |
---|
| 126 | case 2: cube->addTemplate("OrxyRoadCube01"); |
---|
| 127 | break; |
---|
| 128 | case 3: cube->addTemplate("SingleOrxyRoadCube"); |
---|
[11836] | 129 | |
---|
[11914] | 130 | } |
---|
[11836] | 131 | |
---|
[11914] | 132 | cube->setPosition(player->getWorldPosition() + Vector3(1000.0f+j*800.0f, 0.0f, i*600.0f+j*300)); |
---|
| 133 | |
---|
| 134 | /* experimental */ |
---|
[11886] | 135 | |
---|
[11914] | 136 | cube->setVelocity(0,0,500); |
---|
[11886] | 137 | |
---|
[11914] | 138 | /* experimental */ |
---|
[11886] | 139 | |
---|
| 140 | |
---|
[11914] | 141 | //stEntity->setScale3D(50,50,50); |
---|
| 142 | } |
---|
[11836] | 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
[11914] | 146 | //pattern %= 2; |
---|
| 147 | //pattern ++; |
---|
[11836] | 148 | |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | |
---|
[11837] | 154 | OrxyRoadShip* OrxyRoad::getPlayer() |
---|
[11836] | 155 | { |
---|
[11837] | 156 | for (OrxyRoadShip* ship : ObjectList<OrxyRoadShip>()) |
---|
[11836] | 157 | { |
---|
| 158 | return ship; |
---|
| 159 | } |
---|
| 160 | return nullptr; |
---|
| 161 | } |
---|
| 162 | |
---|
[11837] | 163 | void OrxyRoad::costLife() |
---|
[11836] | 164 | { |
---|
[11837] | 165 | //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this))); |
---|
[11836] | 166 | lives = 0; |
---|
| 167 | }; |
---|
| 168 | |
---|
[11837] | 169 | void OrxyRoad::comboControll() |
---|
[11836] | 170 | { |
---|
| 171 | if (b_combo) |
---|
| 172 | multiplier++; |
---|
| 173 | // if no combo was performed before, reset multiplier |
---|
| 174 | else |
---|
| 175 | multiplier = 1; |
---|
| 176 | b_combo = false; |
---|
| 177 | } |
---|
| 178 | |
---|
[11837] | 179 | void OrxyRoad::start() |
---|
[11836] | 180 | { |
---|
| 181 | orxout() << "start" << endl; |
---|
| 182 | for(unsigned int i=0; i< cubeList.size();i++) |
---|
| 183 | { |
---|
| 184 | cubeList.at(i)->destroy(); |
---|
| 185 | cubeList.erase(cubeList.begin()+i); |
---|
| 186 | |
---|
| 187 | } |
---|
| 188 | cubeList.clear(); |
---|
| 189 | // Set variable to temporarily force the player to spawn. |
---|
| 190 | this->bForceSpawn_ = false; |
---|
| 191 | |
---|
| 192 | if (this->center_ == nullptr) // abandon mission! |
---|
| 193 | { |
---|
[11837] | 194 | orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl; |
---|
[11836] | 195 | GSLevel::startMainMenu(); |
---|
| 196 | return; |
---|
| 197 | } |
---|
[11899] | 198 | Deathmatch::start(); |
---|
[11836] | 199 | } |
---|
| 200 | |
---|
[11837] | 201 | void OrxyRoad::playerPreSpawn(PlayerInfo* player) |
---|
[11836] | 202 | { |
---|
| 203 | this->playerInfo_ = player; |
---|
| 204 | if(lives <= 0) |
---|
| 205 | { |
---|
| 206 | this->end(); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | // Reset all the cubes |
---|
| 210 | /* |
---|
| 211 | orxout() << "prespawn" << endl; |
---|
| 212 | for(int i=0; i< cubeList.size();i++) |
---|
| 213 | { |
---|
| 214 | cubeList.at(i)->destroy(); |
---|
| 215 | cubeList.erase(cubeList.begin()+i); |
---|
| 216 | } |
---|
| 217 | cubeList.clear(); |
---|
| 218 | lives = 1; |
---|
| 219 | point = 0; |
---|
| 220 | lastPosition = 0; |
---|
| 221 | */ |
---|
| 222 | } |
---|
| 223 | |
---|
[11837] | 224 | void OrxyRoad::addPoints(int numPoints) |
---|
[11836] | 225 | { |
---|
| 226 | if (!bEndGame) |
---|
| 227 | { |
---|
| 228 | point += numPoints * multiplier; |
---|
| 229 | b_combo = true; |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
[11837] | 233 | void OrxyRoad::end() |
---|
[11836] | 234 | { |
---|
| 235 | // DON'T CALL THIS! |
---|
| 236 | // Deathmatch::end(); |
---|
| 237 | // It will misteriously crash the game! |
---|
| 238 | // Instead startMainMenu, this won't crash. |
---|
| 239 | if (Highscore::exists()) |
---|
| 240 | { |
---|
| 241 | int score = this->getPoints(); |
---|
[11899] | 242 | Highscore::getInstance().storeScore("Orxy Road ", score, this->playerInfo_); |
---|
[11836] | 243 | } |
---|
| 244 | GSLevel::startMainMenu(); |
---|
| 245 | } |
---|
| 246 | } |
---|