[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 | |
---|
[9869] | 20 | #include "loading/fast_factory.h" |
---|
[3708] | 21 | |
---|
[5443] | 22 | #include "state.h" |
---|
[5054] | 23 | |
---|
[9869] | 24 | #include "particles/box_emitter.h" |
---|
| 25 | #include "particles/sprite_particles.h" |
---|
[5443] | 26 | |
---|
[10695] | 27 | #include "sound/resource_sound_buffer.h" |
---|
| 28 | #include "sound_engine.h" |
---|
| 29 | |
---|
| 30 | |
---|
[10114] | 31 | ObjectListDefinition(Explosion); |
---|
[9869] | 32 | CREATE_FAST_FACTORY_STATIC(Explosion); |
---|
[9406] | 33 | |
---|
[10665] | 34 | #include "script_class.h" |
---|
| 35 | CREATE_SCRIPTABLE_CLASS(Explosion, |
---|
| 36 | // Coordinates |
---|
| 37 | addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX)) |
---|
| 38 | ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY)) |
---|
| 39 | ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ)) |
---|
| 40 | ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor)) |
---|
| 41 | ->addMethod("setAbsDir", Executor4<PNode, lua_State*,float,float,float,float>(&PNode::setAbsDir)) |
---|
| 42 | //Explode ! |
---|
| 43 | ->addMethod("explode", Executor3<Explosion, lua_State*, float, float, float>(&Explosion::explode)) |
---|
[10695] | 44 | ->addMethod("setExplosionSound", Executor1<Explosion, lua_State*, const std::string&>(&Explosion::setExplosionSound)) |
---|
[10724] | 45 | ->addMethod("playSound", Executor0<Explosion, lua_State*>(&Explosion::playSound)) |
---|
[10665] | 46 | ); |
---|
| 47 | |
---|
[3708] | 48 | /** |
---|
[4836] | 49 | * standard constructor |
---|
[3708] | 50 | */ |
---|
[7047] | 51 | Explosion::Explosion () |
---|
[3755] | 52 | { |
---|
[9869] | 53 | this->registerObject(this, Explosion::_objectList); |
---|
[7104] | 54 | this->toList(OM_DEAD_TICK); |
---|
[4597] | 55 | |
---|
[9235] | 56 | this->emitter = new BoxEmitter(Vector(10,10,10), 200, 45, M_2_PI); |
---|
[7047] | 57 | this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
[5443] | 58 | this->emitter->setParent(this); |
---|
[5449] | 59 | this->emitter->setSpread(M_PI, M_PI); |
---|
[7047] | 60 | |
---|
| 61 | this->lifeCycle = 0.0f; |
---|
[7105] | 62 | this->lifeTime = .5f; |
---|
[10695] | 63 | |
---|
| 64 | this->explosionSound.setSourceNode(this); |
---|
| 65 | |
---|
[3755] | 66 | } |
---|
[3708] | 67 | |
---|
| 68 | |
---|
| 69 | /** |
---|
[4836] | 70 | * standard deconstructor |
---|
[3708] | 71 | */ |
---|
[7047] | 72 | Explosion::~Explosion () |
---|
[3708] | 73 | { |
---|
[7047] | 74 | delete this->emitter; |
---|
[10695] | 75 | if (this->explosionSound.isPlaying()) |
---|
| 76 | this->explosionSound.stop(); |
---|
[5445] | 77 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[9869] | 78 | if (Explosion::explosionParticles != NULL && Explosion::objectList().size() <= 1) |
---|
[7047] | 79 | Explosion::explosionParticles = NULL; |
---|
[3708] | 80 | } |
---|
| 81 | |
---|
[7047] | 82 | SpriteParticles* Explosion::explosionParticles = NULL; |
---|
[5443] | 83 | |
---|
[7103] | 84 | void Explosion::explode(PNode* position, const Vector& size) |
---|
| 85 | { |
---|
| 86 | Explosion* explosion = dynamic_cast<Explosion*>(Explosion::fastFactory->resurrect()); |
---|
[7105] | 87 | explosion->setAbsCoor(position->getAbsCoor()); |
---|
[7103] | 88 | explosion->emitter->setSize(size); |
---|
| 89 | explosion->activate(); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | |
---|
[10665] | 93 | void Explosion::explode(float x, float y, float z) |
---|
| 94 | { |
---|
| 95 | Explosion* explosion = dynamic_cast<Explosion*>(Explosion::fastFactory->resurrect()); |
---|
| 96 | explosion->setAbsCoor(this->getAbsCoor()); |
---|
| 97 | explosion->emitter->setSize(Vector(x,y,z)); |
---|
| 98 | explosion->activate(); |
---|
[10695] | 99 | |
---|
| 100 | |
---|
[10665] | 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
[7047] | 104 | void Explosion::activate() |
---|
[5443] | 105 | { |
---|
[7047] | 106 | if (unlikely(Explosion::explosionParticles == NULL)) |
---|
[5447] | 107 | { |
---|
[7103] | 108 | Explosion::explosionParticles = new SpriteParticles(5000); |
---|
[7047] | 109 | Explosion::explosionParticles->setName("ExplosionExplosionParticles"); |
---|
[10317] | 110 | Explosion::explosionParticles->setMaterialTexture("textures/radial-trans-noise.png"); |
---|
[10762] | 111 | Explosion::explosionParticles->setLifeSpan(1.5, 0.3); |
---|
| 112 | Explosion::explosionParticles->setRadius(0.0, 30.0); |
---|
| 113 | Explosion::explosionParticles->setRadius(0.5, 50.0); |
---|
| 114 | Explosion::explosionParticles->setRadius(1.0, 30.0); |
---|
| 115 | Explosion::explosionParticles->setColor(0.0, 1.0, 0.5, 0.0, 1.0); |
---|
| 116 | Explosion::explosionParticles->setColor(0.4, 0.8, 0.3, 0.0, 1.0); |
---|
| 117 | Explosion::explosionParticles->setColor(0.8, 0.6, 0.0, 0.0, 0.7); |
---|
| 118 | Explosion::explosionParticles->setColor(1.0, 0.0, 0.0, 0.0, 0.0); |
---|
[5447] | 119 | } |
---|
[5443] | 120 | |
---|
[7047] | 121 | this->emitter->setSystem(Explosion::explosionParticles); |
---|
[7105] | 122 | this->emitter->updateNode(.01); |
---|
[7120] | 123 | this->emitter->updateNode(.01); |
---|
[7047] | 124 | this->toList(OM_DEAD_TICK); |
---|
[7103] | 125 | this->lifeCycle = 0.0; |
---|
[10724] | 126 | this->explosionSound.play(this->explosionSoundBuffer, OrxSound::SoundEngine::getInstance()->getEffectsVolume(), 0.01, false); |
---|
| 127 | |
---|
[5443] | 128 | } |
---|
| 129 | |
---|
| 130 | |
---|
[7047] | 131 | void Explosion::deactivate() |
---|
[5443] | 132 | { |
---|
[6619] | 133 | this->emitter->setSystem(NULL); |
---|
[7047] | 134 | this->toList(OM_DEAD); |
---|
| 135 | Explosion::fastFactory->kill(this); |
---|
[5443] | 136 | } |
---|
| 137 | |
---|
[10724] | 138 | void Explosion::playSound() |
---|
| 139 | { |
---|
| 140 | if (!this->explosionSound.isPlaying()) |
---|
| 141 | this->explosionSound.play(this->explosionSoundBuffer, OrxSound::SoundEngine::getInstance()->getEffectsVolume(), 0.01, false); |
---|
| 142 | } |
---|
[5443] | 143 | |
---|
[3708] | 144 | /** |
---|
[4836] | 145 | * signal tick, time dependent things will be handled here |
---|
| 146 | * @param time since last tick |
---|
[3708] | 147 | */ |
---|
[7047] | 148 | void Explosion::tick (float dt) |
---|
[3708] | 149 | { |
---|
[7047] | 150 | this->lifeCycle += dt; |
---|
| 151 | if(this->lifeTime < this->lifeCycle) |
---|
[6056] | 152 | this->deactivate(); |
---|
[3708] | 153 | } |
---|