#include "AsteroidsShip.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "Asteroids.h" #include "graphics/Camera.h" #include "asteroids/AsteroidStone" #include "weapons/projectiles/Projectile.h" namespace orxonox { //Constructor RegisterClass(AsteroidsShip); AsteroidsShip::AsteroidsShip(Context* context) : SpaceShip(context) { RegisterObject(AsteroidsShip); /*radius = 20; x = getPosition().x; y = getPosition().y; dx = 3.0f; dy = 3.0f; angle= 0.0f;*/ speed = 830; isFireing = false; damping = 10; lastTimeFront = 0; lastTimeLeft = 0; lastTime = 0; } //Destructor AsteroidsShip::~AsteroidsShip() { if (this->isInitialized()) this->cleanup(); } //update coordinates and velocity void AsteroidsShip::tick(float dt) { /*Movement computation Vector3 pos = getPosition(); dx *= damping; dy *= damping; float speed = sqrt(dx*dx+ dy*dy); if(speed > maxspeed) { dx *= maxspeed/speed; dy *= mayspeed/speed; } x += dx; y += dy; if(x>W) x=0; if(x<0) x=W; if(y>H) y=0; if(y<0) y=H; setPosition(x,y,0); //roll? muss sich das Raumschiff drehen? setOrientation(angle, x, y, 0); //Schiessen wenn geschossen wurde // shoot! if (isFireing) ControllableEntity::fire(0); //Leben verloren */ Vector3 pos = 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; //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; }*/ } pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt; } // Camera Camera* camera = this->getCamera(); if (camera != nullptr) { // camera->setPosition(Vector3(-pos.z, -posforeward, 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)); SUPER(AsteroidsShip, tick, dt); } Asteroids* AsteroidsShip::getGame() { if (game == nullptr) { for (Asteroids* asteroids : ObjectList()) game = asteroids; } return game; } void InvaderShip::death() { getGame()->costLife(); SpaceShip::death(); } }