[4593] | 1 | /* |
---|
[3708] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
[5443] | 13 | co-programmer: Benjamin Grauer |
---|
| 14 | |
---|
[3708] | 15 | */ |
---|
[5357] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3708] | 17 | |
---|
[7047] | 18 | #include "explosion.h" |
---|
[3708] | 19 | |
---|
[4947] | 20 | #include "fast_factory.h" |
---|
[3708] | 21 | |
---|
[5443] | 22 | #include "state.h" |
---|
[5444] | 23 | #include "class_list.h" |
---|
[5054] | 24 | |
---|
[6822] | 25 | #include "dot_emitter.h" |
---|
[6621] | 26 | #include "sprite_particles.h" |
---|
[5443] | 27 | |
---|
| 28 | |
---|
[3708] | 29 | using namespace std; |
---|
| 30 | |
---|
[7047] | 31 | CREATE_FAST_FACTORY_STATIC(Explosion, CL_EXPLOSION); |
---|
[3708] | 32 | |
---|
| 33 | /** |
---|
[4836] | 34 | * standard constructor |
---|
[3708] | 35 | */ |
---|
[7047] | 36 | Explosion::Explosion () |
---|
[3755] | 37 | { |
---|
[7047] | 38 | this->setClassID(CL_EXPLOSION, "Explosion"); |
---|
[4597] | 39 | |
---|
[6825] | 40 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
[7047] | 41 | this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[5443] | 42 | this->emitter->setParent(this); |
---|
[5449] | 43 | this->emitter->setSpread(M_PI, M_PI); |
---|
[7047] | 44 | |
---|
| 45 | this->lifeCycle = 0.0f; |
---|
| 46 | this->lifeTime = 4.0f; |
---|
| 47 | |
---|
[3755] | 48 | } |
---|
[3708] | 49 | |
---|
| 50 | |
---|
| 51 | /** |
---|
[4836] | 52 | * standard deconstructor |
---|
[3708] | 53 | */ |
---|
[7047] | 54 | Explosion::~Explosion () |
---|
[3708] | 55 | { |
---|
[7047] | 56 | delete this->emitter; |
---|
[5444] | 57 | |
---|
[5445] | 58 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[7047] | 59 | if (Explosion::explosionParticles != NULL && ClassList::getList(CL_EXPLOSION)->size() <= 1) |
---|
| 60 | Explosion::explosionParticles = NULL; |
---|
[3708] | 61 | } |
---|
| 62 | |
---|
[7047] | 63 | SpriteParticles* Explosion::explosionParticles = NULL; |
---|
[5443] | 64 | |
---|
[7047] | 65 | void Explosion::activate() |
---|
[5443] | 66 | { |
---|
[7047] | 67 | if (unlikely(Explosion::explosionParticles == NULL)) |
---|
[5447] | 68 | { |
---|
[7047] | 69 | Explosion::explosionParticles = new SpriteParticles(200); |
---|
| 70 | Explosion::explosionParticles->setName("ExplosionExplosionParticles"); |
---|
| 71 | Explosion::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 72 | Explosion::explosionParticles->setLifeSpan(.5, .3); |
---|
| 73 | Explosion::explosionParticles->setRadius(0.0, 10); |
---|
| 74 | Explosion::explosionParticles->setRadius(.5, 15.0); |
---|
| 75 | Explosion::explosionParticles->setRadius(1.0, 10.0); |
---|
| 76 | Explosion::explosionParticles->setColor(0.0, 0,1,0,1); |
---|
| 77 | Explosion::explosionParticles->setColor(0.5, .8,.8,0,.8); |
---|
| 78 | Explosion::explosionParticles->setColor(0.8, .8,.8,.3,.8); |
---|
| 79 | Explosion::explosionParticles->setColor(1.0, 1,1,1,.0); |
---|
[5447] | 80 | } |
---|
[5443] | 81 | |
---|
[7047] | 82 | this->emitter->setSystem(Explosion::explosionParticles); |
---|
[5447] | 83 | |
---|
[5769] | 84 | this->updateNode(0); |
---|
[5472] | 85 | this->emitter->setEmissionRate(45.0); |
---|
[5471] | 86 | this->emitter->setEmissionVelocity(0.0); |
---|
[7047] | 87 | this->toList(OM_DEAD_TICK); |
---|
[5443] | 88 | } |
---|
| 89 | |
---|
| 90 | |
---|
[7047] | 91 | void Explosion::deactivate() |
---|
[5443] | 92 | { |
---|
[6619] | 93 | this->emitter->setSystem(NULL); |
---|
[5447] | 94 | this->lifeCycle = 0.0; |
---|
[7047] | 95 | this->toList(OM_DEAD); |
---|
[5443] | 96 | |
---|
[7047] | 97 | Explosion::fastFactory->kill(this); |
---|
[5443] | 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
[3708] | 101 | /** |
---|
[4836] | 102 | * signal tick, time dependent things will be handled here |
---|
| 103 | * @param time since last tick |
---|
[3708] | 104 | */ |
---|
[7047] | 105 | void Explosion::tick (float dt) |
---|
[3708] | 106 | { |
---|
[7047] | 107 | this->lifeCycle += dt; |
---|
| 108 | if(this->lifeTime < this->lifeCycle) |
---|
[6056] | 109 | this->deactivate(); |
---|
[3708] | 110 | } |
---|