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