Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFireball.cc @ 11680

Last change on this file since 11680 was 11653, checked in by zarron, 7 years ago

Boss spawned Gumbas have now max lifetime 2

File size: 5.5 KB
RevLine 
[11567]1    /*
[11556]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 *      Theo von Arx
24 *      Noah Zarro
25 *   Co-authors:
26 *     
27 *
28 */
29
30/**
31    @file SOBFireball.cc
32    @brief Fireballs are the Projectile of the Fireflower Powerup
33*/
34
35#include "SOBFireball.h"
36
37#include "core/CoreIncludes.h"
38#include "core/XMLPort.h"
39#include "SOBFigure.h"
40#include "SOBGumba.h"
[11625]41#include "SOBGumbaBoss.h"   
[11556]42#include "SOB.h"   
43#include "util/Output.h"
44#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
[11599]45#include "graphics/ParticleSpawner.h"
[11556]46
47
48
[11599]49
[11556]50namespace orxonox
51{
52    RegisterClass(SOBFireball);
53
54    SOBFireball::SOBFireball(Context* context) : MovableEntity(context)
55    {
56        RegisterObject(SOBFireball);
57
58        attachedToFigure_ = false;
59        setAngularFactor(0.0);
60        figure_ = nullptr;
61        this->enableCollisionCallback();
[11569]62        gravityAcceleration_ = 350.0;
[11599]63
[11556]64        speed_ = 0;
65        hasCollided_=false;
66        lastPos_ = getPosition();
67        lastPos_.x -= 20;
68        changeAllowed_ = true;
69        changedOn_ = 0.0;
70        goesRight_ = true;
71        collDisX_ = 0;
72        collDisZ_ = 0;
[11575]73        hitCounter_ = 0;
[11599]74        particlespawner_ = NULL ;
75
76
77
78   
79
[11556]80    }
81
82   
83
84    void SOBFireball::XMLPort(Element& xmlelement, XMLPort::Mode mode)
85    {
86        SUPER(SOBFireball, XMLPort, xmlelement, mode);
87        XMLPortParam(SOBFireball, "speed", setSpeed, getSpeed, xmlelement, mode);
88
89
90    }
91
[11577]92    void SOBFireball::setDirection(const bool direction)
93    {
94        if(direction)
95        {
96            goesRight_=true;
97        }
98        else
99        {
100            goesRight_=false;
101        }
102    }
103
[11556]104   
105    bool SOBFireball::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
106        collDisX_ = getPosition().x - contactPoint.getPositionWorldOnB().getX();
107        collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ();
108
[11625]109        SOBGumba*       gumba       = orxonox_cast<SOBGumba*>       (otherObject);
110        SOBGumbaBoss*   gumbaBoss   = orxonox_cast<SOBGumbaBoss*>   (otherObject);
[11556]111
[11653]112        if(gumbaBoss != nullptr && !(gumba->hasCollided_))  //Fireballs can't destroy GumbaBosses, they get destroyed themselves instead
[11625]113        {
114            this->destroyLater();
115            this->hasCollided_ = true;
116        }
[11575]117
[11625]118
119        if(gumba!=nullptr && gumbaBoss == nullptr && !(gumba->hasCollided_)) //if other object is a Gumba, kill the Gumba and add score and destroy the fireball
[11556]120        {
121            gumba->destroyLater();
122            gumba->hasCollided_ = true;
123            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
124            SOBGame->addGumba();
125            this->destroyLater();
126            this->hasCollided_ = true;
127        }
[11575]128
129
[11556]130         //collision with either top or bottom of a block
131        else if(changeAllowed_ && (abs(collDisX_)<=abs(collDisZ_)))
132        {
133            changeAllowed_ = false;
134            Vector3 velocity = getVelocity();
135            velocity.z = -velocity.z;
[11575]136     
[11567]137
[11556]138            setVelocity(velocity);
139        }
140
141        //collision with the vertical side of a block
142        else if(changeAllowed_ && (abs(collDisX_)>abs(collDisZ_))) 
143        {
144            changeAllowed_ = false;
145            goesRight_=!goesRight_;
146        }
147
[11575]148        hitCounter_++;
[11556]149       
[11601]150        collDisZ_=0;
151        collDisX_=0;
152
[11556]153        return true;
154    }
155
156
157    void SOBFireball::setFigure(SOBFigure* newFigure)
158    {
159        figure_ = newFigure;
160    }
161
162
163
164    void SOBFireball::tick(float dt)
165    {
166        SUPER(SOBFireball, tick, dt);
167
[11599]168        //the particle spawner that generates the fire from the backpack when pressed
169        if (particlespawner_ == NULL) {
170            for (WorldEntity* object : this->getAttachedObjects())
171            {
172               if (object->isA(Class(ParticleSpawner)))
173                particlespawner_ = object;
174            }
175
176        }
177
178        if(particlespawner_ != NULL)
179            particlespawner_->setVisible(true);
[11556]180        if (!changeAllowed_) {
181            changedOn_+= dt;
182            // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions!
[11601]183            if (changedOn_> 0.2) {
[11556]184                changeAllowed_ = true;
185                changedOn_ = 0.0;
186
187            }
[11567]188       
[11556]189        }
[11567]190            int dir = 1;
191            if (!goesRight_)
192                dir = -1;
[11556]193
[11567]194            Vector3 velocity = getVelocity();
195            velocity.z -= gravityAcceleration_*dt;
196            velocity.x = dir*speed_;
[11569]197            velocity.y = 0;
[11597]198            if(hitCounter_ >= 3) velocity.y = 0.1*speed_;
[11567]199            setVelocity(velocity);
[11556]200
[11567]201            lastPos_ = getPosition();
[11575]202
203            if(abs(this->getPosition().z) > 1000) delete this;
[11567]204       
[11556]205    }
[11567]206   
[11556]207
208
209}
Note: See TracBrowser for help on using the repository browser.