[12210] | 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: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
[12212] | 30 | @file OrxoBlox.cc |
---|
| 31 | @brief Implementation of the OrxoBlox class. |
---|
[12210] | 32 | */ |
---|
| 33 | |
---|
[12212] | 34 | #include "OrxoBlox.h" |
---|
[12308] | 35 | #include "Highscore.h" |
---|
[12210] | 36 | |
---|
| 37 | #include "core/CoreIncludes.h" |
---|
| 38 | #include "core/EventIncludes.h" |
---|
| 39 | #include "core/command/Executor.h" |
---|
| 40 | |
---|
[12308] | 41 | |
---|
| 42 | #include "core/config/ConfigValueIncludes.h"//Remove?? |
---|
| 43 | |
---|
[12210] | 44 | #include "gamestates/GSLevel.h" |
---|
| 45 | |
---|
[12308] | 46 | |
---|
| 47 | #include "chat/ChatManager.h"//Remove? |
---|
| 48 | |
---|
[12212] | 49 | #include "OrxoBloxCenterpoint.h" |
---|
| 50 | #include "OrxoBloxBall.h" |
---|
[12331] | 51 | //#include "OrxoBloxBot.h"//Remove?? |
---|
[12268] | 52 | #include "OrxoBloxStones.h" |
---|
[12288] | 53 | #include "OrxoBloxWall.h" |
---|
[12314] | 54 | #include "OrxoBloxShip.h" |
---|
[12260] | 55 | |
---|
[12210] | 56 | namespace orxonox |
---|
| 57 | { |
---|
[12308] | 58 | |
---|
[12210] | 59 | |
---|
[12212] | 60 | RegisterUnloadableClass(OrxoBlox); |
---|
[12210] | 61 | |
---|
| 62 | /** |
---|
| 63 | @brief |
---|
| 64 | Constructor. Registers and initializes the object. |
---|
| 65 | */ |
---|
[12337] | 66 | OrxoBlox::OrxoBlox(Context* context) : ::orxonox::Deathmatch::Deathmatch(context) |
---|
[12210] | 67 | { |
---|
[12212] | 68 | RegisterObject(OrxoBlox); |
---|
[12210] | 69 | |
---|
| 70 | this->center_ = nullptr; |
---|
| 71 | this->ball_ = nullptr; |
---|
[12280] | 72 | this->futureWall_ = nullptr; |
---|
[12307] | 73 | this->player_ = nullptr; |
---|
[12331] | 74 | level_ = 0; |
---|
[12210] | 75 | |
---|
[12307] | 76 | this->setHUDTemplate("OrxoBloxHUD"); |
---|
[12277] | 77 | //Error when specified |
---|
[12210] | 78 | |
---|
| 79 | // Pre-set the timer, but don't start it yet. |
---|
[12212] | 80 | this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::startBall, this))); |
---|
[12210] | 81 | this->starttimer_.stopTimer(); |
---|
| 82 | |
---|
[12307] | 83 | |
---|
[12210] | 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | /** |
---|
| 88 | @brief |
---|
| 89 | Destructor. Cleans up, if initialized. |
---|
| 90 | */ |
---|
[12212] | 91 | OrxoBlox::~OrxoBlox() |
---|
[12210] | 92 | { |
---|
| 93 | if (this->isInitialized()) |
---|
| 94 | this->cleanup(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /** |
---|
| 98 | @brief |
---|
| 99 | Cleans up the Gametype by destroying the ball and the bats. |
---|
| 100 | */ |
---|
[12212] | 101 | void OrxoBlox::cleanup() |
---|
[12210] | 102 | { |
---|
| 103 | if (this->ball_ != nullptr) // Destroy the ball, if present. |
---|
| 104 | { |
---|
| 105 | this->ball_->destroy(); |
---|
| 106 | this->ball_ = nullptr; |
---|
| 107 | } |
---|
| 108 | |
---|
[12307] | 109 | if (this->futureWall_) |
---|
| 110 | { |
---|
[12349] | 111 | this->futureWall_->destroy(); |
---|
| 112 | this->futureWall_ = nullptr; |
---|
[12307] | 113 | } |
---|
| 114 | |
---|
[12349] | 115 | for (OrxoBloxWall* wall : this->activeWalls_) |
---|
| 116 | wall->destroy(); |
---|
| 117 | this->activeWalls_.clear(); |
---|
| 118 | |
---|
| 119 | |
---|
[12343] | 120 | for (OrxoBloxStones* stone : this->stones_) |
---|
| 121 | stone->destroy(); |
---|
| 122 | this->stones_.clear(); |
---|
| 123 | |
---|
[12210] | 124 | |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /** |
---|
[12307] | 128 | @brieftt |
---|
[12212] | 129 | Starts the OrxoBlox minigame. |
---|
[12210] | 130 | */ |
---|
[12212] | 131 | void OrxoBlox::start() |
---|
[12210] | 132 | { |
---|
[12212] | 133 | if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place. |
---|
[12210] | 134 | { |
---|
| 135 | if (this->ball_ == nullptr) // If there is no ball, create a new ball. |
---|
| 136 | { |
---|
[12212] | 137 | this->ball_ = new OrxoBloxBall(this->center_->getContext()); |
---|
[12210] | 138 | // Apply the template for the ball specified by the centerpoint. |
---|
| 139 | this->ball_->addTemplate(this->center_->getBalltemplate()); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. |
---|
| 143 | this->center_->attach(this->ball_); |
---|
[12339] | 144 | //Startposition Ball |
---|
[12344] | 145 | this->ball_->setPosition(0, 0, 40); |
---|
[12210] | 146 | this->ball_->setFieldDimension(this->center_->getFieldDimension()); |
---|
| 147 | this->ball_->setSpeed(0); |
---|
| 148 | this->ball_->setAccelerationFactor(this->center_->getBallAccelerationFactor()); |
---|
| 149 | this->ball_->setBatLength(this->center_->getBatLength()); |
---|
| 150 | |
---|
[12331] | 151 | level_=1; |
---|
[12307] | 152 | |
---|
| 153 | // Create the first Wall. |
---|
[12349] | 154 | this->LevelUp(); |
---|
[12307] | 155 | |
---|
[12337] | 156 | //Create Ship |
---|
| 157 | //this->ship_ = new OrxoBloxShip(this->center_->getContext()); |
---|
| 158 | //this->ship_->setPosition(0, 0, 0); |
---|
| 159 | |
---|
[12210] | 160 | } |
---|
| 161 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
| 162 | { |
---|
[12212] | 163 | orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl; |
---|
[12210] | 164 | GSLevel::startMainMenu(); |
---|
| 165 | return; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | // Start the timer. After it has expired the ball is started. |
---|
| 169 | this->starttimer_.startTimer(); |
---|
| 170 | |
---|
| 171 | // Set variable to temporarily force the player to spawn. |
---|
[12359] | 172 | // Set variable to temporarily force the player to spawn. |
---|
| 173 | bool temp = this->bForceSpawn_; |
---|
[12337] | 174 | this->bForceSpawn_ = true; |
---|
[12210] | 175 | |
---|
| 176 | // Call start for the parent class. |
---|
| 177 | Deathmatch::start(); |
---|
| 178 | |
---|
[12359] | 179 | // Reset the variable. |
---|
| 180 | this->bForceSpawn_ = temp; |
---|
| 181 | |
---|
[12210] | 182 | } |
---|
| 183 | |
---|
| 184 | /** |
---|
| 185 | @brief |
---|
[12212] | 186 | Ends the OrxoBlox minigame. |
---|
[12210] | 187 | */ |
---|
[12212] | 188 | void OrxoBlox::end() |
---|
[12210] | 189 | { |
---|
[12268] | 190 | ChatManager::message("You suck!!"); |
---|
[12359] | 191 | |
---|
| 192 | if (Highscore::exists()) |
---|
| 193 | { |
---|
| 194 | int score = this->getScore(this->getPlayer()); |
---|
| 195 | Highscore::getInstance().storeScore("Tetris", score, this->getPlayer()); |
---|
| 196 | } |
---|
| 197 | |
---|
[12210] | 198 | this->cleanup(); |
---|
| 199 | |
---|
| 200 | // Call end for the parent class. |
---|
| 201 | Deathmatch::end(); |
---|
[12351] | 202 | GSLevel::startMainMenu(); |
---|
[12210] | 203 | } |
---|
| 204 | |
---|
[12359] | 205 | PlayerInfo* OrxoBlox::getPlayer() |
---|
[12337] | 206 | { |
---|
[12359] | 207 | return this->player_; |
---|
[12337] | 208 | } |
---|
| 209 | |
---|
[12212] | 210 | void OrxoBlox::spawnPlayer(PlayerInfo* player) |
---|
[12210] | 211 | { |
---|
[12337] | 212 | assert(player); |
---|
[12210] | 213 | |
---|
[12307] | 214 | if(this->player_ == nullptr) |
---|
[12210] | 215 | { |
---|
[12307] | 216 | this->player_ = player; |
---|
[12210] | 217 | this->players_[player].state_ = PlayerState::Alive; |
---|
| 218 | } |
---|
| 219 | |
---|
[12314] | 220 | } |
---|
| 221 | |
---|
[12331] | 222 | void OrxoBlox::LevelUp(){ |
---|
| 223 | level_++; |
---|
[12359] | 224 | this->playerScored(this->player_);// add points |
---|
[12355] | 225 | for(OrxoBloxStones* stone : this->stones_){ |
---|
| 226 | int x_=(stone->getPosition()).x; |
---|
| 227 | int y_=(stone->getPosition()).y; |
---|
| 228 | int z_=(stone->getPosition()).z; |
---|
[12351] | 229 | if(z_==90)this->end(); |
---|
[12355] | 230 | |
---|
| 231 | stone->setPosition(x_,y_,z_+9.0f); |
---|
[12349] | 232 | } |
---|
[12355] | 233 | |
---|
| 234 | |
---|
[12351] | 235 | this->createWall(); |
---|
[12345] | 236 | this->activeWalls_.push_back(this->futureWall_); |
---|
[12350] | 237 | for (int i = 0; i < this->futureWall_->getNumberOfStones(); i++) { |
---|
| 238 | if (this->futureWall_->getStone(i) == nullptr) { |
---|
| 239 | orxout() << "Added nullptr to std::list stones_" << endl; |
---|
| 240 | } |
---|
[12349] | 241 | |
---|
[12346] | 242 | this->stones_.push_back(this->futureWall_->getStone(i)); |
---|
[12350] | 243 | } |
---|
[12360] | 244 | |
---|
| 245 | for(OrxoBloxWall* wall : this->activeWalls_) { |
---|
| 246 | if(wall->isEmpty()) { |
---|
| 247 | wall->destroy(); |
---|
| 248 | } |
---|
| 249 | int NumberOfStones = 0; |
---|
| 250 | for(int i = 0; i < 10; i++) { |
---|
| 251 | if(wall->getStone(i) == nullptr) { |
---|
| 252 | continue; |
---|
| 253 | } |
---|
| 254 | else { |
---|
| 255 | NumberOfStones++; |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | } |
---|
| 259 | } |
---|
[12331] | 260 | //new location of ship |
---|
| 261 | //new amount of balls |
---|
| 262 | //create balls |
---|
| 263 | //insert new wall |
---|
| 264 | } |
---|
[12210] | 265 | |
---|
[12350] | 266 | void OrxoBlox::createWall(){ |
---|
[12307] | 267 | this->futureWall_ = new OrxoBloxWall(this->center_->getContext()); |
---|
| 268 | // Apply the stone template to the stone. |
---|
| 269 | this->futureWall_->addTemplate(this->center_->getWallTemplate()); |
---|
[12210] | 270 | |
---|
[12307] | 271 | // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. |
---|
| 272 | this->center_->attach(this->futureWall_); |
---|
| 273 | |
---|
[12345] | 274 | this->futureWall_->setPosition(0, 0, 0); |
---|
[12307] | 275 | this->futureWall_->setGame(this); |
---|
[12210] | 276 | } |
---|
| 277 | |
---|
[12278] | 278 | |
---|
[12210] | 279 | /** |
---|
| 280 | @brief |
---|
| 281 | Starts the ball with some default speed. |
---|
| 282 | */ |
---|
[12212] | 283 | void OrxoBlox::startBall() |
---|
[12210] | 284 | { |
---|
| 285 | if (this->ball_ != nullptr && this->center_ != nullptr) |
---|
| 286 | this->ball_->setSpeed(this->center_->getBallSpeed()); |
---|
| 287 | } |
---|
| 288 | |
---|
[12350] | 289 | OrxoBloxStones* OrxoBlox::CheckForCollision(OrxoBloxBall* Ball) { |
---|
[12346] | 290 | |
---|
| 291 | orxout() << "Checking for Collision" << endl; |
---|
| 292 | Vector3 BallPosition = Ball->getPosition(); |
---|
| 293 | for(OrxoBloxStones* someStone : this->stones_) |
---|
| 294 | { |
---|
[12350] | 295 | if(someStone == nullptr) |
---|
| 296 | { |
---|
| 297 | continue; |
---|
| 298 | } |
---|
[12346] | 299 | orxout() << "Checking a stone" << endl; |
---|
| 300 | const Vector3& StonePosition = someStone->getPosition(); //!< Saves the position of the currentStone |
---|
[12360] | 301 | int size = someStone->getSize()/2; |
---|
| 302 | if((BallPosition.x - Ball->getRadius() >= StonePosition.x - size && BallPosition.x + Ball->getRadius() <= StonePosition.x + size) && |
---|
| 303 | (BallPosition.z - Ball->getRadius() >= StonePosition.z - size && BallPosition.z + Ball->getRadius() <= StonePosition.z + size)) { |
---|
[12346] | 304 | orxout() << "FOUND ONE" << endl; |
---|
| 305 | return someStone; |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | orxout() << "Found nothing...." << endl; |
---|
| 309 | return nullptr; |
---|
[12350] | 310 | } |
---|
[12260] | 311 | |
---|
[12210] | 312 | } |
---|