[12212] | 1 | #include "OrxoBlox.h" |
---|
[12308] | 2 | #include "Highscore.h" |
---|
[12210] | 3 | |
---|
| 4 | #include "core/CoreIncludes.h" |
---|
| 5 | #include "core/EventIncludes.h" |
---|
| 6 | #include "core/command/Executor.h" |
---|
| 7 | |
---|
[12308] | 8 | |
---|
| 9 | #include "core/config/ConfigValueIncludes.h"//Remove?? |
---|
| 10 | |
---|
[12210] | 11 | #include "gamestates/GSLevel.h" |
---|
| 12 | |
---|
[12308] | 13 | |
---|
| 14 | #include "chat/ChatManager.h"//Remove? |
---|
| 15 | |
---|
[12212] | 16 | #include "OrxoBloxCenterpoint.h" |
---|
[12268] | 17 | #include "OrxoBloxStones.h" |
---|
[12288] | 18 | #include "OrxoBloxWall.h" |
---|
[12314] | 19 | #include "OrxoBloxShip.h" |
---|
[12260] | 20 | |
---|
[12210] | 21 | namespace orxonox |
---|
| 22 | { |
---|
[12308] | 23 | |
---|
[12210] | 24 | |
---|
[12212] | 25 | RegisterUnloadableClass(OrxoBlox); |
---|
[12210] | 26 | |
---|
| 27 | /** |
---|
| 28 | @brief |
---|
| 29 | Constructor. Registers and initializes the object. |
---|
| 30 | */ |
---|
[12366] | 31 | OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context) |
---|
[12210] | 32 | { |
---|
[12212] | 33 | RegisterObject(OrxoBlox); |
---|
[12210] | 34 | |
---|
| 35 | this->center_ = nullptr; |
---|
[12371] | 36 | //this->ball_ = nullptr; |
---|
[12280] | 37 | this->futureWall_ = nullptr; |
---|
[12307] | 38 | this->player_ = nullptr; |
---|
[12331] | 39 | level_ = 0; |
---|
[12394] | 40 | this->counter = 0; |
---|
[12210] | 41 | |
---|
[12307] | 42 | this->setHUDTemplate("OrxoBloxHUD"); |
---|
[12277] | 43 | //Error when specified |
---|
[12210] | 44 | |
---|
| 45 | // Pre-set the timer, but don't start it yet. |
---|
[12371] | 46 | this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::LevelUp, this))); |
---|
[12210] | 47 | this->starttimer_.stopTimer(); |
---|
| 48 | |
---|
[12307] | 49 | |
---|
[12210] | 50 | |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | /** |
---|
| 54 | @brief |
---|
| 55 | Destructor. Cleans up, if initialized. |
---|
| 56 | */ |
---|
[12212] | 57 | OrxoBlox::~OrxoBlox() |
---|
[12210] | 58 | { |
---|
| 59 | if (this->isInitialized()) |
---|
| 60 | this->cleanup(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | @brief |
---|
| 65 | Cleans up the Gametype by destroying the ball and the bats. |
---|
| 66 | */ |
---|
[12212] | 67 | void OrxoBlox::cleanup() |
---|
[12376] | 68 | { |
---|
[12210] | 69 | |
---|
[12396] | 70 | std::vector<OrxoBloxWall*> vyserion_targets; |
---|
| 71 | std::vector<OrxoBloxStones*> casterly_rocks; |
---|
| 72 | |
---|
| 73 | for (OrxoBloxWall* wall : ObjectList<OrxoBloxWall>()) { |
---|
| 74 | if(wall != nullptr) { |
---|
| 75 | vyserion_targets.push_back(wall); |
---|
[12307] | 76 | } |
---|
[12396] | 77 | } |
---|
[12395] | 78 | for (OrxoBloxStones* stone : ObjectList<OrxoBloxStones>()) { |
---|
[12396] | 79 | if(stone != nullptr) { |
---|
| 80 | casterly_rocks.push_back(stone); |
---|
| 81 | } |
---|
[12395] | 82 | } |
---|
[12396] | 83 | for(unsigned int i = 0; i < vyserion_targets.size(); i++) { |
---|
| 84 | vyserion_targets.at(i)->destroy(); |
---|
[12392] | 85 | } |
---|
[12396] | 86 | for(unsigned int i = 0; i < casterly_rocks.size(); i++) { |
---|
| 87 | casterly_rocks.at(i)->destroy(); |
---|
[12392] | 88 | } |
---|
[12210] | 89 | |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
[12307] | 93 | @brieftt |
---|
[12212] | 94 | Starts the OrxoBlox minigame. |
---|
[12210] | 95 | */ |
---|
[12212] | 96 | void OrxoBlox::start() |
---|
[12367] | 97 | |
---|
[12210] | 98 | { |
---|
[12376] | 99 | orxout() << "Orxoblox started" << endl; |
---|
[12212] | 100 | if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place. |
---|
[12210] | 101 | { |
---|
[12394] | 102 | level_= 1; |
---|
[12210] | 103 | } |
---|
| 104 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
| 105 | { |
---|
[12212] | 106 | orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl; |
---|
[12210] | 107 | GSLevel::startMainMenu(); |
---|
| 108 | return; |
---|
| 109 | } |
---|
| 110 | this->starttimer_.startTimer(); |
---|
| 111 | |
---|
[12370] | 112 | this->bForceSpawn_ = false; |
---|
[12210] | 113 | Deathmatch::start(); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | /** |
---|
| 117 | @brief |
---|
[12212] | 118 | Ends the OrxoBlox minigame. |
---|
[12210] | 119 | */ |
---|
[12212] | 120 | void OrxoBlox::end() |
---|
[12210] | 121 | { |
---|
[12268] | 122 | ChatManager::message("You suck!!"); |
---|
[12359] | 123 | |
---|
| 124 | if (Highscore::exists()) |
---|
| 125 | { |
---|
| 126 | int score = this->getScore(this->getPlayer()); |
---|
[12382] | 127 | Highscore::getInstance().storeScore("OrxoBlox", score, this->getPlayer()); |
---|
[12359] | 128 | } |
---|
| 129 | |
---|
[12210] | 130 | this->cleanup(); |
---|
| 131 | |
---|
| 132 | // Call end for the parent class. |
---|
| 133 | Deathmatch::end(); |
---|
[12395] | 134 | //GSLevel::startMainMenu(); |
---|
[12210] | 135 | } |
---|
| 136 | |
---|
[12359] | 137 | PlayerInfo* OrxoBlox::getPlayer() |
---|
[12337] | 138 | { |
---|
[12359] | 139 | return this->player_; |
---|
[12337] | 140 | } |
---|
| 141 | |
---|
[12210] | 142 | |
---|
[12331] | 143 | void OrxoBlox::LevelUp(){ |
---|
| 144 | level_++; |
---|
[12379] | 145 | int z_ = 0; |
---|
[12376] | 146 | |
---|
| 147 | orxout() << "level up called" << endl; |
---|
[12395] | 148 | this->playerScored(this->player_);// add points |
---|
[12355] | 149 | |
---|
[12351] | 150 | this->createWall(); |
---|
[12360] | 151 | |
---|
[12395] | 152 | for(OrxoBloxStones* stone : ObjectList<OrxoBloxStones>()){ |
---|
| 153 | if (stone->isA(Class(OrxoBloxStones))) { |
---|
[12392] | 154 | int x_=(stone->getPosition()).x; |
---|
| 155 | int y_=(stone->getPosition()).y; |
---|
| 156 | z_=(stone->getPosition()).z; |
---|
| 157 | //if(z_==90)this->end(); |
---|
[12384] | 158 | |
---|
[12392] | 159 | stone->setPosition(x_,y_,z_+9.0f); |
---|
| 160 | if( z_ >= 45){ |
---|
| 161 | orxout() << "calling end() function" << endl; |
---|
| 162 | this->end(); |
---|
[12396] | 163 | return; |
---|
[12392] | 164 | } |
---|
[12376] | 165 | } |
---|
[12395] | 166 | else { |
---|
[12396] | 167 | orxout() << "WTF IS THIS SHIT?!?!?!" << endl; |
---|
[12395] | 168 | } |
---|
[12384] | 169 | } |
---|
[12331] | 170 | } |
---|
[12210] | 171 | |
---|
[12350] | 172 | void OrxoBlox::createWall(){ |
---|
[12307] | 173 | this->futureWall_ = new OrxoBloxWall(this->center_->getContext()); |
---|
| 174 | // Apply the stone template to the stone. |
---|
| 175 | this->futureWall_->addTemplate(this->center_->getWallTemplate()); |
---|
[12210] | 176 | |
---|
[12307] | 177 | // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. |
---|
| 178 | this->center_->attach(this->futureWall_); |
---|
| 179 | |
---|
[12345] | 180 | this->futureWall_->setPosition(0, 0, 0); |
---|
[12307] | 181 | this->futureWall_->setGame(this); |
---|
[12210] | 182 | } |
---|
| 183 | |
---|
[12278] | 184 | |
---|
[12367] | 185 | void OrxoBlox::playerPreSpawn(PlayerInfo* player) |
---|
| 186 | { |
---|
| 187 | this->player_ = player; |
---|
| 188 | } |
---|
[12260] | 189 | |
---|
[12391] | 190 | void OrxoBlox::tick(float dt) |
---|
| 191 | { |
---|
| 192 | SUPER(OrxoBlox, tick, dt); |
---|
| 193 | } |
---|
[12396] | 194 | |
---|
[12394] | 195 | void OrxoBlox::count() { |
---|
[12395] | 196 | if(++(this->counter) >= this->max_counter) { |
---|
[12394] | 197 | this->LevelUp(); |
---|
| 198 | counter = 0; |
---|
| 199 | return; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | |
---|
[12210] | 204 | } |
---|