Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickupsFS14/src/modules/jump/JumpShip.cc @ 10017

Last change on this file since 10017 was 10017, checked in by fvultier, 10 years ago

Steuerung funktioniert

File size: 6.8 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 JumpShip.cc
31    @brief Implementation of the JumpShip class.
32*/
33
34#include "JumpShip.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "Jump.h"
39
40namespace orxonox
41{
42    RegisterClass(JumpShip);
43
44    JumpShip::JumpShip(Context* context) : SpaceShip(context)
45    {
46        RegisterObject(JumpShip);
47
48        //speed = 500;
49        //isFireing = false;
50        //damping = 10;
51        leftPressed = false;
52        rightPressed = false;
53        upPressed = false;
54        downPressed = false;
55
56        yScreenPosition = 0;
57        yVelocity = 0;
58    }
59
60    void JumpShip::tick(float dt)
61    {
62        Vector3 movement(0,0,0);
63        Vector3 shipPosition = getPosition();
64
65        /*
66        //Movement calculation
67        lastTimeFront += dt * damping;
68        lastTimeLeft += dt * damping;
69        lastTime += dt;
70
71        velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
72        velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
73
74        //Execute movement
75        if (this->hasLocalController())
76        {
77            float dist_y = velocity.y * dt;
78            float dist_x = velocity.x * dt;
79            if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
80                posforeward += dist_y;
81            else
82            {
83                velocity.y = 0;
84                // restart if game ended
85                if (getGame())
86                    if (getGame()->bEndGame)
87                    {
88                        getGame()->start();
89                        return;
90                    }
91            }
92            if (pos.z + dist_x > 42*2.5 || pos.z + dist_x < -42*3)
93                velocity.x = 0;
94            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
95
96        }
97
98        // shoot!
99        if (isFireing)
100            ControllableEntity::fire(0);
101                */
102        // Camera
103
104
105
106
107            /*
108        // bring back on track!
109        if(pos.y != 0)
110            pos.y = 0;
111
112        setPosition(pos);
113        setOrientation(Vector3::UNIT_Y, Degree(270));
114
115        // Level up!
116        if (pos.x > 42000)
117        {
118            updateLevel();
119            setPosition(Vector3(0, 0, pos.z)); // pos - Vector3(30000, 0, 0)
120        }
121        */
122
123        // Berechne Bewegung anhand der Eingabe
124        if (leftPressed == true)
125        {
126                movement -= Vector3(xVelocity, 0, 0);
127                leftPressed = false;
128        }
129        else if (rightPressed == true)
130        {
131                movement += Vector3(xVelocity, 0, 0);
132                rightPressed = false;
133        }
134
135        if (upPressed == true)
136        {
137                //movement += Vector3(0, xVelocity, 0);
138                yVelocity = ySpeedAfterJump;
139                upPressed = false;
140        }
141        else if (downPressed == true)
142        {
143                movement -= Vector3(0, 0, 0);
144                downPressed = false;
145        }
146
147        movement += Vector3(0, yVelocity, 0);
148        yVelocity -= yAcceleration;
149
150        // Skalierung der Bewegung je nach vergangener Zeit
151        movement *= dt;
152
153        // Verschiebe das Schiff um den berechneten Vektor movement und verhindere Verlassen des Bildschrims
154        shipPosition.x = clamp(shipPosition.x + movement.x, -xBoundary, xBoundary);
155                shipPosition.y += movement.y;
156
157        setPosition(shipPosition);
158
159        // Bildschirmposition kann nur nach oben verschoben werden
160        if (shipPosition.y > yScreenPosition)
161        {
162                yScreenPosition = shipPosition.y;
163        }
164
165        // Kameraposition nachfuehren
166        if (camera == NULL)
167        {
168                camera = getCamera();
169        }
170        if (camera != NULL)
171        {
172
173            camera->setPosition(Vector3(-shipPosition.x, yScreenPosition-shipPosition.y, 100));
174            //camera->setOrientation(Vector3::UNIT_Z, Degree(180));
175        }
176
177        SUPER(JumpShip, tick, dt);
178    }
179/*
180    void JumpShip::updateLevel()
181    {
182        lastTime = 0;
183        if (getGame())
184            getGame()->levelUp();
185    }*/
186
187    void JumpShip::moveFrontBack(const Vector2& value)
188    {
189        if (value.y < 0)
190        {
191                downPressed = true;
192        }
193        else if (value.y > 0)
194        {
195                upPressed = true;
196        }
197        //lastTimeLeft = 0;
198        //desiredVelocity.x = -value.x * speed;
199    }
200
201    void JumpShip::moveRightLeft(const Vector2& value)
202    {
203        if (value.x < 0)
204        {
205                leftPressed = true;
206        }
207        else if (value.x > 0)
208        {
209                rightPressed = true;
210        }
211        //lastTimeFront = 0;
212        //desiredVelocity.y = value.y * speed * 42;
213    }
214
215    /*
216    void JumpShip::boost(bool bBoost)
217    {
218        isFireing = bBoost;
219    }
220    inline bool JumpShip::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
221    {
222        // orxout() << "touch!!! " << endl; //<< otherObject << " at " << contactPoint;
223        WeakPtr<JumpEnemy> enemy = orxonox_cast<JumpEnemy*>(otherObject);
224        WeakPtr<Projectile> shot = orxonox_cast<Projectile*>(otherObject);
225        // ensure that this gets only called once per enemy.
226        if (enemy != NULL && lastEnemy != enemy)
227        {
228            lastEnemy = enemy;
229
230            removeHealth(20);
231            if (getGame())
232            {
233                getGame()->multiplier = 1;                   
234            }
235        }
236        // was shot, decrease multiplier
237        else if (shot != NULL  && lastShot != shot)
238        {
239            if (getGame() && orxonox_cast<JumpEnemy*>(shot->getShooter()) != NULL)
240            {
241                if (getGame()->multiplier > 1)
242                {
243                    lastShot = shot;
244                    getGame()->multiplier -= 1;     
245                }
246            }
247        }
248        return false;
249        // SUPER(JumpShip, collidesAgainst, otherObject, contactPoint);
250    }
251
252    void JumpShip::death()
253    {
254        getGame()->costLife();
255        SpaceShip::death();
256    }
257*/
258    WeakPtr<Jump> JumpShip::getGame()
259    {
260        if (game == NULL)
261        {
262            for (ObjectList<Jump>::iterator it = ObjectList<Jump>::begin(); it != ObjectList<Jump>::end(); ++it)
263            {
264                game = *it;
265            }
266        }
267        return game;
268    }
269
270}
Note: See TracBrowser for help on using the repository browser.