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