Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added a HUD and type to QBlocks

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