Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

updated camera and cube pattern

File size: 6.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 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                }
85               
86
87            }else if(backward){
88                if(velocity.y > 10){
89                     velocity.y -= 10; 
90                }else {
91                    velocity.y = 0; // Prevent players from going backwards
92                }
93                         
94            }else {
95                velocity.y = 0.9 * velocity.y;//reduce speed
96            }
97
98
99
100
101            //float dist_x = velocity.x * dt;
102            //if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
103              //  posforeward += dist_y;
104            //else
105            //{
106                //velocity.y = 0;
107                // restart if game ended
108/*
109                if (getGame())
110                    if (getGame()->bEndGame)
111                    {
112                        getGame()->start();
113                        return;
114                    }*/
115            //}
116
117            //Left right steering
118
119
120            if(steeredLeft){
121                velocity.x += 100;
122                steeredLeft = false;
123
124            }else if(steeredRight) {
125                velocity.x += -100;
126                steeredRight = false;
127            }else {
128                if(velocity.x < -2 || velocity.x > 2 ){
129                    velocity.= velocity.x *0.9;
130                }else{
131                    velocity.x += 0;
132                }
133               
134            }
135
136            pos += Vector3(velocity.y, 0, velocity.x) * dt;
137           
138        }
139
140
141
142        // Camera
143        Camera* camera = this->getCamera();
144        if (camera != nullptr)
145        {
146           camera->setPosition(Vector3(0 ,50,50)); // try to get side/top view
147            //camera->setOrientation(Vector3(-1,-1,0), Degree(45));
148            //camera->setOrientation(Vector3(-1,-1,-1), Degree(0));
149           camera->setOrientation(Vector3::UNIT_Z, Degree(0));
150        }
151
152
153
154        // bring back on track!
155        if(pos.y != 0)
156        {
157            pos.y = 0;
158        }
159
160        setPosition(pos);
161        setOrientation(Vector3::UNIT_Y, Degree(270));
162
163        // Level up!
164        if (pos.x > 42000)
165        {
166            updateLevel();
167            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
168        }
169
170        SUPER(OrxyRoadShip, tick, dt);
171    }
172
173    void OrxyRoadShip::updateLevel()
174    {
175        lastTime = 0;
176        if (getGame())
177            getGame()->levelUp();
178    }
179
180    void OrxyRoadShip::moveFrontBack(const Vector2& value)
181    {
182        this->steering_.z -= value.x ;
183        if(value.x > 0){
184            forward  = true;
185            backward = false;
186        }else if(value.x < 0){
187            forward = false;
188            backward = true;
189        }
190       
191        //lastTimeFront = 0;
192        //desiredVelocity.y = value.y * speed * 42;
193
194    }
195
196    void OrxyRoadShip::moveRightLeft(const Vector2& value)
197    {
198        this->steering_.x += value.x;
199        if(value.x==-1){
200            steeredLeft = false;
201            steeredRight = true;       
202            orxout(user_info) << "Steering RIGHT "<<steering_.x << endl;
203        }else {
204            steeredRight = false;
205            steeredLeft = true;
206             orxout(user_info) << "Steering LEFT "<<steering_.x << endl;
207
208        }
209       
210
211        //lastTimeLeft = 0;
212        //desiredVelocity.x = value.x * speed;
213    }
214    void OrxyRoadShip::boost(bool bBoost)
215    {
216        //bool boosting = bBoost;
217    }
218
219    inline bool OrxyRoadShip::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
220    {
221
222        removeHealth(100);
223        this->death();
224        return false;
225    }
226
227    OrxyRoad* OrxyRoadShip::getGame()
228    {
229        if (game == nullptr)
230        {
231            for (OrxyRoad* race : ObjectList<OrxyRoad>())
232            {
233                game = race;
234            }
235        }
236        return game;
237    }
238
239    void OrxyRoadShip::death()
240    {
241        getGame()->costLife();
242        SpaceShip::death();
243    }
244}
Note: See TracBrowser for help on using the repository browser.