/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004-2006 orx 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, or (at your option) any later version. ### File Specific main-programmer: Nicolas Schlumberger, Marc Schaerrer co-programmer: Benjamin Grauer */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON #include "spike_ball.h" #include "state.h" #include "model.h" #include "particles/dot_emitter.h" #include "particles/sprite_particles.h" #include #include "debug.h" #include "space_ships/space_ship.h" #include "weapons/weapon.h" #include "class_id_DEPRECATED.h" ObjectListDefinition(SpikeBall); CREATE_FAST_FACTORY_STATIC(SpikeBall); /** * standard constructor */ SpikeBall::SpikeBall () : Projectile() { this->registerObject(this, SpikeBall::_objectList); this->loadModel("models/projectiles/spike_ball.obj", .25); this->setMinEnergy(1); this->setHealthMax(0); this->lifeSpan = 1.0; this->emitter = new DotEmitter(100, 5, M_2_PI); this->emitter->setParent(this); this->emitter->setSpread(M_PI, M_PI); this->emitter->setEmissionRate(300.0); this->emitter->setEmissionVelocity(50.0); this->speed = 150; this->angle = 0; this->rotationSpeed = 0; /* this->halo = new Billboard(); this->halo->setSize(.35, .35); this->halo->setTexture("hbolt_halo.png");*/ } /** * standard deconstructor */ SpikeBall::~SpikeBall () { // delete this->emitter; /* this is normaly done by World.cc by deleting the ParticleEngine */ if (SpikeBall::explosionParticles != NULL && SpikeBall::objectList().size() <= 1) { //if (ClassList::exists(SpikeBall::explosionParticles, CL_PARTICLE_SYSTEM)) // delete SpikeBall::explosionParticles; PRINTF(1)("Deleting SpikeBall Particles\n"); SpikeBall::explosionParticles = NULL; } } SpriteParticles* SpikeBall::explosionParticles = NULL; void SpikeBall::activate() { if (unlikely(SpikeBall::explosionParticles == NULL)) { SpikeBall::explosionParticles = new SpriteParticles(1000); SpikeBall::explosionParticles->setName("BoltExplosionParticles"); SpikeBall::explosionParticles->setLifeSpan(.5, .3); SpikeBall::explosionParticles->setRadius(0.0, 10.0); SpikeBall::explosionParticles->setRadius(.5, 6.0); SpikeBall::explosionParticles->setRadius(1.0, 3.0); SpikeBall::explosionParticles->setColor(0.0, 1,1,0,.9); SpikeBall::explosionParticles->setColor(0.5, .8,.8,0,.5); SpikeBall::explosionParticles->setColor(1.0, .8,.8,.7,.0); } this->setDamage(5); this->setHealth(0); } void SpikeBall::deactivate() { assert (SpikeBall::explosionParticles != NULL); SpikeBall::explosionParticles->removeEmitter(this->emitter); this->lifeCycle = 0.0; this->toList(OM_NULL); this->removeNode(); SpikeBall::fastFactory->kill(this); } void SpikeBall::collidesWith(WorldEntity* entity, const Vector& location) { PRINTF(0)("Collision with SpikeBall\n"); if (this->hitEntity != entity && entity->isA(CL_NPC)) this->destroy( entity ); this->hitEntity = entity; dynamic_cast(entity)->damage(this->getDamage(),0); // this->deactivate(); } /* void SpikeBall::blow() { const float* v = this->getModel()->getVertexArray(); Projectile* pj = NULL; for (unsigned int i = 0; i < this->getModel()->getVertexCount(); i++) { // v = this->getModel()->getModelInfo pj = this->getProjectile(); if (pj == NULL) return; if (v[i].x * v[i].x + v[i].y * v[i].y + v[i].z * v[i].z > 4) { pj->setParent(PNode::getNullParent()); pj->setAbsCoor(this->getAbsCoor() + v); pj->setAbsDir(v->getNormalized() * this->speed); pj->activate(); } } }*/ /** * signal tick, time dependent things will be handled here * @param dt time since last tick */ void SpikeBall::tick (float dt) { //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); Vector v = this->velocity * dt; this->shiftCoor(v); if (this->tickLifeCycle(dt)){ // this->blow(); this->deactivate(); } angle += rotationSpeed * dt; } /** * the function gets called, when the projectile is destroyed */ void SpikeBall::destroy (WorldEntity* killer) { Projectile::destroy( killer ); PRINTF(5)("DESTROY SpikeBall\n"); this->lifeCycle = .95; //!< @todo calculate this usefully. this->emitter->setSystem(SpikeBall::explosionParticles); } void SpikeBall::draw () const { glPushAttrib(GL_ENABLE_BIT); //glDisable(GL_LIGHTING); glMatrixMode(GL_MODELVIEW); glPushMatrix(); float matrix[4][4]; glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); glRotatef(angle, 1.0, 0.0, 0.0); this->getAbsDir().matrix (matrix); glMultMatrixf((float*)matrix); this->getModel()->draw(); this->halo->draw(); glPopMatrix(); glPopAttrib(); }