[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 | { |
---|
| 111 | this->futureWall_->destroy(); |
---|
| 112 | this->futureWall_ = nullptr; |
---|
| 113 | } |
---|
| 114 | |
---|
[12343] | 115 | for (OrxoBloxStones* stone : this->stones_) |
---|
| 116 | stone->destroy(); |
---|
| 117 | this->stones_.clear(); |
---|
| 118 | |
---|
[12210] | 119 | |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /** |
---|
[12307] | 123 | @brieftt |
---|
[12212] | 124 | Starts the OrxoBlox minigame. |
---|
[12210] | 125 | */ |
---|
[12212] | 126 | void OrxoBlox::start() |
---|
[12210] | 127 | { |
---|
[12212] | 128 | if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place. |
---|
[12210] | 129 | { |
---|
| 130 | if (this->ball_ == nullptr) // If there is no ball, create a new ball. |
---|
| 131 | { |
---|
[12212] | 132 | this->ball_ = new OrxoBloxBall(this->center_->getContext()); |
---|
[12210] | 133 | // Apply the template for the ball specified by the centerpoint. |
---|
| 134 | this->ball_->addTemplate(this->center_->getBalltemplate()); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | // Attach the ball to the centerpoint and set the parameters as specified in the centerpoint, the ball is attached to. |
---|
| 138 | this->center_->attach(this->ball_); |
---|
[12339] | 139 | //Startposition Ball |
---|
| 140 | this->ball_->setPosition(0, 0, 50); |
---|
[12210] | 141 | this->ball_->setFieldDimension(this->center_->getFieldDimension()); |
---|
| 142 | this->ball_->setSpeed(0); |
---|
| 143 | this->ball_->setAccelerationFactor(this->center_->getBallAccelerationFactor()); |
---|
| 144 | this->ball_->setBatLength(this->center_->getBatLength()); |
---|
| 145 | |
---|
[12331] | 146 | level_=1; |
---|
[12307] | 147 | |
---|
| 148 | // Create the first Wall. |
---|
[12342] | 149 | this->LevelUp(); |
---|
[12307] | 150 | |
---|
[12337] | 151 | //Create Ship |
---|
| 152 | //this->ship_ = new OrxoBloxShip(this->center_->getContext()); |
---|
| 153 | //this->ship_->setPosition(0, 0, 0); |
---|
| 154 | |
---|
[12210] | 155 | } |
---|
| 156 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
| 157 | { |
---|
[12212] | 158 | orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl; |
---|
[12210] | 159 | GSLevel::startMainMenu(); |
---|
| 160 | return; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | // Start the timer. After it has expired the ball is started. |
---|
| 164 | this->starttimer_.startTimer(); |
---|
| 165 | |
---|
| 166 | // Set variable to temporarily force the player to spawn. |
---|
[12337] | 167 | this->bForceSpawn_ = true; |
---|
[12210] | 168 | |
---|
| 169 | // Call start for the parent class. |
---|
| 170 | Deathmatch::start(); |
---|
| 171 | |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | /** |
---|
| 175 | @brief |
---|
[12212] | 176 | Ends the OrxoBlox minigame. |
---|
[12210] | 177 | */ |
---|
[12212] | 178 | void OrxoBlox::end() |
---|
[12210] | 179 | { |
---|
[12268] | 180 | ChatManager::message("You suck!!"); |
---|
[12210] | 181 | this->cleanup(); |
---|
| 182 | |
---|
| 183 | // Call end for the parent class. |
---|
| 184 | Deathmatch::end(); |
---|
| 185 | } |
---|
| 186 | |
---|
[12337] | 187 | OrxoBloxShip* OrxoBlox::getPlayer() |
---|
| 188 | { |
---|
| 189 | if (playership == nullptr) |
---|
| 190 | { |
---|
| 191 | for (OrxoBloxShip* ship_ : ObjectList<OrxoBloxShip>()) |
---|
| 192 | { |
---|
| 193 | playership = ship_; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | return playership; |
---|
| 197 | } |
---|
| 198 | |
---|
[12212] | 199 | void OrxoBlox::spawnPlayer(PlayerInfo* player) |
---|
[12210] | 200 | { |
---|
[12337] | 201 | assert(player); |
---|
[12210] | 202 | |
---|
[12307] | 203 | if(this->player_ == nullptr) |
---|
[12210] | 204 | { |
---|
[12307] | 205 | this->player_ = player; |
---|
[12210] | 206 | this->players_[player].state_ = PlayerState::Alive; |
---|
| 207 | } |
---|
| 208 | |
---|
[12314] | 209 | } |
---|
| 210 | |
---|
[12331] | 211 | void OrxoBlox::LevelUp(){ |
---|
| 212 | level_++; |
---|
[12342] | 213 | this->createWall(); |
---|
[12343] | 214 | //this->activeWalls_.push_back(this->futureWall_); |
---|
[12331] | 215 | //When levelup? wo wird es ausgeloest? |
---|
| 216 | //new location of ship |
---|
| 217 | //new amount of balls |
---|
| 218 | //create balls |
---|
| 219 | //insert new wall |
---|
[12342] | 220 | |
---|
[12331] | 221 | } |
---|
[12210] | 222 | |
---|
[12307] | 223 | void OrxoBlox::createWall(void){ |
---|
| 224 | this->futureWall_ = new OrxoBloxWall(this->center_->getContext()); |
---|
| 225 | // Apply the stone template to the stone. |
---|
| 226 | this->futureWall_->addTemplate(this->center_->getWallTemplate()); |
---|
[12210] | 227 | |
---|
[12307] | 228 | // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. |
---|
| 229 | this->center_->attach(this->futureWall_); |
---|
| 230 | |
---|
[12343] | 231 | float y_=(this->center_->getFieldDimension()).y; |
---|
| 232 | //stone->setPosition(size_*i -x_/2 +4.5f, -3.5f, -y_/2 + 6.5f); |
---|
| 233 | this->futureWall_->setPosition(0, 0, -y_/2 + 6.5f); |
---|
[12307] | 234 | this->futureWall_->setGame(this); |
---|
[12210] | 235 | } |
---|
| 236 | |
---|
[12278] | 237 | |
---|
[12210] | 238 | /** |
---|
| 239 | @brief |
---|
| 240 | Starts the ball with some default speed. |
---|
| 241 | */ |
---|
[12212] | 242 | void OrxoBlox::startBall() |
---|
[12210] | 243 | { |
---|
| 244 | if (this->ball_ != nullptr && this->center_ != nullptr) |
---|
| 245 | this->ball_->setSpeed(this->center_->getBallSpeed()); |
---|
| 246 | } |
---|
| 247 | |
---|
[12260] | 248 | |
---|
[12307] | 249 | |
---|
[12210] | 250 | } |
---|