Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc @ 11541

Last change on this file since 11541 was 11541, checked in by vyang, 7 years ago

TestLevel Design → immer noch mit Fehlermeldungen, Asteroiden in der death() Methode von AsteroidsStone spawnen oder im game?

File size: 3.0 KB
RevLine 
[11506]1#include "AsteroidsShip.h"
2
3#include "core/CoreIncludes.h"
4#include "core/XMLPort.h"
[11516]5#include "Asteroids.h"
[11506]6#include "graphics/Camera.h"
[11528]7#include "asteroids/AsteroidStone.h"
[11506]8#include "weapons/projectiles/Projectile.h"
[11528]9#include "asteroids/AsteroidsCenterpoint.h"
[11506]10
[11516]11
[11506]12namespace orxonox
13{
14    //Constructor
15    RegisterClass(AsteroidsShip);
16
17    AsteroidsShip::AsteroidsShip(Context* context) : SpaceShip(context)
18    {
19        RegisterObject(AsteroidsShip);
20
[11541]21        angle= 0.0f;
22
23
24
[11516]25        isFireing = false;
[11541]26        damping = 0.90;
[11516]27
28        lastTimeFront = 0;
29        lastTimeLeft = 0;
30        lastTime = 0;
31
[11541]32        height = this->getGame()->center_->getFieldHeight();
33        width = this->getGame()->center_->getFieldWidth();
34
35        force.x =0;
36        force.y =0;
37
38        velocity.x = 0;
39        velocity.y = 0;
40
[11506]41    }
[11516]42
[11506]43    //Destructor
44    AsteroidsShip::~AsteroidsShip()
45    {
46        if (this->isInitialized())
47            this->cleanup();
48    }
49
50
51
52    //update coordinates and velocity
53    void AsteroidsShip::tick(float dt)
54    {
[11541]55        //Movement computation beachte Beschleunigung?
[11516]56        Vector3 pos = getPosition();
57
[11541]58        float speed = sqrt(velocity.x*velocity.x+ velocity.y*velocity.y);
[11516]59        if(speed > maxspeed)
60        {
[11541]61            velocity.x *= maxspeed/speed;
62            velocity.y *= mayspeed/speed;
[11516]63        }
64
[11541]65        pos.x += velocity.x*dt;
66        pos.y += velocity.y*dt;
[11516]67
68
[11541]69        //haelt ship innerhalb des Kamerafensters
70        if(x>width) x=0;
71        if(x<0) x=width;
72        if(y>height) y=0;
73        if(y<0) y=height);
[11506]74
[11541]75
[11506]76        //Schiessen wenn geschossen wurde
77        // shoot!
[11541]78/*
[11506]79        if (isFireing)
80            ControllableEntity::fire(0);
[11541]81        */
[11516]82
83        //Execute movement
84        if (this->hasLocalController())
85        {
[11541]86            force.x += 1;
87            force.y += 1;
[11516]88
89        }
90
91
[11528]92
93        //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren
[11516]94        Camera* camera = this->getCamera();
95        if (camera != nullptr)
96        {
[11541]97            camera->setPosition(Vector3(0,cameradistance, 0));
98            camera->setOrientation(Vector3::UNIT_Z, Degree(90));
[11516]99        }
100
101
102
103        // bring back on track!
104        if(pos.y != 0)
105        {
106            pos.y = 0;
107        }
108
[11541]109        velocity.x *= damping;
110        velocity.y *= damping;
111
[11516]112        setPosition(pos);
113        setOrientation(Vector3::UNIT_Y, Degree(270));
114
115        SUPER(AsteroidsShip, tick, dt);
[11541]116
[11506]117    }
[11528]118
119    void AsteroidsShip::moveFrontBack(const Vector2& value)
120    {
[11541]121        velocity.x += 1;
[11528]122    } 
123
[11541]124    void AsteroidsShip::moveUpDown(const Vector2& value)
[11528]125    {
[11541]126        velocity.y +=1;
[11528]127
128    }
[11541]129    void AsteroidsShip::moveFrontLeftRight(const Vector2& value)
[11528]130    {
131
132    }
133
[11516]134    Asteroids* AsteroidsShip::getGame()
135    {
136        if (game == nullptr)
137        {
138            for (Asteroids* asteroids : ObjectList<Asteroids>())
139                game = asteroids;
140        }
141        return game;
142    }
[11506]143
[11528]144    void AsteroidsShip::death()
[11516]145    {
146        getGame()->costLife();
147        SpaceShip::death();
148    }
[11506]149
150
151
152}
Note: See TracBrowser for help on using the repository browser.