/* * 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: * Sebastian Hirsch * Robin Jacobs * Co-authors: * */ /** @file OrxyRoadShip.cc @brief Implementation of the OrxyRoadShip class. */ #include "OrxyRoadShip.h" #include "core/CoreIncludes.h" namespace orxonox { RegisterClass(OrxyRoadShip); OrxyRoadShip::OrxyRoadShip(Context* context) : SpaceShip(context) { RegisterObject(OrxyRoadShip); speed = 830; isFireing = false; damping = 10; // not sure if has to be zero? lastTimeFront = 0; lastTimeLeft = 0; lastTime = 0; steeredLeft = false; steeredRight = false; forward = false; backward = false; } void OrxyRoadShip::tick(float dt) { //orxout(user_info) << "This is some cool output!" << endl; Vector3 pos = getPosition(); //Vector3 pos1 = getPosition(); //Movement calculation lastTimeFront += dt * damping; lastTimeLeft += dt * damping; lastTime += dt; //velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f); //velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f); //Execute movement if (this->hasLocalController()) { //float dist_y = velocity.y * dt; //forward backwards movement if(forward){ if(velocity.y < 300){// Limit for max velocity velocity.y += 30; forward = false; } }else if(backward){ if(velocity.y > 10){ velocity.y -= 30; }else { velocity.y = 0; // Prevent players from going backwards } backward = false; }else { velocity.y = 0.9 * velocity.y;//reduce speed } //float dist_x = velocity.x * dt; //if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6) // posforeward += dist_y; //else //{ //velocity.y = 0; // restart if game ended /* if (getGame()) if (getGame()->bEndGame) { getGame()->start(); return; }*/ //} //Left right steering if(!steeredLeft&&!steeredRight){ velocity.x = velocity.x *0.8; } if(steeredLeft){ steeredLeft = false; if(velocity.x<100){//if(!forward) Experimental for only allowing steering left and right when velocity.x += 6; steeredLeft = false; } }else if(steeredRight) { steeredRight = false; if(velocity.x>-100){ velocity.x += -6; steeredRight = false; } }else { if(velocity.x < -2 || velocity.x > 2 ){ velocity.x = velocity.x *0.9; }else{ velocity.x += 0; } } pos += Vector3(velocity.y, 0, velocity.x) * dt; } // Camera Camera* camera = this->getCamera(); if (camera != nullptr) { camera->setPosition(Vector3(0 ,50,50)); // try to get side/top view //camera->setOrientation(Vector3(-1,-1,0), Degree(45)); //camera->setOrientation(Vector3(-1,-1,-1), Degree(0)); camera->setOrientation(Vector3::UNIT_Z, Degree(0)); } // bring back on track! if(pos.y != 0) { pos.y = 0; } setPosition(pos); setOrientation(Vector3::UNIT_Y, Degree(270)); // Level up! if (pos.x > 42000) { updateLevel(); setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0) } SUPER(OrxyRoadShip, tick, dt); } void OrxyRoadShip::updateLevel() { lastTime = 0; if (getGame()) getGame()->levelUp(); } void OrxyRoadShip::moveFrontBack(const Vector2& value) { this->steering_.z -= value.x ; if(value.x > 0){ forward = true; backward = false; }else if(value.x < 0){ forward = false; backward = true; } //lastTimeFront = 0; //desiredVelocity.y = value.y * speed * 42; } void OrxyRoadShip::moveRightLeft(const Vector2& value) { this->steering_.x += value.x; if(value.x==-1){ steeredLeft = false; steeredRight = true; //orxout(user_info) << "Steering RIGHT "<death(); return false; } OrxyRoad* OrxyRoadShip::getGame() { if (game == nullptr) { for (OrxyRoad* race : ObjectList()) { game = race; } } return game; } void OrxyRoadShip::death() { getGame()->costLife(); SpaceShip::death(); } }