Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11634 was 11625, checked in by varxth, 7 years ago

improvment

File size: 5.4 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 "SOBGumbaBoss.h"   
42#include "SOB.h"   
43#include "util/Output.h"
44#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
45#include "graphics/ParticleSpawner.h"
46
47
48
49
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();
62        gravityAcceleration_ = 350.0;
63
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;
73        hitCounter_ = 0;
74        particlespawner_ = NULL ;
75
76
77
78   
79
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
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
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
109        SOBGumba*       gumba       = orxonox_cast<SOBGumba*>       (otherObject);
110        SOBGumbaBoss*   gumbaBoss   = orxonox_cast<SOBGumbaBoss*>   (otherObject);
111
112        if(gumbaBoss != nullptr && !(gumba->hasCollided_))
113        {
114            this->destroyLater();
115            this->hasCollided_ = true;
116        }
117
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
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        }
128
129
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;
136     
137
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
148        hitCounter_++;
149       
150        collDisZ_=0;
151        collDisX_=0;
152
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
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);
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!
183            if (changedOn_> 0.2) {
184                changeAllowed_ = true;
185                changedOn_ = 0.0;
186
187            }
188       
189        }
190            int dir = 1;
191            if (!goesRight_)
192                dir = -1;
193
194            Vector3 velocity = getVelocity();
195            velocity.z -= gravityAcceleration_*dt;
196            velocity.x = dir*speed_;
197            velocity.y = 0;
198            if(hitCounter_ >= 3) velocity.y = 0.1*speed_;
199            setVelocity(velocity);
200
201            lastPos_ = getPosition();
202
203            if(abs(this->getPosition().z) > 1000) delete this;
204       
205    }
206   
207
208
209}
Note: See TracBrowser for help on using the repository browser.