Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/OrxyRoad_FS18/src/modules/orxyroad/OrxyRoadShip.cc @ 11981

Last change on this file since 11981 was 11981, checked in by sehirsch, 6 years ago

Changed controls

File size: 6.5 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 OrxyRoadShip.cc
31    @brief Implementation of the OrxyRoadShip class.
32*/
33
34#include "OrxyRoadShip.h"
35#include "core/CoreIncludes.h"
36
37namespace orxonox
38{
39    RegisterClass(OrxyRoadShip);
40
41    OrxyRoadShip::OrxyRoadShip(Context* context) : SpaceShip(context)
42    {
43        RegisterObject(OrxyRoadShip);
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        steeredLeft = false;
54        steeredRight = false;
55        forward = false;
56        backward = false;
57    }
58
59    void OrxyRoadShip::tick(float dt)
60    {
61        //orxout(user_info) << "This is some cool output!" << endl;
62
63        Vector3 pos = getPosition();
64        Vector3 pos1 = getPosition();
65
66        //Movement calculation
67        lastTimeFront += dt * damping;
68        lastTimeLeft += dt * damping;
69        lastTime += dt;
70
71       
72        //velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
73        //velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
74
75        //Execute movement
76       
77        if (this->hasLocalController())
78        {
79            float dist_y = velocity.y * dt;
80            //forward backwards movement
81            if(forward){
82                if(velocity.y < 200){// Limit for max velocity
83                    velocity.y += 10;
84                    forward = false;
85                }
86               
87
88            }else if(backward){
89                if(velocity.y > 10){
90                     velocity.y -= 10; 
91                }else {
92                    velocity.y = 0; // Prevent players from going backwards
93                }
94                backward = false;
95                         
96            }else {
97                velocity.y = 0.9 * velocity.y;//reduce speed
98            }
99
100
101
102
103            //float dist_x = velocity.x * dt;
104            //if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
105              //  posforeward += dist_y;
106            //else
107            //{
108                //velocity.y = 0;
109                // restart if game ended
110/*
111                if (getGame())
112                    if (getGame()->bEndGame)
113                    {
114                        getGame()->start();
115                        return;
116                    }*/
117            //}
118
119            //Left right steering
120
121
122            if(steeredLeft){
123                if(true){//if(!forward) Experimental for only allowing steering left and right when
124                    velocity.x += 5;
125                    steeredLeft = false;
126                }
127               
128
129            }else if(steeredRight) {
130                if(true){
131                    velocity.x += -5;
132                    steeredRight = false;
133                }
134            }else {
135                if(velocity.x < -2 || velocity.x > 2 ){
136                    velocity.= velocity.x *0.9;
137                }else{
138                    velocity.x += 0;
139                }
140               
141            }
142
143            pos += Vector3(velocity.y, 0, velocity.x) * dt;
144           
145        }
146
147
148
149        // Camera
150        Camera* camera = this->getCamera();
151        if (camera != nullptr)
152        {
153           camera->setPosition(Vector3(0 ,50,50)); // try to get side/top view
154            //camera->setOrientation(Vector3(-1,-1,0), Degree(45));
155            //camera->setOrientation(Vector3(-1,-1,-1), Degree(0));
156           camera->setOrientation(Vector3::UNIT_Z, Degree(0));
157        }
158
159
160
161        // bring back on track!
162        if(pos.y != 0)
163        {
164            pos.y = 0;
165        }
166
167        setPosition(pos);
168        setOrientation(Vector3::UNIT_Y, Degree(270));
169
170        // Level up!
171        if (pos.x > 42000)
172        {
173            updateLevel();
174            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
175        }
176
177        SUPER(OrxyRoadShip, tick, dt);
178    }
179
180    void OrxyRoadShip::updateLevel()
181    {
182        lastTime = 0;
183        if (getGame())
184            getGame()->levelUp();
185    }
186
187    void OrxyRoadShip::moveFrontBack(const Vector2& value)
188    {
189        this->steering_.z -= value.x ;
190        if(value.x > 0){
191            forward  = true;
192            backward = false;
193        }else if(value.x < 0){
194            forward = false;
195            backward = true;
196        }
197       
198        //lastTimeFront = 0;
199        //desiredVelocity.y = value.y * speed * 42;
200
201    }
202
203    void OrxyRoadShip::moveRightLeft(const Vector2& value)
204    {
205        this->steering_.x += value.x;
206        if(value.x==-1){
207            steeredLeft = false;
208            steeredRight = true;       
209            //orxout(user_info) << "Steering RIGHT "<<steering_.x << endl;
210        }else {
211            steeredRight = false;
212            steeredLeft = true;
213             //orxout(user_info) << "Steering LEFT "<<steering_.x << endl;
214
215        }       
216
217        //lastTimeLeft = 0;
218        //desiredVelocity.x = value.x * speed;
219    }
220    void OrxyRoadShip::boost(bool bBoost)
221    {
222        //bool boosting = bBoost;
223    }
224
225    inline bool OrxyRoadShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
226    {
227
228        removeHealth(100);
229        this->death();
230        return false;
231    }
232
233    OrxyRoad* OrxyRoadShip::getGame()
234    {
235        if (game == nullptr)
236        {
237            for (OrxyRoad* race : ObjectList<OrxyRoad>())
238            {
239                game = race;
240            }
241        }
242        return game;
243    }
244
245    void OrxyRoadShip::death()
246    {
247        getGame()->costLife();
248        SpaceShip::death();
249    }
250}
Note: See TracBrowser for help on using the repository browser.