/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * */ /** @file OrxoBlox.cc @brief Implementation of the OrxoBlox class. */ #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->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() { //if (this->ball_ != nullptr) // Destroy the ball, if present. //{ // this->ball_->destroy(); // this->ball_ = nullptr; //} /*if (this->futureWall_ != nullptr) { this->futureWall_->destroy(); this->futureWall_ = nullptr; } */ for (OrxoBloxWall* wall : this->activeWalls_) { if (wall != nullptr) wall->destroy(); } this->activeWalls_.clear(); for (OrxoBloxStones* stone : this->stones_) { if(stone != nullptr) stone->destroy(); } this->stones_.clear(); if(this->playership != nullptr) { this->playership->destroy(); } if(this->center_ != nullptr) { this->center_->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; } // Start the timer. After it has expired the ball is started. this->starttimer_.startTimer(); // Set variable to temporarily force the player to spawn. // Set variable to temporarily force the player to spawn. //bool temp = this->bForceSpawn_; this->bForceSpawn_ = false; // Call start for the parent class. Deathmatch::start(); // Reset the variable. //this->bForceSpawn_ = temp; } /** @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::spawnPlayer(PlayerInfo* player) // { // assert(player); // if(this->player_ == nullptr) // { // this->player_ = player; // this->players_[player].state_ = PlayerState::Alive; // } // } void OrxoBlox::LevelUp(){ level_++; int z_ = 0; orxout() << "level up called" << endl; this->playerScored(this->player_);// add points this->createWall(); this->activeWalls_.push_back(this->futureWall_); for (int i = 0; i < this->futureWall_->getNumberOfStones(); i++) { if (this->futureWall_->getStone(i) == nullptr) { orxout() << "Added nullptr to std::list stones_" << endl; } this->stones_.push_back(this->futureWall_->getStone(i)); } for(OrxoBloxWall* wall : this->activeWalls_) { if(wall->isEmpty()) { wall->destroy(); } int NumberOfStones = 0; for(int i = 0; i < 10; i++) { if(wall->getStone(i) == nullptr) { continue; } else { NumberOfStones++; } } } //new location of ship //new amount of balls //create balls //insert new wall for(OrxoBloxStones* stone : this->stones_){ if (stone != nullptr) { 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(); } } } } 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); } /** @brief Starts the ball with some default speed. */ //void OrxoBlox::startBall() //{ // if (this->ball_ != nullptr && this->center_ != nullptr) // this->ball_->setSpeed(this->center_->getBallSpeed()); //} /*OrxoBloxStones* OrxoBlox::CheckForCollision(OrxoBloxBall* Ball) { //orxout() << "Checking for Collision" << endl; Vector3 BallPosition = Ball->getPosition(); for(OrxoBloxStones* someStone : this->stones_) { if(someStone == nullptr) { continue; } //orxout() << "Checking a stone" << endl; const Vector3& StonePosition = someStone->getPosition(); //!< Saves the position of the currentStone int size = someStone->getSize()/2; if((BallPosition.x - Ball->getRadius() >= StonePosition.x - size && BallPosition.x + Ball->getRadius() <= StonePosition.x + size) && (BallPosition.z - Ball->getRadius() >= StonePosition.z - size && BallPosition.z + Ball->getRadius() <= StonePosition.z + size)) { //orxout() << "FOUND ONE" << endl; return someStone; } } orxout() << "Found nothing...." << endl; return nullptr; } */ void OrxoBlox::playerPreSpawn(PlayerInfo* player) { this->player_ = player; } void OrxoBlox::tick(float dt) { SUPER(OrxoBlox, tick, dt); } /* bool OrxoBlox::Intersect(int XpositionBall, int XPositionBlock, int YPositionBall, int YPositionBlock, int radiusBall, int sizeBlock) { distanceX = XpositionBall - XPositionBlock; distanceY = YPositionBall - YPositionBlock; if (distanceX < 0) { distanceX = -distanceX; } if (distanceY < 0) { distanceY = -distanceY; } if((distanceX <= radiusBall + sizeBlock) || (distanceY <= radiusBall + sizeBlock)) { return true; } else { top = YPositionBall + radiusBall; right = XpositionBall + radiusBall; bottom = YPositionBall - radiusBall; left = XpositionBall - radiusBall; if((top >= YPositionBlock - size) && (top <= YPositionBlock + size) && (left <= XPositionBlock + size) && (left >= XPositionBlock - size)) } } */ }