| [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 | |
|---|
| [11168] | 66 | totFlags = 0; |
|---|
| 67 | |
|---|
| [10895] | 68 | this->setHUDTemplate("HoverHUD"); |
|---|
| [11151] | 69 | |
|---|
| [10658] | 70 | } |
|---|
| 71 | |
|---|
| [11151] | 72 | void Hover::start() |
|---|
| [10658] | 73 | { |
|---|
| [11151] | 74 | Gametype::start(); |
|---|
| [11040] | 75 | if(this->firstTick_ && this->origin_) |
|---|
| [11035] | 76 | { |
|---|
| 77 | this->firstTick_ = false; |
|---|
| [10787] | 78 | |
|---|
| [11151] | 79 | numCells = this->origin_->getNumCells(); |
|---|
| 80 | cellSize = this->origin_->getCellSize(); |
|---|
| 81 | cellHeight = this->origin_->getCellHeight(); |
|---|
| [11040] | 82 | |
|---|
| 83 | MazeGenerator generator(numCells); |
|---|
| [11035] | 84 | generator.generateMaze(); |
|---|
| 85 | generator.renderMaze(); |
|---|
| [10787] | 86 | |
|---|
| [11035] | 87 | int* levelcode = generator.getLevelcode(); |
|---|
| [10787] | 88 | |
|---|
| [10928] | 89 | //Outer Walls |
|---|
| [11040] | 90 | for(int i = 0; i<numCells; i++){ |
|---|
| [11042] | 91 | (new HoverWall(origin_->getContext()))->init(0, i+1, cellSize, cellHeight, 1); |
|---|
| 92 | (new HoverWall(origin_->getContext()))->init(numCells, i+1, cellSize, cellHeight, 1); |
|---|
| 93 | (new HoverWall(origin_->getContext()))->init(i+1, 0, cellSize, cellHeight, 2); |
|---|
| 94 | (new HoverWall(origin_->getContext()))->init(i+1, numCells, cellSize, cellHeight, 2); |
|---|
| [10928] | 95 | } |
|---|
| 96 | |
|---|
| [11163] | 97 | |
|---|
| 98 | |
|---|
| [10930] | 99 | //Generate inner Walls according to levelcode |
|---|
| [11040] | 100 | for(int y=0; y<numCells; y++){ |
|---|
| 101 | for(int x=0; x<numCells; x++){ |
|---|
| [11169] | 102 | switch(levelcode[ y * numCells + x ]) |
|---|
| 103 | { |
|---|
| [11042] | 104 | case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1); |
|---|
| [11169] | 105 | break; |
|---|
| [11042] | 106 | case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1); |
|---|
| 107 | case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0); |
|---|
| [11169] | 108 | default: |
|---|
| 109 | break; |
|---|
| [10787] | 110 | } |
|---|
| [11169] | 111 | } |
|---|
| [10787] | 112 | } |
|---|
| 113 | |
|---|
| [11151] | 114 | //Generate 5 flags randomly (test only 1 flag) |
|---|
| [11163] | 115 | for ( int i = 0; i < 5; i++ ) |
|---|
| [11042] | 116 | { |
|---|
| 117 | HoverFlag* flag = new HoverFlag(origin_->getContext()); |
|---|
| 118 | flag->init(rand()%numCells, rand()%numCells, cellSize); |
|---|
| [11043] | 119 | flags_.push_back(flag); |
|---|
| [11042] | 120 | } |
|---|
| [11163] | 121 | |
|---|
| [10900] | 122 | |
|---|
| [11177] | 123 | //Generate 5 PickupSpawners randomly (destroy hover pickup) |
|---|
| [11168] | 124 | for (int i = 0; i<5; i++) |
|---|
| [11163] | 125 | { |
|---|
| [11169] | 126 | PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext()); |
|---|
| 127 | |
|---|
| 128 | pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 10.0f)); |
|---|
| 129 | pickupSpawner->setPickupTemplateName(origin_->getPickupTemplate()); |
|---|
| 130 | pickupSpawner->setMaxSpawnedItems(5); |
|---|
| 131 | pickupSpawner->setRespawnTime(30); |
|---|
| 132 | pickupSpawner->setTriggerDistance(5); |
|---|
| 133 | // Add pickup spawner to the pickup spawner list |
|---|
| 134 | pickupSpawners_.push_back(pickupSpawner); |
|---|
| [11163] | 135 | } |
|---|
| [11177] | 136 | |
|---|
| 137 | //Generate 5 PickupSpawners randomly (damage pickup) |
|---|
| 138 | for (int i = 0; i<5; i++) |
|---|
| 139 | { |
|---|
| 140 | PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext()); |
|---|
| 141 | |
|---|
| 142 | pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 10.0f)); |
|---|
| 143 | pickupSpawner->setPickupTemplateName(origin_->getPickupTemplateDam()); |
|---|
| 144 | pickupSpawner->setMaxSpawnedItems(5); |
|---|
| 145 | pickupSpawner->setRespawnTime(30); |
|---|
| 146 | pickupSpawner->setTriggerDistance(5); |
|---|
| 147 | // Add pickup spawner to the pickup spawner list |
|---|
| 148 | pickupSpawners_.push_back(pickupSpawner); |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | //***************************************************************************** |
|---|
| 152 | |
|---|
| 153 | Pawn* crate = new Pawn(origin_->getContext()); |
|---|
| 154 | |
|---|
| 155 | crate->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 10.0f)); |
|---|
| 156 | crate->addTemplate(origin_->getObstacleTemplate()); |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | |
|---|
| [11171] | 161 | //If no lives are left, end game |
|---|
| 162 | if(lives <= 0){ |
|---|
| 163 | GSLevel::startMainMenu(); |
|---|
| 164 | } |
|---|
| [11163] | 165 | |
|---|
| [11169] | 166 | orxout() << this->origin_->getPickupTemplate() << endl; |
|---|
| 167 | orxout() << this->origin_->getPickupRepresentationTemplate() << endl; |
|---|
| [11177] | 168 | |
|---|
| 169 | orxout() << this->origin_->getPickupTemplateDam() << endl; |
|---|
| 170 | orxout() << this->origin_->getPickupRepresentationTemplateDam() << endl; |
|---|
| [11151] | 171 | } |
|---|
| 172 | } |
|---|
| [10930] | 173 | |
|---|
| [11151] | 174 | |
|---|
| [11177] | 175 | // Start new level |
|---|
| 176 | void Hover::newLevel() |
|---|
| [11169] | 177 | { |
|---|
| [11151] | 178 | //Generate 5 flags randomly (test only 1 flag) |
|---|
| [11163] | 179 | for ( int i = 0; i < 5; i++ ) |
|---|
| [11151] | 180 | { |
|---|
| 181 | HoverFlag* flag = new HoverFlag(origin_->getContext()); |
|---|
| 182 | flag->init(rand()%numCells, rand()%numCells, cellSize); |
|---|
| 183 | flags_.push_back(flag); |
|---|
| 184 | } |
|---|
| [11169] | 185 | |
|---|
| [11151] | 186 | } |
|---|
| 187 | |
|---|
| 188 | void Hover::tick(float dt) |
|---|
| 189 | { |
|---|
| 190 | SUPER(Hover, tick, dt); |
|---|
| 191 | |
|---|
| 192 | |
|---|
| [10930] | 193 | // Check if ship collided with one of the flags |
|---|
| [11169] | 194 | for ( unsigned int i = 0; i < flags_.size(); i++ ) |
|---|
| 195 | { |
|---|
| 196 | if(flags_[i]->getCollided()) |
|---|
| 197 | { |
|---|
| [11043] | 198 | flags_[i]->destroyLater(); |
|---|
| 199 | flags_.erase (flags_.begin()+i); |
|---|
| [11168] | 200 | totFlags++; |
|---|
| [11151] | 201 | if(flags_.size()<=0){ |
|---|
| [11177] | 202 | //ChatManager::message("Level Up!"); |
|---|
| [11151] | 203 | |
|---|
| 204 | levelUp(); |
|---|
| 205 | //GSLevel::startMainMenu(); |
|---|
| 206 | } |
|---|
| [10894] | 207 | } |
|---|
| [11151] | 208 | |
|---|
| [10894] | 209 | } |
|---|
| [11043] | 210 | numberOfFlags_ = flags_.size(); |
|---|
| [11171] | 211 | |
|---|
| 212 | if(lives <= 0){ |
|---|
| 213 | GSLevel::startMainMenu(); |
|---|
| 214 | } |
|---|
| [10658] | 215 | } |
|---|
| [11151] | 216 | |
|---|
| 217 | void Hover::levelUp() |
|---|
| 218 | { |
|---|
| 219 | level++; |
|---|
| [11177] | 220 | //increment lives after every 4 levels |
|---|
| 221 | if(level%4 == 0) |
|---|
| 222 | { |
|---|
| 223 | lives++; |
|---|
| 224 | } |
|---|
| 225 | newLevel(); |
|---|
| [11151] | 226 | |
|---|
| 227 | } |
|---|
| [11169] | 228 | |
|---|
| 229 | Vector3 Hover::get3dCoordinates(int x, int y, float heightOffset) |
|---|
| 230 | { |
|---|
| 231 | return Vector3(x*cellSize*1.0f + cellSize/2, heightOffset, y*cellSize*1.0f + cellSize/2); |
|---|
| 232 | } |
|---|
| [11171] | 233 | |
|---|
| 234 | void Hover::costLife() |
|---|
| 235 | { |
|---|
| 236 | lives--; |
|---|
| 237 | if (lives <= 0) |
|---|
| 238 | GSLevel::startMainMenu(); |
|---|
| 239 | } |
|---|
| [10658] | 240 | } |
|---|