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