/* * 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: * Florian Zinggeler * Co-authors: * ... * */ /** @file FlappyOrxAsteroid.h @brief Declaration of the FlappyOrxAsteroid class. */ #include "FlappyOrxAsteroid.h" #include "core/CoreIncludes.h" #include "FlappyOrx.h" #include "FlappyOrxShip.h" namespace orxonox { RegisterClass(FlappyOrxAsteroid); FlappyOrxAsteroid::FlappyOrxAsteroid(Context* context) : Pawn(context) { RegisterObject(FlappyOrxAsteroid); enableCollisionCallback(); lifetime = 0; } void FlappyOrxAsteroid::tick(float dt) { lifetime += dt; // die after 5 seconds. if (lifetime > 5000) removeHealth(2000); if (player != nullptr) { float newZ = 2/(pow(std::abs(getPosition().x - player->getPosition().x) * 0.01f, 2) + 1) * (player->getPosition().z - getPosition().z); setVelocity(Vector3(1000.f - level * 100 , 0, newZ)); } SUPER(FlappyOrxAsteroid, tick, dt); } inline bool FlappyOrxAsteroid::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) { if(orxonox_cast(otherObject)) removeHealth(2000); return false; } FlappyOrx* FlappyOrxAsteroid::getGame() { if (game == nullptr) { for (FlappyOrx* flappyOrx : ObjectList()) game = flappyOrx; } return game; } void FlappyOrxAsteroid::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) { Pawn::damage(damage, healthdamage, shielddamage, originator, cs); if (getGame() && orxonox_cast(originator) != nullptr && getHealth() <= 0) getGame()->addPoints(42); } }