Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11599 was 11599, checked in by varxth, 6 years ago

fireball with particle spawner

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