Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/mac_HS16/src/modules/dodgerace/DodgeRaceShip.cc @ 12373

Last change on this file since 12373 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • 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#include "core/CoreIncludes.h"
36
37namespace orxonox
38{
39    RegisterClass(DodgeRaceShip);
40
41    DodgeRaceShip::DodgeRaceShip(Context* context) : SpaceShip(context)
42    {
43        RegisterObject(DodgeRaceShip);
44
45        speed = 830;
46        isFireing = false;
47        damping = 10;
48
49        // not sure if has to be zero?
50        lastTimeFront = 0;
51        lastTimeLeft = 0;
52        lastTime = 0;
53    }
54
55    void DodgeRaceShip::tick(float dt)
56    {
57        Vector3 pos = getPosition();
58
59        //Movement calculation
60        lastTimeFront += dt * damping;
61        lastTimeLeft += dt * damping;
62        lastTime += dt;
63
64        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
65        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
66
67        //Execute movement
68        if (this->hasLocalController())
69        {
70            float dist_y = velocity.y * dt;
71            //float dist_x = velocity.x * dt;
72            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
73                posforeward += dist_y;
74            else
75            {
76                velocity.y = 0;
77                // restart if game ended
78/*
79                if (getGame())
80                    if (getGame()->bEndGame)
81                    {
82                        getGame()->start();
83                        return;
84                    }*/
85            }
86
87            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
88        }
89
90
91        // Camera
92        Camera* camera = this->getCamera();
93        if (camera != nullptr)
94        {
95            // camera->setPosition(Vector3(-pos.z, -posforeward, 0));
96            camera->setOrientation(Vector3::UNIT_Z, Degree(0));
97        }
98
99
100
101        // bring back on track!
102        if(pos.y != 0)
103        {
104            pos.y = 0;
105        }
106
107        setPosition(pos);
108        setOrientation(Vector3::UNIT_Y, Degree(270));
109
110        // Level up!
111        if (pos.x > 42000)
112        {
113            updateLevel();
114            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
115        }
116
117        SUPER(DodgeRaceShip, tick, dt);
118    }
119
120    void DodgeRaceShip::updateLevel()
121    {
122        lastTime = 0;
123        if (getGame())
124            getGame()->levelUp();
125    }
126
127    void DodgeRaceShip::moveFrontBack(const Vector2& value)
128    {
129        //lastTimeFront = 0;
130        //desiredVelocity.y = value.y * speed * 42;
131
132    }
133
134    void DodgeRaceShip::moveRightLeft(const Vector2& value)
135    {
136        lastTimeLeft = 0;
137        desiredVelocity.x = value.x * speed;
138    }
139    void DodgeRaceShip::boost(bool bBoost)
140    {
141        //getGame()->bEndGame = bBoost;
142    }
143
144    inline bool DodgeRaceShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
145    {
146
147        removeHealth(100);
148        this->death();
149        return false;
150    }
151
152    DodgeRace* DodgeRaceShip::getGame()
153    {
154        if (game == nullptr)
155        {
156            for (DodgeRace* race : ObjectList<DodgeRace>())
157            {
158                game = race;
159            }
160        }
161        return game;
162    }
163
164    void DodgeRaceShip::death()
165    {
166        getGame()->costLife();
167        SpaceShip::death();
168    }
169}
Note: See TracBrowser for help on using the repository browser.