#include "AsteroidsShip.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "Asteroids.h" #include "graphics/Camera.h" #include "asteroids/AsteroidStone.h" #include "weapons/projectiles/Projectile.h" #include "asteroids/AsteroidsCenterpoint.h" namespace orxonox { //Constructor RegisterClass(AsteroidsShip); AsteroidsShip::AsteroidsShip(Context* context) : SpaceShip(context) { RegisterObject(AsteroidsShip); angle= 0.0f; isFireing = false; damping = 0.90; lastTimeFront = 0; lastTimeLeft = 0; lastTime = 0; height = this->getGame()->center_->getFieldHeight(); width = this->getGame()->center_->getFieldWidth(); force.x =0; force.y =0; velocity.x = 0; velocity.y = 0; } //Destructor AsteroidsShip::~AsteroidsShip() { if (this->isInitialized()) this->cleanup(); } //update coordinates and velocity void AsteroidsShip::tick(float dt) { //Movement computation beachte Beschleunigung? Vector3 pos = getPosition(); float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y); if(speed > maxspeed) { velocity.x *= maxspeed/speed; velocity.y *= mayspeed/speed; } pos.x += velocity.x*dt; pos.y += velocity.y*dt; //haelt ship innerhalb des Kamerafensters if(x>width) x=0; if(x<0) x=width; if(y>height) y=0; if(y<0) y=height); //Schiessen wenn geschossen wurde // shoot! /* if (isFireing) ControllableEntity::fire(0); */ //Execute movement if (this->hasLocalController()) { force.x += 1; force.y += 1; } //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren Camera* camera = this->getCamera(); if (camera != nullptr) { camera->setPosition(Vector3(0,cameradistance, 0)); camera->setOrientation(Vector3::UNIT_Z, Degree(90)); } // bring back on track! if(pos.y != 0) { pos.y = 0; } velocity.x *= damping; velocity.y *= damping; setPosition(pos); setOrientation(Vector3::UNIT_Y, Degree(270)); SUPER(AsteroidsShip, tick, dt); } void AsteroidsShip::moveFrontBack(const Vector2& value) { velocity.x += 1; } void AsteroidsShip::moveUpDown(const Vector2& value) { velocity.y +=1; } void AsteroidsShip::moveFrontLeftRight(const Vector2& value) { } Asteroids* AsteroidsShip::getGame() { if (game == nullptr) { for (Asteroids* asteroids : ObjectList()) game = asteroids; } return game; } void AsteroidsShip::death() { getGame()->costLife(); SpaceShip::death(); } }