/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 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: Patrick Boenzli co-programmer: Benjamin Grauer */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON #include "explosion.h" #include "fast_factory.h" #include "state.h" #include "class_list.h" #include "box_emitter.h" #include "sprite_particles.h" using namespace std; CREATE_FAST_FACTORY_STATIC(Explosion, CL_EXPLOSION); /** * standard constructor */ Explosion::Explosion () { this->setClassID(CL_EXPLOSION, "Explosion"); this->toList(OM_DEAD_TICK); this->emitter = new BoxEmitter(Vector(10,10,10), 1000, 30, M_2_PI); this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); this->emitter->setParent(this); this->emitter->setSpread(M_PI, M_PI); this->lifeCycle = 0.0f; this->lifeTime = 1.0f; } /** * standard deconstructor */ Explosion::~Explosion () { delete this->emitter; /* this is normaly done by World.cc by deleting the ParticleEngine */ if (Explosion::explosionParticles != NULL && ClassList::getList(CL_EXPLOSION)->size() <= 1) Explosion::explosionParticles = NULL; } SpriteParticles* Explosion::explosionParticles = NULL; void Explosion::explode(PNode* position, const Vector& size) { Explosion* explosion = dynamic_cast(Explosion::fastFactory->resurrect()); explosion->setParent(position); explosion->emitter->setSize(size); explosion->activate(); } void Explosion::activate() { if (unlikely(Explosion::explosionParticles == NULL)) { Explosion::explosionParticles = new SpriteParticles(5000); Explosion::explosionParticles->setName("ExplosionExplosionParticles"); Explosion::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); Explosion::explosionParticles->setLifeSpan(.5, .3); Explosion::explosionParticles->setRadius(0.0, 10); Explosion::explosionParticles->setRadius(.5, 15.0); Explosion::explosionParticles->setRadius(1.0, 10.0); Explosion::explosionParticles->setColor(0.0, 0,1,0,1); Explosion::explosionParticles->setColor(0.5, .8,.8,0,.8); Explosion::explosionParticles->setColor(0.8, .8,.8,.3,.8); Explosion::explosionParticles->setColor(1.0, 1,1,1,.0); } this->emitter->setSystem(Explosion::explosionParticles); this->toList(OM_DEAD_TICK); this->lifeCycle = 0.0; } void Explosion::deactivate() { this->emitter->setSystem(NULL); this->toList(OM_DEAD); this->emitter->setParent(PNode::getNullParent()); Explosion::fastFactory->kill(this); } /** * signal tick, time dependent things will be handled here * @param time since last tick */ void Explosion::tick (float dt) { this->lifeCycle += dt; if(this->lifeTime < this->lifeCycle) this->deactivate(); }