/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Theo von Arx * Noah Zarro * Co-authors: * * */ /** @file SOBFireball.cc @brief Fireballs are the Projectile of the Fireflower Powerup */ #include "SOBFireball.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "SOBFigure.h" #include "SOBGumba.h" #include "SOBGumbaBoss.h" #include "SOB.h" #include "util/Output.h" #include #include "graphics/ParticleSpawner.h" namespace orxonox { RegisterClass(SOBFireball); SOBFireball::SOBFireball(Context* context) : MovableEntity(context) { RegisterObject(SOBFireball); setAngularFactor(0.0); this->enableCollisionCallback(); gravityAcceleration_ = 350.0; speed_ = 0; hasCollided_=false; changeAllowed_ = true; changedOn_ = 0.0; goesRight_ = true; hitCounter_ = 0; particlespawner_ = NULL ; } void SOBFireball::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(SOBFireball, XMLPort, xmlelement, mode); XMLPortParam(SOBFireball, "speed", setSpeed, getSpeed, xmlelement, mode); } void SOBFireball::setDirection(const bool direction) { if(direction) { goesRight_=true; } else { goesRight_=false; } } bool SOBFireball::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { float collDisX_ = getPosition().x - contactPoint.getPositionWorldOnB().getX(); float collDisZ_ = getPosition().z - contactPoint.getPositionWorldOnB().getZ(); SOBGumba* gumba = orxonox_cast (otherObject); SOBGumbaBoss* gumbaBoss = orxonox_cast (otherObject); if(gumbaBoss != nullptr && !(gumba->hasCollided_)) //Fireballs can't destroy GumbaBosses, they get destroyed themselves instead { this->destroyLater(); this->hasCollided_ = true; } if(gumba!=nullptr && gumbaBoss == nullptr && !(gumba->hasCollided_)) //if other object is a Gumba, kill the Gumba and add score and destroy the fireball { gumba->destroyLater(); gumba->hasCollided_ = true; SOB* SOBGame = orxonox_cast(getGametype()); SOBGame->addGumba(); this->destroyLater(); this->hasCollided_ = true; } //collision with either top or bottom of a block else if(changeAllowed_ && (abs(collDisX_)<=abs(collDisZ_))) { changeAllowed_ = false; Vector3 velocity = getVelocity(); velocity.z = -velocity.z; setVelocity(velocity); } //collision with the vertical side of a block else if(changeAllowed_ && (abs(collDisX_)>abs(collDisZ_))) { changeAllowed_ = false; goesRight_=!goesRight_; } hitCounter_++; return true; } void SOBFireball::tick(float dt) { SUPER(SOBFireball, tick, dt); //the particle spawner that generates the fire from the backpack when pressed if (particlespawner_ == NULL) { for (WorldEntity* object : this->getAttachedObjects()) { if (object->isA(Class(ParticleSpawner))) particlespawner_ = object; } } if(particlespawner_ != NULL) particlespawner_->setVisible(true); if (!changeAllowed_) { changedOn_+= dt; // After a collision, we don't listen for collisions for 200ms - that's because one wall can cause several collisions! if (changedOn_> 0.2) { changeAllowed_ = true; changedOn_ = 0.0; } } int dir = 1; if (!goesRight_) dir = -1; Vector3 velocity = getVelocity(); velocity.z -= gravityAcceleration_*dt; velocity.x = dir*speed_; velocity.y = 0; if(hitCounter_ >= 3) velocity.y = 0.1f*speed_; setVelocity(velocity); if(abs(this->getPosition().z) > 1000) this->destroyLater(); } }