| 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 | |
|---|
| 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(); |
|---|
| 60 | gravityAcceleration_ = 350.0; |
|---|
| 61 | |
|---|
| 62 | speed_ = 0; |
|---|
| 63 | hasCollided_=false; |
|---|
| 64 | changeAllowed_ = true; |
|---|
| 65 | changedOn_ = 0.0; |
|---|
| 66 | goesRight_ = true; |
|---|
| 67 | hitCounter_ = 0; |
|---|
| 68 | particlespawner_ = NULL ; |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 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 | |
|---|
| 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 | |
|---|
| 98 | |
|---|
| 99 | bool SOBFireball::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { |
|---|
| 100 | float collDisX_ = getPosition().x - contactPoint.getPositionWorldOnB().getX(); |
|---|
| 101 | float collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ(); |
|---|
| 102 | |
|---|
| 103 | SOBGumba* gumba = orxonox_cast<SOBGumba*> (otherObject); |
|---|
| 104 | SOBGumbaBoss* gumbaBoss = orxonox_cast<SOBGumbaBoss*> (otherObject); |
|---|
| 105 | |
|---|
| 106 | if(gumbaBoss != nullptr && !(gumba->hasCollided_)) //Fireballs can't destroy GumbaBosses, they get destroyed themselves instead |
|---|
| 107 | { |
|---|
| 108 | this->destroyLater(); |
|---|
| 109 | this->hasCollided_ = true; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 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 |
|---|
| 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 | } |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 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; |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 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 | |
|---|
| 142 | hitCounter_++; |
|---|
| 143 | |
|---|
| 144 | return true; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | void SOBFireball::tick(float dt) |
|---|
| 149 | { |
|---|
| 150 | SUPER(SOBFireball, tick, dt); |
|---|
| 151 | |
|---|
| 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); |
|---|
| 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! |
|---|
| 167 | if (changedOn_> 0.2) { |
|---|
| 168 | changeAllowed_ = true; |
|---|
| 169 | changedOn_ = 0.0; |
|---|
| 170 | |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | } |
|---|
| 174 | int dir = 1; |
|---|
| 175 | if (!goesRight_) |
|---|
| 176 | dir = -1; |
|---|
| 177 | |
|---|
| 178 | Vector3 velocity = getVelocity(); |
|---|
| 179 | velocity.z -= gravityAcceleration_*dt; |
|---|
| 180 | velocity.x = dir*speed_; |
|---|
| 181 | velocity.y = 0; |
|---|
| 182 | if(hitCounter_ >= 3) velocity.y = 0.1f*speed_; |
|---|
| 183 | setVelocity(velocity); |
|---|
| 184 | |
|---|
| 185 | if(abs(this->getPosition().z) > 1000) this->destroyLater(); |
|---|
| 186 | |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | } |
|---|