[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: |
---|
[11998] | 23 | * Sebastian Hirsch |
---|
| 24 | * Robin Jacobs |
---|
| 25 | * Co-authors: |
---|
[11836] | 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; |
---|
[11935] | 59 | roadWidth = 3000; |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|
[11836] | 65 | // spawn enemy every 3.5 seconds |
---|
[11837] | 66 | //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&OrxyRoad::spawnEnemy, this))); |
---|
| 67 | comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&OrxyRoad::comboControll, this))); |
---|
[11836] | 68 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
| 69 | this->center_ = nullptr; |
---|
| 70 | |
---|
[11837] | 71 | this->setHUDTemplate("OrxyRoadHUD"); |
---|
[11836] | 72 | } |
---|
| 73 | |
---|
[11837] | 74 | void OrxyRoad::levelUp() |
---|
[11836] | 75 | { |
---|
| 76 | level++; |
---|
| 77 | if (getPlayer() != nullptr) |
---|
| 78 | { |
---|
| 79 | for (int i = 0; i < 7; i++) |
---|
| 80 | { |
---|
| 81 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
| 82 | chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
| 83 | chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
| 84 | chunk5->setScale(10); |
---|
| 85 | chunk5->setEffect1("Orxonox/explosion2b"); |
---|
| 86 | chunk5->setEffect2("Orxonox/smoke6"); |
---|
| 87 | chunk5->Explode(); |
---|
| 88 | |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | addPoints(multiplier * 42); |
---|
| 92 | multiplier *= 2; |
---|
| 93 | toggleShowLevel(); |
---|
[11837] | 94 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&OrxyRoad::toggleShowLevel, this))); |
---|
[11836] | 95 | } |
---|
[11935] | 96 | int OrxyRoad::generateStreet(int type, OrxyRoadShip* player){ |
---|
[11972] | 97 | int trafficVelocities[]= {200,1400,500, 300}; |
---|
[11985] | 98 | int velocityVariation[] = {40,80,100,20}; |
---|
[11996] | 99 | int numObjects[] = {30,30,30,30}; // default, spaceship, satellite, asteroid per track |
---|
[11935] | 100 | int streetSize[] = {3 , 1, 2, 4}; |
---|
[11972] | 101 | int trackWidth = 700; |
---|
[11935] | 102 | |
---|
| 103 | for(int j = 0; j < streetSize[type]; j++)//width of Street |
---|
| 104 | { |
---|
[11972] | 105 | int sign = rand()%2; |
---|
| 106 | |
---|
[11985] | 107 | //orxout(internal_error) << sign<< endl; |
---|
[11972] | 108 | |
---|
| 109 | |
---|
| 110 | |
---|
[11935] | 111 | for(int i = -numObjects[type]/2; i<numObjects[type]/2; i++) |
---|
| 112 | { |
---|
| 113 | OrxyRoadCube* cube = new OrxyRoadCube(this->center_->getContext()); |
---|
| 114 | cubeList.push_back(cube); |
---|
[11972] | 115 | int templateType = rand()%2; |
---|
[11996] | 116 | |
---|
[11935] | 117 | switch(type) |
---|
| 118 | { |
---|
[11972] | 119 | case 0 : |
---|
| 120 | if(templateType >=1){ |
---|
[11975] | 121 | cube->addTemplate("asteroid1");//default |
---|
[11972] | 122 | }else { |
---|
[11975] | 123 | cube->addTemplate("satellite");//default |
---|
[11972] | 124 | } |
---|
[11935] | 125 | break; |
---|
| 126 | case 1: |
---|
[11972] | 127 | if(templateType >=1){ |
---|
[11975] | 128 | cube->addTemplate("spaceshuttle");//spaceship1 |
---|
[11972] | 129 | }else { |
---|
[11975] | 130 | cube->addTemplate("spaceshuttle");//spaceship2 |
---|
[11972] | 131 | } |
---|
| 132 | |
---|
[11836] | 133 | |
---|
[11935] | 134 | break; |
---|
[11972] | 135 | case 2: |
---|
| 136 | if(templateType >=1){ |
---|
[11975] | 137 | cube->addTemplate("satellite");//satellite |
---|
[11972] | 138 | }else { |
---|
[11975] | 139 | cube->addTemplate("satellite");//satellite |
---|
[11996] | 140 | } |
---|
[11972] | 141 | |
---|
| 142 | |
---|
[11935] | 143 | break; |
---|
[11972] | 144 | case 3: |
---|
| 145 | if(templateType >=1){ |
---|
[11975] | 146 | cube->addTemplate("asteroid1");//asteroid |
---|
[11972] | 147 | }else { |
---|
[11975] | 148 | cube->addTemplate("asteroid2");//asteroid |
---|
[11972] | 149 | } |
---|
[11935] | 150 | |
---|
[11972] | 151 | |
---|
[11935] | 152 | } |
---|
| 153 | |
---|
[11985] | 154 | int posVar = rand()%2; |
---|
| 155 | int distance = trafficVelocities[type]*3 +posVar*trafficVelocities[type]/10; //Todo better calculation of distance between objects |
---|
[11935] | 156 | |
---|
[11985] | 157 | cube->setPosition(player->getWorldPosition() + Vector3(2000.0f+j*trackWidth, 0.0f, i*distance)); |
---|
[11935] | 158 | |
---|
| 159 | /* experimental */ |
---|
[11972] | 160 | |
---|
[11935] | 161 | |
---|
[11972] | 162 | if(sign>=1){ |
---|
[11985] | 163 | cube->setVelocity(0,0,trafficVelocities[type]*level+velocityVariation[j%3]); |
---|
[11972] | 164 | } else{ |
---|
[11985] | 165 | cube->setVelocity(0,0,-trafficVelocities[type]*level+velocityVariation[j%3]); |
---|
[11972] | 166 | } |
---|
| 167 | |
---|
[11935] | 168 | |
---|
[11972] | 169 | |
---|
| 170 | |
---|
[11935] | 171 | /* experimental */ |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | //stEntity->setScale3D(50,50,50); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | return streetSize[type] * trackWidth; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | |
---|
[11837] | 183 | void OrxyRoad::tick(float dt) |
---|
[11836] | 184 | { |
---|
[11934] | 185 | SUPER(OrxyRoad, tick, dt); |
---|
| 186 | |
---|
[11837] | 187 | OrxyRoadShip* player = this->getPlayer(); |
---|
[11836] | 188 | if (player != nullptr) |
---|
| 189 | { |
---|
| 190 | currentPosition = player->getWorldPosition().x; |
---|
| 191 | counter = counter + (currentPosition - lastPosition); |
---|
| 192 | lastPosition = currentPosition; |
---|
| 193 | point = (int) currentPosition; |
---|
| 194 | player->speed = 830.0f - (point / 1000); |
---|
| 195 | |
---|
| 196 | for(unsigned int i=0; i < cubeList.size();i++) |
---|
| 197 | { |
---|
[11985] | 198 | if(cubeList.at(i)->getPosition().x < currentPosition-500) |
---|
[11836] | 199 | { |
---|
| 200 | cubeList.at(i)->destroy(); |
---|
| 201 | cubeList.erase(cubeList.begin()+i); |
---|
| 202 | } |
---|
| 203 | } |
---|
| 204 | |
---|
[11935] | 205 | |
---|
| 206 | |
---|
| 207 | |
---|
[11985] | 208 | if(counter >= roadWidth-200) |
---|
[11836] | 209 | { |
---|
[11935] | 210 | int type = rand() % 4; |
---|
[11996] | 211 | //orxout(user_info) << "Random : "<<type<< endl; |
---|
[11836] | 212 | |
---|
[11935] | 213 | roadWidth = generateStreet(type,player);//Generate street to specific type type = 0 default, type = 1 space ship type = 2 statellite/cubes, type = 3 asteroids |
---|
| 214 | counter = 0; |
---|
[11836] | 215 | |
---|
[11914] | 216 | //pattern %= 2; |
---|
| 217 | //pattern ++; |
---|
[11836] | 218 | |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
[11837] | 224 | OrxyRoadShip* OrxyRoad::getPlayer() |
---|
[11836] | 225 | { |
---|
[11837] | 226 | for (OrxyRoadShip* ship : ObjectList<OrxyRoadShip>()) |
---|
[11836] | 227 | { |
---|
| 228 | return ship; |
---|
| 229 | } |
---|
| 230 | return nullptr; |
---|
| 231 | } |
---|
| 232 | |
---|
[11837] | 233 | void OrxyRoad::costLife() |
---|
[11836] | 234 | { |
---|
[11837] | 235 | //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&OrxyRoad::end, this))); |
---|
[11836] | 236 | lives = 0; |
---|
| 237 | }; |
---|
| 238 | |
---|
[11837] | 239 | void OrxyRoad::comboControll() |
---|
[11836] | 240 | { |
---|
| 241 | if (b_combo) |
---|
| 242 | multiplier++; |
---|
| 243 | // if no combo was performed before, reset multiplier |
---|
| 244 | else |
---|
| 245 | multiplier = 1; |
---|
| 246 | b_combo = false; |
---|
| 247 | } |
---|
| 248 | |
---|
[11837] | 249 | void OrxyRoad::start() |
---|
[11836] | 250 | { |
---|
| 251 | orxout() << "start" << endl; |
---|
| 252 | for(unsigned int i=0; i< cubeList.size();i++) |
---|
| 253 | { |
---|
| 254 | cubeList.at(i)->destroy(); |
---|
| 255 | cubeList.erase(cubeList.begin()+i); |
---|
| 256 | |
---|
| 257 | } |
---|
| 258 | cubeList.clear(); |
---|
| 259 | // Set variable to temporarily force the player to spawn. |
---|
| 260 | this->bForceSpawn_ = false; |
---|
| 261 | |
---|
| 262 | if (this->center_ == nullptr) // abandon mission! |
---|
| 263 | { |
---|
[11837] | 264 | orxout(internal_error) << "OrxyRoad: No Centerpoint specified." << endl; |
---|
[11836] | 265 | GSLevel::startMainMenu(); |
---|
| 266 | return; |
---|
| 267 | } |
---|
[11899] | 268 | Deathmatch::start(); |
---|
[11836] | 269 | } |
---|
| 270 | |
---|
[11837] | 271 | void OrxyRoad::playerPreSpawn(PlayerInfo* player) |
---|
[11836] | 272 | { |
---|
| 273 | this->playerInfo_ = player; |
---|
| 274 | if(lives <= 0) |
---|
| 275 | { |
---|
| 276 | this->end(); |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | // Reset all the cubes |
---|
| 280 | /* |
---|
| 281 | orxout() << "prespawn" << endl; |
---|
| 282 | for(int i=0; i< cubeList.size();i++) |
---|
| 283 | { |
---|
| 284 | cubeList.at(i)->destroy(); |
---|
| 285 | cubeList.erase(cubeList.begin()+i); |
---|
| 286 | } |
---|
| 287 | cubeList.clear(); |
---|
| 288 | lives = 1; |
---|
| 289 | point = 0; |
---|
| 290 | lastPosition = 0; |
---|
| 291 | */ |
---|
| 292 | } |
---|
| 293 | |
---|
[11837] | 294 | void OrxyRoad::addPoints(int numPoints) |
---|
[11836] | 295 | { |
---|
| 296 | if (!bEndGame) |
---|
| 297 | { |
---|
| 298 | point += numPoints * multiplier; |
---|
| 299 | b_combo = true; |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | |
---|
[11837] | 303 | void OrxyRoad::end() |
---|
[11836] | 304 | { |
---|
| 305 | // DON'T CALL THIS! |
---|
| 306 | // Deathmatch::end(); |
---|
| 307 | // It will misteriously crash the game! |
---|
| 308 | // Instead startMainMenu, this won't crash. |
---|
| 309 | if (Highscore::exists()) |
---|
| 310 | { |
---|
| 311 | int score = this->getPoints(); |
---|
[11899] | 312 | Highscore::getInstance().storeScore("Orxy Road ", score, this->playerInfo_); |
---|
[11836] | 313 | } |
---|
| 314 | GSLevel::startMainMenu(); |
---|
| 315 | } |
---|
| 316 | } |
---|