[10658] | 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: |
---|
[10930] | 23 | * Manuel Meier |
---|
[10658] | 24 | * Co-authors: |
---|
[11036] | 25 | * Cyrill Burgener |
---|
[10658] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | @file Hover.cc |
---|
[10930] | 31 | @brief Implementation of the Hover class. Sets up the whole Minigame |
---|
[10658] | 32 | */ |
---|
| 33 | |
---|
| 34 | #include "Hover.h" |
---|
[11151] | 35 | #include "chat/ChatManager.h" |
---|
[11041] | 36 | #include "HoverOrigin.h" |
---|
[10708] | 37 | #include "HoverWall.h" |
---|
[11041] | 38 | #include "HoverFlag.h" |
---|
[11035] | 39 | #include "MazeGenerator.h" |
---|
[10658] | 40 | #include "core/CoreIncludes.h" |
---|
[11151] | 41 | #include "gamestates/GSLevel.h" |
---|
[11171] | 42 | #include "HoverShip.h" |
---|
[10658] | 43 | |
---|
[11163] | 44 | #include "pickup/PickupSpawner.h" |
---|
| 45 | #include "pickup/Pickup.h" |
---|
| 46 | |
---|
[10658] | 47 | namespace orxonox |
---|
| 48 | { |
---|
| 49 | RegisterUnloadableClass(Hover); |
---|
| 50 | |
---|
[10664] | 51 | Hover::Hover(Context* context) : Gametype(context) |
---|
[10658] | 52 | { |
---|
| 53 | RegisterObject(Hover); |
---|
[11035] | 54 | |
---|
[11071] | 55 | this->origin_ = nullptr; |
---|
[11043] | 56 | this->numberOfFlags_ = 1; |
---|
[11035] | 57 | this->firstTick_ = true; |
---|
[11151] | 58 | level = 1; //start at level 1 |
---|
| 59 | flagsTaken = 0;// took 0 flags in the beginning |
---|
[11171] | 60 | lives = 3; |
---|
[11035] | 61 | |
---|
[11151] | 62 | numCells = 0; |
---|
| 63 | cellSize = 0; |
---|
| 64 | cellHeight = 0; |
---|
| 65 | |
---|
[11192] | 66 | bShowLevel = false; |
---|
| 67 | |
---|
[11168] | 68 | totFlags = 0; |
---|
| 69 | |
---|
[10895] | 70 | this->setHUDTemplate("HoverHUD"); |
---|
[11151] | 71 | |
---|
[10658] | 72 | } |
---|
| 73 | |
---|
[11151] | 74 | void Hover::start() |
---|
[10658] | 75 | { |
---|
[11151] | 76 | Gametype::start(); |
---|
[11040] | 77 | if(this->firstTick_ && this->origin_) |
---|
[11035] | 78 | { |
---|
| 79 | this->firstTick_ = false; |
---|
[10787] | 80 | |
---|
[11151] | 81 | numCells = this->origin_->getNumCells(); |
---|
| 82 | cellSize = this->origin_->getCellSize(); |
---|
| 83 | cellHeight = this->origin_->getCellHeight(); |
---|
[11040] | 84 | |
---|
[11192] | 85 | /* |
---|
| 86 | bool occupiedCells[numCells][numCells]; |
---|
| 87 | |
---|
| 88 | for(int i = 0; i < numCells; i++) |
---|
| 89 | { |
---|
| 90 | for(int j = 0; j < numCells; j++) |
---|
| 91 | { |
---|
| 92 | occupiedCells[i][j] = false; |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | occupiedCells[0][0] = true; |
---|
| 96 | */ |
---|
| 97 | |
---|
[11040] | 98 | MazeGenerator generator(numCells); |
---|
[11035] | 99 | generator.generateMaze(); |
---|
| 100 | generator.renderMaze(); |
---|
[10787] | 101 | |
---|
[11035] | 102 | int* levelcode = generator.getLevelcode(); |
---|
[10787] | 103 | |
---|
[10928] | 104 | //Outer Walls |
---|
[11040] | 105 | for(int i = 0; i<numCells; i++){ |
---|
[11042] | 106 | (new HoverWall(origin_->getContext()))->init(0, i+1, cellSize, cellHeight, 1); |
---|
| 107 | (new HoverWall(origin_->getContext()))->init(numCells, i+1, cellSize, cellHeight, 1); |
---|
| 108 | (new HoverWall(origin_->getContext()))->init(i+1, 0, cellSize, cellHeight, 2); |
---|
| 109 | (new HoverWall(origin_->getContext()))->init(i+1, numCells, cellSize, cellHeight, 2); |
---|
[10928] | 110 | } |
---|
| 111 | |
---|
[11163] | 112 | |
---|
[11192] | 113 | //Ground |
---|
| 114 | for(int i = 0; i<numCells; i++){ |
---|
| 115 | for(int j = 0; j<numCells; j++){ |
---|
| 116 | StaticEntity* groundCell = new StaticEntity(origin_->getContext()); |
---|
[11163] | 117 | |
---|
[11192] | 118 | groundCell->addTemplate(origin_->getGroundTemplate()); |
---|
| 119 | groundCell->setPosition(get3dCoordinates(i,j,-60)); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | |
---|
[10930] | 126 | //Generate inner Walls according to levelcode |
---|
[11040] | 127 | for(int y=0; y<numCells; y++){ |
---|
| 128 | for(int x=0; x<numCells; x++){ |
---|
[11169] | 129 | switch(levelcode[ y * numCells + x ]) |
---|
| 130 | { |
---|
[11042] | 131 | case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1); |
---|
[11169] | 132 | break; |
---|
[11042] | 133 | case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1); |
---|
| 134 | case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0); |
---|
[11169] | 135 | default: |
---|
| 136 | break; |
---|
[10787] | 137 | } |
---|
[11169] | 138 | } |
---|
[10787] | 139 | } |
---|
| 140 | |
---|
[11192] | 141 | createFlags(); |
---|
[10900] | 142 | |
---|
[11182] | 143 | //Generate 3 PickupSpawners randomly (destroy hover pickup) |
---|
| 144 | for (int i = 0; i<3; i++) |
---|
[11163] | 145 | { |
---|
[11169] | 146 | PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext()); |
---|
| 147 | |
---|
[11192] | 148 | pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f)); |
---|
[11169] | 149 | pickupSpawner->setPickupTemplateName(origin_->getPickupTemplate()); |
---|
[11182] | 150 | pickupSpawner->setMaxSpawnedItems(3); |
---|
[11169] | 151 | pickupSpawner->setRespawnTime(30); |
---|
[11192] | 152 | pickupSpawner->setTriggerDistance(40); |
---|
[11169] | 153 | // Add pickup spawner to the pickup spawner list |
---|
| 154 | pickupSpawners_.push_back(pickupSpawner); |
---|
[11163] | 155 | } |
---|
[11177] | 156 | |
---|
[11182] | 157 | //Generate 3 PickupSpawners randomly (speed pickup) |
---|
| 158 | for (int i = 0; i<3; i++) |
---|
[11177] | 159 | { |
---|
| 160 | PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext()); |
---|
| 161 | |
---|
[11192] | 162 | pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f)); |
---|
[11182] | 163 | pickupSpawner->setPickupTemplateName(origin_->getPickupTemplateSpeed()); |
---|
| 164 | pickupSpawner->setMaxSpawnedItems(3); |
---|
[11177] | 165 | pickupSpawner->setRespawnTime(30); |
---|
[11192] | 166 | pickupSpawner->setTriggerDistance(40); |
---|
[11177] | 167 | // Add pickup spawner to the pickup spawner list |
---|
| 168 | pickupSpawners_.push_back(pickupSpawner); |
---|
| 169 | } |
---|
| 170 | |
---|
[11182] | 171 | //Generate 3 PickupSpawners randomly (shrink pickup) |
---|
| 172 | for (int i = 0; i<3; i++) |
---|
| 173 | { |
---|
| 174 | PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext()); |
---|
| 175 | |
---|
[11192] | 176 | pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 0.0f)); |
---|
[11182] | 177 | pickupSpawner->setPickupTemplateName(origin_->getPickupTemplateShrink()); |
---|
| 178 | pickupSpawner->setMaxSpawnedItems(3); |
---|
| 179 | pickupSpawner->setRespawnTime(30); |
---|
[11192] | 180 | pickupSpawner->setTriggerDistance(40); |
---|
[11182] | 181 | // Add pickup spawner to the pickup spawner list |
---|
| 182 | pickupSpawners_.push_back(pickupSpawner); |
---|
| 183 | } |
---|
| 184 | |
---|
[11177] | 185 | //***************************************************************************** |
---|
| 186 | |
---|
[11192] | 187 | //Generate destroyable crates randomly on field |
---|
[11182] | 188 | |
---|
[11192] | 189 | for (int i = 0; i<10; i++){ |
---|
[11177] | 190 | |
---|
[11192] | 191 | Pawn* crate = new Pawn(origin_->getContext()); |
---|
| 192 | |
---|
| 193 | crate->addTemplate(origin_->getObstacleTemplate()); |
---|
| 194 | crate->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 43.0f)); |
---|
| 195 | |
---|
| 196 | |
---|
| 197 | } |
---|
[11184] | 198 | |
---|
[11177] | 199 | |
---|
| 200 | |
---|
| 201 | |
---|
[11171] | 202 | //If no lives are left, end game |
---|
[11182] | 203 | if(lives <= 0) |
---|
| 204 | { |
---|
[11171] | 205 | GSLevel::startMainMenu(); |
---|
| 206 | } |
---|
[11182] | 207 | // Debug |
---|
[11169] | 208 | orxout() << this->origin_->getPickupTemplate() << endl; |
---|
| 209 | orxout() << this->origin_->getPickupRepresentationTemplate() << endl; |
---|
[11177] | 210 | |
---|
[11192] | 211 | |
---|
[11182] | 212 | orxout() << this->origin_->getPickupTemplateSpeed() << endl; |
---|
| 213 | orxout() << this->origin_->getPickupRepresentationTemplateSpeed() << endl; |
---|
| 214 | |
---|
| 215 | orxout() << this->origin_->getObstacleTemplate() << endl; |
---|
[11192] | 216 | //orxout() << crate->getPosition() << endl; |
---|
[11182] | 217 | } |
---|
[11151] | 218 | } |
---|
[10930] | 219 | |
---|
[11151] | 220 | |
---|
[11177] | 221 | // Start new level |
---|
[11192] | 222 | void Hover::createFlags() |
---|
[11169] | 223 | { |
---|
[11151] | 224 | //Generate 5 flags randomly (test only 1 flag) |
---|
[11192] | 225 | |
---|
| 226 | /* do |
---|
| 227 | { |
---|
| 228 | int i = 0; |
---|
| 229 | |
---|
| 230 | HoverFlag* flag = new HoverFlag(origin_->getContext()); |
---|
| 231 | int x = rand()%numCells; |
---|
| 232 | int y = rand()%numCells; |
---|
| 233 | flag->init(x, y, cellSize); |
---|
| 234 | flags_.push_back(flag); |
---|
| 235 | |
---|
| 236 | occupiedCells[x][y] = true; |
---|
| 237 | |
---|
| 238 | i++; |
---|
| 239 | |
---|
| 240 | }while( i<5 || occupiedCells[x][y] == true); |
---|
| 241 | */ |
---|
| 242 | |
---|
[11163] | 243 | for ( int i = 0; i < 5; i++ ) |
---|
[11151] | 244 | { |
---|
| 245 | HoverFlag* flag = new HoverFlag(origin_->getContext()); |
---|
| 246 | flag->init(rand()%numCells, rand()%numCells, cellSize); |
---|
| 247 | flags_.push_back(flag); |
---|
[11192] | 248 | |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | if(flags_[i]->getPosition() == get3dCoordinates(0,0,-60)) |
---|
| 252 | { |
---|
| 253 | flags_[i]->destroyLater(); |
---|
| 254 | flags_.erase(flags_.begin()+i); |
---|
| 255 | } |
---|
[11151] | 256 | } |
---|
[11169] | 257 | |
---|
[11151] | 258 | } |
---|
| 259 | |
---|
| 260 | void Hover::tick(float dt) |
---|
| 261 | { |
---|
| 262 | SUPER(Hover, tick, dt); |
---|
| 263 | |
---|
| 264 | |
---|
[10930] | 265 | // Check if ship collided with one of the flags |
---|
[11169] | 266 | for ( unsigned int i = 0; i < flags_.size(); i++ ) |
---|
| 267 | { |
---|
| 268 | if(flags_[i]->getCollided()) |
---|
| 269 | { |
---|
[11043] | 270 | flags_[i]->destroyLater(); |
---|
| 271 | flags_.erase (flags_.begin()+i); |
---|
[11168] | 272 | totFlags++; |
---|
[11151] | 273 | if(flags_.size()<=0){ |
---|
[11177] | 274 | //ChatManager::message("Level Up!"); |
---|
[11151] | 275 | |
---|
| 276 | levelUp(); |
---|
| 277 | //GSLevel::startMainMenu(); |
---|
| 278 | } |
---|
[10894] | 279 | } |
---|
[11151] | 280 | |
---|
[10894] | 281 | } |
---|
[11043] | 282 | numberOfFlags_ = flags_.size(); |
---|
[11171] | 283 | |
---|
| 284 | if(lives <= 0){ |
---|
| 285 | GSLevel::startMainMenu(); |
---|
| 286 | } |
---|
[10658] | 287 | } |
---|
[11151] | 288 | |
---|
| 289 | void Hover::levelUp() |
---|
| 290 | { |
---|
| 291 | level++; |
---|
[11177] | 292 | //increment lives after every 4 levels |
---|
| 293 | if(level%4 == 0) |
---|
| 294 | { |
---|
| 295 | lives++; |
---|
| 296 | } |
---|
[11192] | 297 | createFlags(); |
---|
| 298 | toggleShowLevel(); |
---|
| 299 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Hover::toggleShowLevel, this))); |
---|
[11151] | 300 | |
---|
| 301 | } |
---|
[11169] | 302 | |
---|
| 303 | Vector3 Hover::get3dCoordinates(int x, int y, float heightOffset) |
---|
| 304 | { |
---|
| 305 | return Vector3(x*cellSize*1.0f + cellSize/2, heightOffset, y*cellSize*1.0f + cellSize/2); |
---|
| 306 | } |
---|
[11171] | 307 | |
---|
| 308 | void Hover::costLife() |
---|
| 309 | { |
---|
| 310 | lives--; |
---|
| 311 | if (lives <= 0) |
---|
| 312 | GSLevel::startMainMenu(); |
---|
| 313 | } |
---|
[10658] | 314 | } |
---|