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