/* * 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: * Fabien Vultier * Co-authors: * ... * */ /** @file SOBFigure.cc @brief This class represents your figure when you play the minigame. Here the movement of the figure, activating items, ... are handled. */ #include "SOBFigure.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "graphics/Model.h" #include "graphics/Camera.h" namespace orxonox { RegisterClass(SOBFigure); SOBFigure::SOBFigure(Context* context) : ControllableEntity(context) { RegisterObject(SOBFigure); // initialize variables moveUpPressed_ = false; moveDownPressed_ = false; moveLeftPressed_ = false; moveDownPressed_ = false; firePressed_ = false; timeSinceLastFire_ = 0.0; lastSpeed_z = 0.0; gravityAcceleration_ = 250.0; pitch_ = 0.0; dead_ = false; setAngularFactor(0.0); } void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(SOBFigure, XMLPort, xmlelement, mode); } void SOBFigure::tick(float dt) { SUPER(SOBFigure, tick, dt); if (hasLocalController()) { Vector3 velocity = getVelocity(); Vector3 position = getPosition(); if (dead_) { velocity.x = 0; velocity.z = 0; setVelocity(velocity); return; } int maxvelocity_x = 100; int speedAddedPerTick = 5; int camMaxOffset = 25; timeSinceLastFire_ += dt; lastSpeed_z = velocity.z; //If player hits space and does not move in z-dir if (firePressed_ && std::abs(velocity.z) < 0.07 && std::abs(lastSpeed_z) < 0.07) { velocity.z = 150; } // rotate(1,getOrientation()* WorldEntity::FRONT) //Left-right movement with acceleration if (moveRightPressed_) { if (std::abs(velocity.x) < maxvelocity_x) { velocity.x += speedAddedPerTick; // if (pitch_ > 0.0) { // pitch -= turn_fac*dt); // } } } else if (moveLeftPressed_) { if (std::abs(velocity.x) < maxvelocity_x) { velocity.x -= speedAddedPerTick; } } else { velocity.x /= 1.1; } velocity.z -= gravityAcceleration_*dt; setVelocity(velocity); //Camera operation Camera* cam = getCamera(); Vector3 campos = cam->getPosition(); if (campos.x + camMaxOffset < position.x) { campos.x = position.x - camMaxOffset; cam->setPosition(campos); } if (campos.x - camMaxOffset > position.x) { campos.x = position.x + camMaxOffset; cam->setPosition(campos); } } // Move through the left and right screen boundaries //setPosition(position); // Reset key variables moveUpPressed_ = false; moveDownPressed_ = false; moveLeftPressed_ = false; moveRightPressed_ = false; moveDownPressed_ = false; firePressed_ = false; } void SOBFigure::moveFrontBack(const Vector2& value) { if (value.x > 0) { moveUpPressed_ = true; moveDownPressed_ = false; } else { moveUpPressed_ = false; moveDownPressed_ = true; } } void SOBFigure::moveRightLeft(const Vector2& value) { if (value.x > 0) { moveLeftPressed_ = false; moveRightPressed_ = true; } else { moveLeftPressed_ = true; moveRightPressed_ = false; } } void SOBFigure::boost(bool boost) { firePressed_ = true; } }