/* * 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: * Joel Lingg * Co-authors: * ... * */ #include "StoryModeController.h" namespace orxonox { RegisterClass(StoryModeController); StoryModeController::StoryModeController(Context * context): SpaceShip(context) { RegisterObject(StoryModeController); //initiate all variables according to our needs selectedPos_ = new SMCoord(0); moveForward_ = false; moveBackward_ = false; boostPressed_ = false; init_ = true; dtime_ = 50; time_ = dtime_ + 1; updatePosition(); } StoryModeController::~StoryModeController() { delete selectedPos_; selectedPos_ = nullptr; } //Pre:selectedPos_ needs to be defined // Post: the position of the camera will be updated void StoryModeController::updatePosition() { Vector3 pos = selectedPos_ -> get3dcoordinate(); setPosition(pos); } //Pre: @index integer //post: our new position is updated in selectedPos_ void StoryModeController::setLocation(int index) { selectedPos_ -> set(index); } //Function which is repeated anz dt. void StoryModeController::tick(float dt) { //Passing arguments to SpaceShip SUPER(StoryModeController, tick, dt); Camera * camera = this -> getCamera(); if (init_ && camera != nullptr) { camera -> setPosition(0, 0, 200); camera -> setOrientation(Vector3::UNIT_Z, Degree(0)); init_ = false; } //As I dont want to update positions every time (to prevent multiple key presses) time_ is raised untill a sertain dtime_ time_++; if (time_ >= dtime_) { time_ = 0; if (moveForward_ == true) { moveForward_ = false; selectedPos_ -> set(selectedPos_ -> getIndex() + 1); updatePosition(); } if (moveBackward_ == true) { moveBackward_ = false; selectedPos_ -> set(selectedPos_ -> getIndex() - 1); updatePosition(); } if (boostPressed_ == true) { boostPressed_ = false; chooseGame(); } //updates the cameraposition if (camera != nullptr) { camera -> setPosition(0, 0, 200); camera -> setOrientation(Vector3::UNIT_Z, Degree(0)); } } } //Post: The game is choosen acording to the index in selectedPos_. This one must be extended if more games want to be loaded void StoryModeController::chooseGame() { int ind = selectedPos_ -> getIndex(); std::string name = "changeGame "; switch (ind) { case 0: name = name + "gallery.oxw"; break; case 1: name = name + "pong.oxw"; break; case 2: name = name + "towerDefense.oxw"; break; case 3: name = name + "SOB.oxw"; break; default: name = name + "MapExample.oxw"; break; } CommandExecutor::execute(name); } //decides if we move left or right void StoryModeController::moveRightLeft(const Vector2 & value) { if (!moveForward_ && !moveBackward_ && !boostPressed_) { if (value.x > 0) { moveForward_ = false; moveBackward_ = true; } else { moveBackward_ = false; moveForward_ = true; } } } //decides to choose the game void StoryModeController::boost(bool bBoost) { if (!moveForward_ && !moveBackward_ && !boostPressed_) { boostPressed_ = true; } } //Some functions I didn't use, but can be used to enhance your map. Just orientate at the function above void StoryModeController::rotateYaw(const Vector2 & value) {} void StoryModeController::rotatePitch(const Vector2 & value) {} void StoryModeController::rotateRoll(const Vector2 & value) {} void StoryModeController::moveFrontBack(const Vector2 & value) {} void StoryModeController::fire(unsigned int a) {} void StoryModeController::fired(unsigned int b) {} }