Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Files hinzugefuegt, versucht Aehnlichkeiten mit anderen minigames (dodgerace, invader) zu finden. Testlevel noch zu bearbeiten. Gametype Asteroids crashed immer noch

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