Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SuperOrxoBros_FS17/src/modules/superorxobros/SOBFigure.cc @ 11400

Last change on this file since 11400 was 11400, checked in by jkindle, 7 years ago

Added jetpack, rotation of player, Questionmark-blocks and Hitlistener for the QBlocks. Made description for David in XML file for usage of hittable blocks

File size: 5.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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file SOBFigure.cc
31    @brief This class represents your figure when you play the minigame. Here the movement of the figure, activating items, ... are handled.
32*/
33
34#include "SOBFigure.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38#include "graphics/Model.h"
39#include "graphics/Camera.h"
40#include "graphics/ParticleSpawner.h"
41
42
43namespace orxonox
44{
45    RegisterClass(SOBFigure);
46
47    SOBFigure::SOBFigure(Context* context) : ControllableEntity(context)
48    {
49        RegisterObject(SOBFigure);
50
51        // initialize variables
52
53        moveUpPressed_ = false;
54        moveDownPressed_ = false;
55        moveLeftPressed_ = false;
56        moveDownPressed_ = false;
57        firePressed_ = false;
58        timeSinceLastFire_ = 0.0;
59        lastSpeed_z = 0.0;
60        isColliding_ = true;
61        particlespawner_ = NULL;
62
63        gravityAcceleration_ = 350.0;
64        pitch_ = 0.0;
65
66        dead_ = false;
67        setAngularFactor(0.0);
68         this->enableCollisionCallback();
69    }
70
71
72
73    bool SOBFigure::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
74
75        isColliding_ = true;
76
77
78return true;
79    }
80
81
82
83    void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode)
84    {
85        SUPER(SOBFigure, XMLPort, xmlelement, mode);
86
87    }
88
89
90
91    void SOBFigure::tick(float dt)
92    {
93        SUPER(SOBFigure, tick, dt);
94
95        if (particlespawner_ == NULL) {
96            for (WorldEntity* object : this->getAttachedObjects())
97            {
98                 if (object->isA(Class(ParticleSpawner)))
99                    particlespawner_ = object;
100                   
101            }
102 
103        }
104       
105
106
107
108
109        if (firePressed_ == false) {
110             gravityAcceleration_ = 350.0;
111
112        }
113
114        if (hasLocalController())
115        {
116          Vector3 velocity = getVelocity();
117          Vector3 position = getPosition();
118
119          if (dead_) {
120            velocity.x = 0;
121            velocity.z = 0;
122            setVelocity(velocity);
123            return;
124        }
125
126
127        int maxvelocity_x = 100;
128        int speedAddedPerTick = 5;
129        int camMaxOffset = 25;
130
131        timeSinceLastFire_ += dt;
132        lastSpeed_z = velocity.z;
133
134
135
136        //Handle the rocket fire from the jetpack
137        if (velocity.z > 40)
138            particlespawner_->setVisible(true); 
139        else
140            particlespawner_->setVisible(false); 
141
142        //If player hits space and does not move in z-dir
143        if (firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) {
144            gravityAcceleration_ = 100.0;
145            velocity.z = 110; //150
146        }
147
148      // rotate(1,getOrientation()* WorldEntity::FRONT)
149
150
151        //Left-right movement with acceleration
152        float rot = getOrientation().getRoll().valueDegrees();
153        if (moveRightPressed_) {
154            if (rot < 0.0)
155                    setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6));
156
157            if (std::abs(velocity.x) < maxvelocity_x) {
158                velocity.x += speedAddedPerTick;
159
160               
161
162               
163
164                // if (pitch_ > 0.0) {
165                //     pitch -= turn_fac*dt);
166                // }
167            }
168        } else if (moveLeftPressed_) {
169            if (rot >= 0.0)
170                    setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() + dt*Radian(6));
171
172            if (std::abs(velocity.x) < maxvelocity_x) {
173                velocity.x -= speedAddedPerTick;
174            }
175        } else {
176            velocity.x /= 1.1;
177        }
178
179
180        velocity.z -= gravityAcceleration_*dt;
181        setVelocity(velocity);
182
183
184        //Camera operation
185        Camera* cam = getCamera();
186        Vector3 campos = cam->getPosition();
187
188        if (campos.x + camMaxOffset < position.x) {
189            campos.x = position.x - camMaxOffset;
190            cam->setPosition(campos);
191        }
192           if (campos.x - camMaxOffset > position.x) {
193            campos.x = position.x + camMaxOffset;
194            cam->setPosition(campos);
195        }
196
197
198
199
200    }
201
202        // Move through the left and right screen boundaries
203
204        //setPosition(position);
205
206        // Reset key variables
207    moveUpPressed_ = false;
208    moveDownPressed_ = false;
209    moveLeftPressed_ = false;
210    moveRightPressed_ = false;
211    moveDownPressed_ = false;
212    isColliding_ = false;
213
214}
215
216
217
218
219
220
221void SOBFigure::moveFrontBack(const Vector2& value)
222{
223    if (value.x > 0)
224    {
225        moveUpPressed_ = true;
226        moveDownPressed_ = false;
227    }
228    else
229    {
230        moveUpPressed_ = false;
231        moveDownPressed_ = true;
232    }
233}
234
235void SOBFigure::moveRightLeft(const Vector2& value)
236{
237    if (value.x > 0)
238    {
239        moveLeftPressed_ = false;
240        moveRightPressed_ = true;
241    }
242    else
243    {
244        moveLeftPressed_ = true;
245        moveRightPressed_ = false;
246    }
247}
248
249
250
251
252
253void SOBFigure::boost(bool boost)
254{
255    firePressed_ = boost;
256}
257}
Note: See TracBrowser for help on using the repository browser.