/* * 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: * Fabian 'x3n' Landau * Co-authors: * ... * */ /** @file ParticleProjectile.h @brief Implementation of the ParticleProjectile class. */ #include "BallProjectile.h" #include #include "core/CoreIncludes.h" #include "tools/ParticleInterface.h" #include "Scene.h" #include "core/command/Executor.h" #include "util/Convert.h" namespace orxonox { RegisterClass(BallProjectile); BallProjectile::BallProjectile(Context* context) : BillboardProjectile(context) { RegisterObject(BallProjectile); this->textureIndex_ = 1; this->setMass(0.1f); this->maxTextureIndex_ = 8; this->setDestroyAfterCollision(false); //I want the ball to bounce, not to be destroyed //setEffect("Orxonox/sparks2"); } void BallProjectile::registerVariables() { registerVariable(this->materialBase_); } /** @brief Set the material. @param material The name of the material. Material names with 1 to 8 appended must exist. */ void BallProjectile::setMaterial(const std::string& material) { this->materialBase_ = material; BillboardProjectile::setMaterial(material + multi_cast(this->textureIndex_)); } /** @brief Change the texture. */ void BallProjectile::changeTexture() { this->textureIndex_++; if (this->textureIndex_ > this->maxTextureIndex_) this->textureIndex_ = 1; this->setMaterial(this->materialBase_); } void BallProjectile::Bounce(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs) { Vector3 velocity = this->getVelocity(); Vector3 positionOtherObject = otherObject->getPosition(); Vector3 contactPosition = this->getPosition(); orxout() << "About to Bounce >D" << endl; //if (positionOtherObject.y < 0) { //this.destroy() //}S //else { int distance_X = positionOtherObject.x - contactPosition.x; int distance_Y = positionOtherObject.y - contactPosition.y; if (distance_X < 0) distance_Y = -distance_Y; if (distance_Y < 0) distance_X = -distance_X; if (distance_X < distance_Y) velocity.y = -velocity.y; if (distance_Y < distance_X) velocity.x = -velocity.x; else { velocity.x = -velocity.x; velocity.y = -velocity.y; } //} } /** @brief The function called when a projectile hits another thing. Calls the hit-function, starts the shield recharge countdown, displays visual hit effects defined in Pawn. Needs to be called in the collidesAgainst() function by every Class directly inheriting from BasicProjectile. @param otherObject A pointer to the object the Projectile has collided against. @param contactPoint A btManifoldPoint indicating the point of contact/impact. @param cs The btCollisionShape of the other object @return Returns true if the collision resulted in a successful hit. @see Pawn.h */ bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs) { orxout() << "wanna bounce..." << endl; bool result = BasicProjectile::processCollision(otherObject, contactPoint, cs); Bounce(otherObject, contactPoint, cs); orxout() << "BOUNCED!" << endl; return result; } }