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