Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/dodgerace/DodgeRaceShip.cc @ 10525

Last change on this file since 10525 was 10236, checked in by landauf, 10 years ago

replaced tabs with spaces. no changes in code.

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Florian Zinggeler
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file DodgeRaceShip.cc
31    @brief Implementation of the DodgeRaceShip class.
32*/
33
34#include "DodgeRaceShip.h"
35
36namespace orxonox
37{
38    RegisterClass(DodgeRaceShip);
39
40    DodgeRaceShip::DodgeRaceShip(Context* context) : SpaceShip(context)
41    {
42        RegisterObject(DodgeRaceShip);
43
44        speed = 830;
45        isFireing = false;
46        damping = 10;
47
48        // not sure if has to be zero?
49        lastTimeFront = 0;
50        lastTimeLeft = 0;
51        lastTime = 0;
52    }
53
54    void DodgeRaceShip::tick(float dt)
55    {
56        Vector3 pos = getPosition();
57
58        //Movement calculation
59        lastTimeFront += dt * damping;
60        lastTimeLeft += dt * damping;
61        lastTime += dt;
62
63        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
64        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
65
66        //Execute movement
67        if (this->hasLocalController())
68        {
69            float dist_y = velocity.y * dt;
70            //float dist_x = velocity.x * dt;
71            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
72                posforeward += dist_y;
73            else
74            {
75                velocity.y = 0;
76                // restart if game ended
77/*
78                if (getGame())
79                    if (getGame()->bEndGame)
80                    {
81                        getGame()->start();
82                        return;
83                    }*/
84            }
85
86            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
87        }
88
89
90        // Camera
91        WeakPtr<Camera> camera = this->getCamera();
92        if (camera != NULL)
93        {
94            // camera->setPosition(Vector3(-pos.z, -posforeward, 0));
95            camera->setOrientation(Vector3::UNIT_Z, Degree(0));
96        }
97
98
99
100        // bring back on track!
101        if(pos.y != 0)
102        {
103            pos.y = 0;
104        }
105
106        setPosition(pos);
107        setOrientation(Vector3::UNIT_Y, Degree(270));
108
109        // Level up!
110        if (pos.x > 42000)
111        {
112            updateLevel();
113            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
114        }
115
116        SUPER(DodgeRaceShip, tick, dt);
117    }
118
119    void DodgeRaceShip::updateLevel()
120    {
121        lastTime = 0;
122        if (getGame())
123            getGame()->levelUp();
124    }
125
126    void DodgeRaceShip::moveFrontBack(const Vector2& value)
127    {
128        //lastTimeFront = 0;
129        //desiredVelocity.y = value.y * speed * 42;
130
131    }
132
133    void DodgeRaceShip::moveRightLeft(const Vector2& value)
134    {
135        lastTimeLeft = 0;
136        desiredVelocity.x = value.x * speed;
137    }
138    void DodgeRaceShip::boost(bool bBoost)
139    {
140        //getGame()->bEndGame = bBoost;
141    }
142
143    inline bool DodgeRaceShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
144    {
145
146        removeHealth(100);
147        this->death();
148        return false;
149    }
150
151    WeakPtr<DodgeRace> DodgeRaceShip::getGame()
152    {
153        if (game == NULL)
154        {
155            for (ObjectList<DodgeRace>::iterator it = ObjectList<DodgeRace>::begin(); it != ObjectList<DodgeRace>::end(); ++it)
156            {
157                game = *it;
158            }
159        }
160        return game;
161    }
162
163    void DodgeRaceShip::death()
164    {
165        getGame()->costLife();
166        SpaceShip::death();
167    }
168}
Note: See TracBrowser for help on using the repository browser.