Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

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