Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/jump/JumpFigure.cc @ 10260

Last change on this file since 10260 was 10260, checked in by landauf, 9 years ago

merged the latest changes from pickupsFS14 to trunk

File size: 11.0 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 JumpFigure.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 "JumpFigure.h"
35
36#include "core/CoreIncludes.h"
37#include "core/XMLPort.h"
38
39namespace orxonox
40{
41    RegisterClass(JumpFigure);
42
43    JumpFigure::JumpFigure(Context* context) : ControllableEntity(context)
44    {
45        RegisterObject(JumpFigure);
46
47        // initialize variables
48        leftHand_ = NULL;
49        rightHand_ = NULL;
50        fieldHeight_ = 0;
51        fieldWidth_ = 0;
52        jumpSpeed_ = 0.0;
53        handSpeed_ = 0.0;
54        handMaxAngle_ = 0.0;
55        handMinAngle_ = 0.0;
56        rocketPos_ = 0.0;
57        propellerPos_ = 0.0;
58        bootsPos_ = 0.0;
59        moveUpPressed_ = false;
60        moveDownPressed_ = false;
61        moveLeftPressed_ = false;
62        moveDownPressed_ = false;
63        firePressed_ = false;
64        fireSignal_ = false;
65        timeSinceLastFire_ = 0.0;
66        gravityAcceleration_ = 8.0;
67        mouseFactor_ = 75.0;
68        maxFireRate_ = 0.3;
69        handAngle_ = 0.0;
70        animateHands_ = false;
71        turnUp_ = false;
72        rocketActive_ = NULL;
73        propellerActive_ = NULL;
74        bootsActive_ = NULL;
75        shieldActive_ = NULL;
76        rocketSpeed_ = 0.0;
77        propellerSpeed_ = 0.0;
78        dead_ = false;
79    }
80
81    void JumpFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode)
82    {
83        SUPER(JumpFigure, XMLPort, xmlelement, mode);
84        XMLPortParam(JumpFigure, "mouseFactor", setMouseFactor, getMouseFactor, xmlelement, mode);
85        XMLPortParam(JumpFigure, "modelLefthand", setModelLeftHand, getModelLeftHand, xmlelement, mode);
86        XMLPortParam(JumpFigure, "modelRighthand", setModelRightHand, getModelRightHand, xmlelement, mode);
87        XMLPortParam(JumpFigure, "rocketPos", setRocketPos, getRocketPos, xmlelement, mode);
88        XMLPortParam(JumpFigure, "propellerPos", setPropellerPos, getPropellerPos, xmlelement, mode);
89        XMLPortParam(JumpFigure, "bootsPos", setBootsPos, getBootsPos, xmlelement, mode);
90        XMLPortParam(JumpFigure, "jumpSpeed", setJumpSpeed, getJumpSpeed, xmlelement, mode);
91        XMLPortParam(JumpFigure, "rocketSpeed", setRocketSpeed, getRocketSpeed, xmlelement, mode);
92        XMLPortParam(JumpFigure, "propellerSpeed", setPropellerSpeed, getPropellerSpeed, xmlelement, mode);
93        XMLPortParam(JumpFigure, "handMinAngle", setHandMinAngle, getHandMinAngle, xmlelement, mode);
94        XMLPortParam(JumpFigure, "handMaxAngle", setHandMaxAngle, getHandMaxAngle, xmlelement, mode);
95        XMLPortParam(JumpFigure, "handSpeed", setHandSpeed, getHandSpeed, xmlelement, mode);
96    }
97
98    void JumpFigure::tick(float dt)
99    {
100        SUPER(JumpFigure, tick, dt);
101
102        if (hasLocalController())
103        {
104            timeSinceLastFire_ += dt;
105
106            // Move up/down
107            Vector3 velocity = getVelocity();
108            if (rocketActive_ != NULL)
109            {
110                velocity.z = rocketSpeed_;
111            }
112            else if (propellerActive_ != NULL)
113            {
114                velocity.z = propellerSpeed_;
115            }
116            else
117            {
118                velocity.z -= gravityAcceleration_;
119            }
120
121            // Animate Hands
122            if (animateHands_ == true)
123            {
124                if (turnUp_ == true)
125                {
126                    handAngle_ += handSpeed_ * dt;
127                }
128                else
129                {
130                    handAngle_ -= handSpeed_ * dt;
131                }
132                if (handAngle_ > handMaxAngle_)
133                {
134                    turnUp_ = false;
135                }
136                if (handAngle_ <= handMinAngle_)
137                {
138                    animateHands_ = false;
139                }
140
141                if (leftHand_ != NULL)
142                {
143                    leftHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(-handAngle_));
144                }
145                if (rightHand_ != NULL)
146                {
147                    rightHand_->setOrientation(Vector3(0.0, 1.0, 0.0), Degree(handAngle_));
148                }
149            }
150
151            // Move left/right
152            if (dead_ == false)
153            {
154                velocity.x = -mouseFactor_*horizontalSpeed_;
155            }
156            else
157            {
158                velocity.x = 0.0;
159            }
160
161            // Cheats
162            /*if (moveUpPressed_ == true)
163            {
164                velocity.z = 400.0f;
165                moveUpPressed_ = false;
166                dead_ = false;
167            }
168            if (moveDownPressed_ == true)
169            {
170                moveDownPressed_ = false;
171            }*/
172
173            setVelocity(velocity);
174
175
176            if (firePressed_ && timeSinceLastFire_ >= maxFireRate_)
177            {
178                firePressed_ = false;
179                timeSinceLastFire_ = 0.0;
180                fireSignal_ = true;
181            }
182        }
183
184        // Move through the left and right screen boundaries
185        Vector3 position = getPosition();
186        if (position.x < -fieldWidth_*1.1f)
187        {
188            position.x = fieldWidth_*1.1f;
189        }
190        else if (position.x > fieldWidth_*1.1f)
191        {
192            position.x = -fieldWidth_*1.1f;
193        }
194        setPosition(position);
195
196        // Reset key variables
197        moveUpPressed_ = false;
198        moveDownPressed_ = false;
199        moveLeftPressed_ = false;
200        moveDownPressed_ = false;
201        firePressed_ = false;
202    }
203
204    void JumpFigure::JumpFromPlatform(JumpPlatform* platform)
205    {
206        if (dead_ == false)
207        {
208            Vector3 velocity = getVelocity();
209            if (bootsActive_ == NULL)
210            {
211                velocity.z = 1.2f*jumpSpeed_;
212            }
213            else
214            {
215                velocity.z = jumpSpeed_;
216            }
217            setVelocity(velocity);
218            animateHands_ = true;
219            handAngle_ = 0.0;
220            turnUp_ = true;
221        }
222    }
223
224    void JumpFigure::JumpFromSpring(JumpSpring* spring)
225    {
226        if (dead_ == false)
227        {
228            Vector3 velocity = getVelocity();
229            velocity.z = 1.2f*jumpSpeed_;
230            setVelocity(velocity);
231        }
232    }
233
234    void JumpFigure::CollisionWithEnemy(JumpEnemy* enemy)
235    {
236        if (rocketActive_ == NULL && propellerActive_ == NULL && shieldActive_ == NULL)
237        {
238            dead_ = true;
239        }
240    }
241
242    bool JumpFigure::StartRocket(JumpRocket* rocket)
243    {
244        if (rocketActive_ == NULL && propellerActive_ == NULL && bootsActive_ == NULL)
245        {
246            attach(rocket);
247            rocket->setPosition(0.0, rocketPos_, 0.0);
248            rocket->setVelocity(0.0, 0.0, 0.0);
249            rocketActive_ = rocket;
250
251            return true;
252        }
253
254        return false;
255    }
256
257    void JumpFigure::StopRocket(JumpRocket* rocket)
258    {
259        rocket->setPosition(0.0, 0.0, -1000.0);
260        rocket->setVelocity(0.0, 0.0, 0.0);
261        detach(rocket);
262        rocket->destroy();
263        rocketActive_ = NULL;
264    }
265
266    bool JumpFigure::StartPropeller(JumpPropeller* propeller)
267    {
268        if (rocketActive_ == NULL && propellerActive_ == NULL && bootsActive_ == NULL)
269        {
270            attach(propeller);
271            propeller->setPosition(0.0, 0.0, propellerPos_);
272            propeller->setVelocity(0.0, 0.0, 0.0);
273            propellerActive_ = propeller;
274
275            return true;
276        }
277
278        return false;
279    }
280
281    void JumpFigure::StopPropeller(JumpPropeller* propeller)
282    {
283        propeller->setPosition(0.0, 0.0, -1000.0);
284        propeller->setVelocity(0.0, 0.0, 0.0);
285        detach(propeller);
286        propeller->destroy();
287        propellerActive_ = NULL;
288    }
289
290    bool JumpFigure::StartBoots(JumpBoots* boots)
291    {
292        if (rocketActive_ == NULL && propellerActive_ == NULL && bootsActive_ == NULL)
293        {
294            attach(boots);
295            boots->setPosition(0.0, 0.0, bootsPos_);
296            boots->setVelocity(0.0, 0.0, 0.0);
297            bootsActive_ = boots;
298
299            return true;
300        }
301
302        return false;
303    }
304
305    void JumpFigure::StopBoots(JumpBoots* boots)
306    {
307        boots->setPosition(0.0, 0.0, -1000.0);
308        boots->setVelocity(0.0, 0.0, 0.0);
309        detach(boots);
310        boots->destroy();
311        bootsActive_ = NULL;
312    }
313
314    bool JumpFigure::StartShield(JumpShield* shield)
315    {
316        if (shieldActive_ == false)
317        {
318            attach(shield);
319            shield->setPosition(0.0, 0.0, propellerPos_);
320            shield->setVelocity(0.0, 0.0, 0.0);
321            shieldActive_ = shield;
322
323            return true;
324        }
325
326        return false;
327    }
328
329    void JumpFigure::StopShield(JumpShield* shield)
330    {
331        shield->setPosition(0.0, 0.0, -1000.0);
332        shield->setVelocity(0.0, 0.0, 0.0);
333        detach(shield);
334        shield->destroy();
335        shieldActive_ = NULL;
336    }
337
338    void JumpFigure::InitializeAnimation(Context* context)
339    {
340        leftHand_ = new Model(context);
341        rightHand_ = new Model(context);
342
343        leftHand_->addTemplate(modelLeftHand_);
344        rightHand_->addTemplate(modelRightHand_);
345
346        attach(leftHand_);
347        attach(rightHand_);
348    }
349
350    void JumpFigure::moveFrontBack(const Vector2& value)
351    {
352        if (value.x > 0)
353        {
354            moveUpPressed_ = true;
355            moveDownPressed_ = false;
356        }
357        else
358        {
359            moveUpPressed_ = false;
360            moveDownPressed_ = true;
361        }
362    }
363
364    void JumpFigure::moveRightLeft(const Vector2& value)
365    {
366        if (value.x > 0)
367        {
368            moveLeftPressed_ = false;
369            moveRightPressed_ = true;
370        }
371        else
372        {
373            moveLeftPressed_ = true;
374            moveRightPressed_ = false;
375        }
376    }
377
378    void JumpFigure::rotateYaw(const Vector2& value)
379    {
380        horizontalSpeed_ = value.x;
381    }
382
383    void JumpFigure::rotatePitch(const Vector2& value)
384    {
385
386
387    }
388
389    void JumpFigure::rotateRoll(const Vector2& value)
390    {
391
392
393    }
394
395    void JumpFigure::fire(unsigned int firemode)
396    {
397
398    }
399
400    void JumpFigure::fired(unsigned int firemode)
401    {
402        firePressed_ = true;
403    }
404}
Note: See TracBrowser for help on using the repository browser.