Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_HS18/src/modules/orxyroad/OrxyRoadShip.cc @ 12177

Last change on this file since 12177 was 12177, checked in by siramesh, 5 years ago

Super Orxo Bros Final (Sidharth Ramesh, Nisa Balta, Jeff Ren)

File size: 6.7 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 *      Sebastian Hirsch
24 *      Robin Jacobs
25 *   Co-authors:
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 < 300){// Limit for max velocity
83                    velocity.y += 30;
84                    forward = false;
85                }
86               
87
88            }else if(backward){
89                if(velocity.y > 10){
90                     velocity.y -= 30; 
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            if(!steeredLeft&&!steeredRight){
122                    velocity.x = velocity.x *0.8;
123            }
124
125            if(steeredLeft){
126                steeredLeft = false;
127                if(velocity.x<100){//if(!forward) Experimental for only allowing steering left and right when
128                    velocity.x += 6;
129                    steeredLeft = false;
130                }             
131
132            }else if(steeredRight) {
133                steeredRight = false;
134                if(velocity.x>-100){
135                    velocity.x += -6;
136                    steeredRight = false;
137                }       
138            }else {
139                if(velocity.x < -2 || velocity.x > 2 ){
140                    velocity.= velocity.x *0.9;
141                }else{
142                    velocity.x += 0;
143                }
144               
145            }
146
147            pos += Vector3(velocity.y, 0, velocity.x) * dt;
148           
149        }
150
151
152
153        // Camera
154        Camera* camera = this->getCamera();
155        if (camera != nullptr)
156        {
157           camera->setPosition(Vector3(0 ,50,50)); // try to get side/top view
158            //camera->setOrientation(Vector3(-1,-1,0), Degree(45));
159            //camera->setOrientation(Vector3(-1,-1,-1), Degree(0));
160           camera->setOrientation(Vector3::UNIT_Z, Degree(0));
161        }
162
163
164
165        // bring back on track!
166        if(pos.y != 0)
167        {
168            pos.y = 0;
169        }
170
171        setPosition(pos);
172        setOrientation(Vector3::UNIT_Y, Degree(270));
173
174        // Level up!
175        if (pos.x > 42000)
176        {
177            updateLevel();
178            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
179        }
180
181        SUPER(OrxyRoadShip, tick, dt);
182    }
183
184    void OrxyRoadShip::updateLevel()
185    {
186        lastTime = 0;
187        if (getGame())
188            getGame()->levelUp();
189    }
190
191    void OrxyRoadShip::moveFrontBack(const Vector2& value)
192    {
193        this->steering_.z -= value.x ;
194        if(value.x > 0){
195            forward  = true;
196            backward = false;
197        }else if(value.x < 0){
198            forward = false;
199            backward = true;
200        }
201       
202        //lastTimeFront = 0;
203        //desiredVelocity.y = value.y * speed * 42;
204
205    }
206
207    void OrxyRoadShip::moveRightLeft(const Vector2& value)
208    {
209        this->steering_.x += value.x;
210        if(value.x==-1){
211            steeredLeft = false;
212            steeredRight = true;       
213            //orxout(user_info) << "Steering RIGHT "<<steering_.x << endl;
214        }else {
215            steeredRight = false;
216            steeredLeft = true;
217             //orxout(user_info) << "Steering LEFT "<<steering_.x << endl;
218
219        }       
220
221        //lastTimeLeft = 0;
222        //desiredVelocity.x = value.x * speed;
223    }
224    void OrxyRoadShip::boost(bool bBoost)
225    {
226        //bool boosting = bBoost;
227    }
228
229    inline bool OrxyRoadShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
230    {
231
232        removeHealth(100);
233        this->death();
234        return false;
235    }
236
237    OrxyRoad* OrxyRoadShip::getGame()
238    {
239        if (game == nullptr)
240        {
241            for (OrxyRoad* race : ObjectList<OrxyRoad>())
242            {
243                game = race;
244            }
245        }
246        return game;
247    }
248
249    void OrxyRoadShip::death()
250    {
251        getGame()->costLife();
252        SpaceShip::death();
253    }
254}
Note: See TracBrowser for help on using the repository browser.