#include "OrxoBlox.h" #include "Highscore.h" #include "core/CoreIncludes.h" #include "core/EventIncludes.h" #include "core/command/Executor.h" #include "core/config/ConfigValueIncludes.h"//Remove?? #include "gamestates/GSLevel.h" #include "chat/ChatManager.h"//Remove? #include "OrxoBloxCenterpoint.h" #include "OrxoBloxStones.h" #include "OrxoBloxWall.h" #include "OrxoBloxShip.h" namespace orxonox { RegisterUnloadableClass(OrxoBlox); /** @brief Constructor. Registers and initializes the object. */ OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context) { RegisterObject(OrxoBlox); this->center_ = nullptr; //this->ball_ = nullptr; this->futureWall_ = nullptr; this->player_ = nullptr; level_ = 0; this->counter = 0; this->setHUDTemplate("OrxoBloxHUD"); //Error when specified // Pre-set the timer, but don't start it yet. this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::LevelUp, this))); this->starttimer_.stopTimer(); } /** @brief Destructor. Cleans up, if initialized. */ OrxoBlox::~OrxoBlox() { if (this->isInitialized()) this->cleanup(); } /** @brief Cleans up the Gametype by destroying the ball and the bats. */ void OrxoBlox::cleanup() { std::vector vyserion_targets; std::vector casterly_rocks; for (OrxoBloxWall* wall : ObjectList()) { if(wall != nullptr) { vyserion_targets.push_back(wall); } } for (OrxoBloxStones* stone : ObjectList()) { if(stone != nullptr) { casterly_rocks.push_back(stone); } } for(unsigned int i = 0; i < vyserion_targets.size(); i++) { vyserion_targets.at(i)->destroy(); } for(unsigned int i = 0; i < casterly_rocks.size(); i++) { casterly_rocks.at(i)->destroy(); } } /** @brieftt Starts the OrxoBlox minigame. */ void OrxoBlox::start() { orxout() << "Orxoblox started" << endl; if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place. { level_= 1; } else // If no centerpoint was specified, an error is thrown and the level is exited. { orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl; GSLevel::startMainMenu(); return; } this->starttimer_.startTimer(); this->bForceSpawn_ = false; Deathmatch::start(); } /** @brief Ends the OrxoBlox minigame. */ void OrxoBlox::end() { ChatManager::message("You suck!!"); if (Highscore::exists()) { int score = this->getScore(this->getPlayer()); Highscore::getInstance().storeScore("OrxoBlox", score, this->getPlayer()); } this->cleanup(); // Call end for the parent class. Deathmatch::end(); //GSLevel::startMainMenu(); } PlayerInfo* OrxoBlox::getPlayer() { return this->player_; } void OrxoBlox::LevelUp(){ level_++; int z_ = 0; orxout() << "level up called" << endl; this->playerScored(this->player_);// add points this->createWall(); for(OrxoBloxStones* stone : ObjectList()){ if (stone->isA(Class(OrxoBloxStones))) { int x_=(stone->getPosition()).x; int y_=(stone->getPosition()).y; z_=(stone->getPosition()).z; //if(z_==90)this->end(); stone->setPosition(x_,y_,z_+9.0f); if( z_ >= 45){ orxout() << "calling end() function" << endl; this->end(); return; } } else { orxout() << "WTF IS THIS SHIT?!?!?!" << endl; } } } void OrxoBlox::createWall(){ this->futureWall_ = new OrxoBloxWall(this->center_->getContext()); // Apply the stone template to the stone. this->futureWall_->addTemplate(this->center_->getWallTemplate()); // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. this->center_->attach(this->futureWall_); this->futureWall_->setPosition(0, 0, 0); this->futureWall_->setGame(this); } void OrxoBlox::playerPreSpawn(PlayerInfo* player) { this->player_ = player; } void OrxoBlox::tick(float dt) { SUPER(OrxoBlox, tick, dt); } void OrxoBlox::count() { if(++(this->counter) >= this->max_counter) { this->LevelUp(); counter = 0; return; } } }