[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" |
---|
[10658] | 42 | |
---|
[11163] | 43 | #include "pickup/PickupSpawner.h" |
---|
| 44 | #include "pickup/Pickup.h" |
---|
| 45 | |
---|
[10658] | 46 | namespace orxonox |
---|
| 47 | { |
---|
| 48 | RegisterUnloadableClass(Hover); |
---|
| 49 | |
---|
[10664] | 50 | Hover::Hover(Context* context) : Gametype(context) |
---|
[10658] | 51 | { |
---|
| 52 | RegisterObject(Hover); |
---|
[11035] | 53 | |
---|
[11071] | 54 | this->origin_ = nullptr; |
---|
[11043] | 55 | this->numberOfFlags_ = 1; |
---|
[11035] | 56 | this->firstTick_ = true; |
---|
[11151] | 57 | level = 1; //start at level 1 |
---|
| 58 | flagsTaken = 0;// took 0 flags in the beginning |
---|
[11035] | 59 | |
---|
[11151] | 60 | numCells = 0; |
---|
| 61 | cellSize = 0; |
---|
| 62 | cellHeight = 0; |
---|
| 63 | |
---|
[11168] | 64 | totFlags = 0; |
---|
| 65 | |
---|
[10895] | 66 | this->setHUDTemplate("HoverHUD"); |
---|
[11151] | 67 | |
---|
[10658] | 68 | } |
---|
| 69 | |
---|
[11151] | 70 | void Hover::start() |
---|
[10658] | 71 | { |
---|
[11151] | 72 | Gametype::start(); |
---|
[11040] | 73 | if(this->firstTick_ && this->origin_) |
---|
[11035] | 74 | { |
---|
| 75 | this->firstTick_ = false; |
---|
[10787] | 76 | |
---|
[11151] | 77 | numCells = this->origin_->getNumCells(); |
---|
| 78 | cellSize = this->origin_->getCellSize(); |
---|
| 79 | cellHeight = this->origin_->getCellHeight(); |
---|
[11040] | 80 | |
---|
| 81 | MazeGenerator generator(numCells); |
---|
[11035] | 82 | generator.generateMaze(); |
---|
| 83 | generator.renderMaze(); |
---|
[10787] | 84 | |
---|
[11035] | 85 | int* levelcode = generator.getLevelcode(); |
---|
[10787] | 86 | |
---|
[10928] | 87 | //Outer Walls |
---|
[11040] | 88 | for(int i = 0; i<numCells; i++){ |
---|
[11042] | 89 | (new HoverWall(origin_->getContext()))->init(0, i+1, cellSize, cellHeight, 1); |
---|
| 90 | (new HoverWall(origin_->getContext()))->init(numCells, i+1, cellSize, cellHeight, 1); |
---|
| 91 | (new HoverWall(origin_->getContext()))->init(i+1, 0, cellSize, cellHeight, 2); |
---|
| 92 | (new HoverWall(origin_->getContext()))->init(i+1, numCells, cellSize, cellHeight, 2); |
---|
[10928] | 93 | } |
---|
| 94 | |
---|
[11163] | 95 | |
---|
| 96 | |
---|
[10930] | 97 | //Generate inner Walls according to levelcode |
---|
[11040] | 98 | for(int y=0; y<numCells; y++){ |
---|
| 99 | for(int x=0; x<numCells; x++){ |
---|
[11169] | 100 | switch(levelcode[ y * numCells + x ]) |
---|
| 101 | { |
---|
[11042] | 102 | case 1: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1); |
---|
[11169] | 103 | break; |
---|
[11042] | 104 | case 3: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 1); |
---|
| 105 | case 2: (new HoverWall(origin_->getContext()))->init(x+1, numCells-y, cellSize, cellHeight, 0); |
---|
[11169] | 106 | default: |
---|
| 107 | break; |
---|
[10787] | 108 | } |
---|
[11169] | 109 | } |
---|
[10787] | 110 | } |
---|
| 111 | |
---|
[11151] | 112 | //Generate 5 flags randomly (test only 1 flag) |
---|
[11163] | 113 | for ( int i = 0; i < 5; i++ ) |
---|
[11042] | 114 | { |
---|
| 115 | HoverFlag* flag = new HoverFlag(origin_->getContext()); |
---|
| 116 | flag->init(rand()%numCells, rand()%numCells, cellSize); |
---|
[11043] | 117 | flags_.push_back(flag); |
---|
[11042] | 118 | } |
---|
[11163] | 119 | |
---|
[10900] | 120 | |
---|
[11168] | 121 | //Generate 5 PickupSpawners randomly |
---|
| 122 | for (int i = 0; i<5; i++) |
---|
[11163] | 123 | { |
---|
[11169] | 124 | PickupSpawner* pickupSpawner = new PickupSpawner(origin_->getContext()); |
---|
| 125 | |
---|
| 126 | pickupSpawner->setPosition(get3dCoordinates(rand()%numCells, rand()%numCells, 10.0f)); |
---|
| 127 | pickupSpawner->setPickupTemplateName(origin_->getPickupTemplate()); |
---|
| 128 | pickupSpawner->setMaxSpawnedItems(5); |
---|
| 129 | pickupSpawner->setRespawnTime(30); |
---|
| 130 | pickupSpawner->setTriggerDistance(5); |
---|
| 131 | // Add pickup spawner to the pickup spawner list |
---|
| 132 | pickupSpawners_.push_back(pickupSpawner); |
---|
[11163] | 133 | } |
---|
| 134 | |
---|
[11169] | 135 | orxout() << this->origin_->getPickupTemplate() << endl; |
---|
| 136 | orxout() << this->origin_->getPickupRepresentationTemplate() << endl; |
---|
[11151] | 137 | } |
---|
| 138 | } |
---|
[10930] | 139 | |
---|
[11151] | 140 | |
---|
[11169] | 141 | // Rename/delete this function. |
---|
| 142 | void Hover::startLevel() |
---|
| 143 | { |
---|
[11151] | 144 | //Generate 5 flags randomly (test only 1 flag) |
---|
[11163] | 145 | for ( int i = 0; i < 5; i++ ) |
---|
[11151] | 146 | { |
---|
| 147 | HoverFlag* flag = new HoverFlag(origin_->getContext()); |
---|
| 148 | flag->init(rand()%numCells, rand()%numCells, cellSize); |
---|
| 149 | flags_.push_back(flag); |
---|
| 150 | } |
---|
| 151 | |
---|
[11168] | 152 | //Generate 5 PickupSpawners randomly |
---|
| 153 | for (int i = 0; i<5; i++) |
---|
| 154 | { |
---|
| 155 | PickupSpawner* pickup = new PickupSpawner(origin_->getContext()); |
---|
| 156 | //PickupSpawner->setPosition(rand()%numCells, rand()%numCells, cellSize); |
---|
| 157 | //pickup->createDroppedPickup(this->getContext(), pickup , this, 5); |
---|
[11169] | 158 | pickupSpawners_.push_back(pickup); |
---|
[11168] | 159 | } |
---|
| 160 | |
---|
[11169] | 161 | |
---|
[11151] | 162 | } |
---|
| 163 | |
---|
| 164 | void Hover::tick(float dt) |
---|
| 165 | { |
---|
| 166 | SUPER(Hover, tick, dt); |
---|
| 167 | |
---|
| 168 | |
---|
[10930] | 169 | // Check if ship collided with one of the flags |
---|
[11169] | 170 | for ( unsigned int i = 0; i < flags_.size(); i++ ) |
---|
| 171 | { |
---|
| 172 | if(flags_[i]->getCollided()) |
---|
| 173 | { |
---|
[11043] | 174 | flags_[i]->destroyLater(); |
---|
| 175 | flags_.erase (flags_.begin()+i); |
---|
[11168] | 176 | totFlags++; |
---|
[11151] | 177 | if(flags_.size()<=0){ |
---|
| 178 | ChatManager::message("Level Up!"); |
---|
| 179 | |
---|
| 180 | levelUp(); |
---|
| 181 | //GSLevel::startMainMenu(); |
---|
| 182 | } |
---|
[10894] | 183 | } |
---|
[11151] | 184 | |
---|
[10894] | 185 | } |
---|
[11043] | 186 | numberOfFlags_ = flags_.size(); |
---|
[10658] | 187 | } |
---|
[11151] | 188 | |
---|
| 189 | void Hover::levelUp() |
---|
| 190 | { |
---|
| 191 | level++; |
---|
| 192 | startLevel(); |
---|
| 193 | |
---|
| 194 | } |
---|
[11169] | 195 | |
---|
| 196 | Vector3 Hover::get3dCoordinates(int x, int y, float heightOffset) |
---|
| 197 | { |
---|
| 198 | return Vector3(x*cellSize*1.0f + cellSize/2, heightOffset, y*cellSize*1.0f + cellSize/2); |
---|
| 199 | } |
---|
[10658] | 200 | } |
---|