Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Spawn Funktion fuer die Asteroiden veraendert

File size: 3.7 KB
Line 
1#include "AsteroidsShip.h"
2
3#include "core/CoreIncludes.h"
4#include "core/XMLPort.h"
5#include "Asteroids.h"
6#include "graphics/Camera.h"
7#include "asteroids/AsteroidStone.h"
8#include "weapons/projectiles/Projectile.h"
9#include "asteroids/AsteroidsCenterpoint.h"
10
11
12namespace orxonox
13{
14    //Constructor
15    RegisterClass(AsteroidsShip);
16
17    AsteroidsShip::AsteroidsShip(Context* context) : SpaceShip(context)
18    {
19        RegisterObject(AsteroidsShip);
20        /*radius = 20;
21        x = getPosition().x;
22        y = getPosition().y;
23        dx = 3.0f;
24        dy = 3.0f;
25        angle= 0.0f;*/
26
27        speed = 830;
28        isFireing = false;
29        damping = 10;
30
31        lastTimeFront = 0;
32        lastTimeLeft = 0;
33        lastTime = 0;
34
35    }
36
37    //Destructor
38    AsteroidsShip::~AsteroidsShip()
39    {
40        if (this->isInitialized())
41            this->cleanup();
42    }
43
44
45
46    //update coordinates and velocity
47    void AsteroidsShip::tick(float dt)
48    {
49        /*Movement computation
50        Vector3 pos = getPosition();
51
52        dx *= damping;
53        dy *= damping;
54
55        float speed = sqrt(dx*dx+ dy*dy);
56        if(speed > maxspeed)
57        {
58            dx *= maxspeed/speed;
59            dy *= mayspeed/speed;
60        }
61
62        x += dx;
63        y += dy;
64
65        if(x>W) x=0;
66        if(x<0) x=W;
67        if(y>H) y=0;
68        if(y<0) y=H;
69        setPosition(x,y,0);
70
71        //roll? muss sich das Raumschiff drehen?
72        setOrientation(angle, x, y, 0);
73
74        //Schiessen wenn geschossen wurde
75        // shoot!
76        if (isFireing)
77            ControllableEntity::fire(0);
78       
79        //Leben verloren */
80        Vector3 pos = getPosition();
81
82        //Movement calculation
83        lastTimeFront += dt * damping;
84        lastTimeLeft += dt * damping;
85        lastTime += dt;
86
87        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
88        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
89
90        //Execute movement
91        if (this->hasLocalController())
92        {
93            float dist_y = velocity.y * dt;
94            //float dist_x = velocity.x * dt;
95            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
96                posforeward += dist_y;
97            else
98            {
99                velocity.y = 0;
100                // restart if game ended
101/*
102                if (getGame())
103                    if (getGame()->bEndGame)
104                    {
105                        getGame()->start();
106                        return;
107                    }*/
108            }
109
110            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
111
112        }
113
114
115
116        //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren
117        Camera* camera = this->getCamera();
118        if (camera != nullptr)
119        {
120            // camera->setPosition(Vector3(-pos.z, -posforeward, 0));
121            camera->setOrientation(Vector3::UNIT_Z, Degree(0));
122        }
123
124
125
126        // bring back on track!
127        if(pos.y != 0)
128        {
129            pos.y = 0;
130        }
131
132        setPosition(pos);
133        setOrientation(Vector3::UNIT_Y, Degree(270));
134
135        SUPER(AsteroidsShip, tick, dt);
136    }
137
138    void AsteroidsShip::moveFrontBack(const Vector2& value)
139    {
140
141
142    } 
143
144    void AsteroidsShip::moveFrontBack(const Vector2& value)
145    {
146
147    }
148    void AsteroidsShip::moveFrontBack(const Vector2& value)
149    {
150
151    }
152
153    Asteroids* AsteroidsShip::getGame()
154    {
155        if (game == nullptr)
156        {
157            for (Asteroids* asteroids : ObjectList<Asteroids>())
158                game = asteroids;
159        }
160        return game;
161    }
162
163    void AsteroidsShip::death()
164    {
165        getGame()->costLife();
166        SpaceShip::death();
167    }
168
169
170
171}
Note: See TracBrowser for help on using the repository browser.