Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Fixed turning, added and finished Gumbas, added turnOnCollide for all NPC and items, added Flagstone - todo: add points on flagstone hit and go into a between lvl mode, then warp to lvl 2. AAH, and added onDeath fcts…

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