Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/effects/explosion.cc @ 10753

Last change on this file since 10753 was 10695, checked in by snellen, 17 years ago

changes on soundengine and mover by fabian landau

File size: 4.5 KB
Line 
1/*
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
13   co-programmer: Benjamin Grauer
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "explosion.h"
19
20#include "loading/fast_factory.h"
21
22#include "state.h"
23
24#include "particles/box_emitter.h"
25#include "particles/sprite_particles.h"
26
27#include "sound/resource_sound_buffer.h"
28#include "sound_engine.h"
29
30
31ObjectListDefinition(Explosion);
32CREATE_FAST_FACTORY_STATIC(Explosion);
33
34#include "script_class.h"
35CREATE_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))
44                            ->addMethod("setExplosionSound", Executor1<Explosion, lua_State*, const std::string&>(&Explosion::setExplosionSound))
45                       );
46
47/**
48 *  standard constructor
49*/
50Explosion::Explosion ()
51{
52  this->registerObject(this, Explosion::_objectList);
53  this->toList(OM_DEAD_TICK);
54
55  this->emitter = new BoxEmitter(Vector(10,10,10), 200, 45, M_2_PI);
56  this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
57  this->emitter->setParent(this);
58  this->emitter->setSpread(M_PI, M_PI);
59
60  this->lifeCycle = 0.0f;
61  this->lifeTime = .5f;
62 
63  this->explosionSound.setSourceNode(this);
64 
65}
66
67
68/**
69 *  standard deconstructor
70*/
71Explosion::~Explosion ()
72{
73  delete this->emitter;
74  if (this->explosionSound.isPlaying())
75    this->explosionSound.stop();
76  /* this is normaly done by World.cc by deleting the ParticleEngine */
77  if (Explosion::explosionParticles != NULL && Explosion::objectList().size() <= 1)
78     Explosion::explosionParticles = NULL;
79}
80
81SpriteParticles* Explosion::explosionParticles = NULL;
82
83void Explosion::explode(PNode* position, const Vector& size)
84{
85  Explosion* explosion = dynamic_cast<Explosion*>(Explosion::fastFactory->resurrect());
86  explosion->setAbsCoor(position->getAbsCoor());
87  explosion->emitter->setSize(size);
88  explosion->activate();
89}
90
91
92void Explosion::explode(float x, float y, float z)
93{
94  Explosion* explosion = dynamic_cast<Explosion*>(Explosion::fastFactory->resurrect());
95  explosion->setAbsCoor(this->getAbsCoor());
96  explosion->emitter->setSize(Vector(x,y,z));
97  explosion->activate();
98 
99 
100}
101
102
103void Explosion::activate()
104{
105  if (unlikely(Explosion::explosionParticles == NULL))
106  {
107    Explosion::explosionParticles = new SpriteParticles(5000);
108    Explosion::explosionParticles->setName("ExplosionExplosionParticles");
109    Explosion::explosionParticles->setMaterialTexture("textures/radial-trans-noise.png");
110    Explosion::explosionParticles->setLifeSpan(1.5, .3);
111    Explosion::explosionParticles->setRadius(0.0, 10);
112    Explosion::explosionParticles->setRadius(.5, 30.0);
113    Explosion::explosionParticles->setRadius(1.0, 10.0);
114    Explosion::explosionParticles->setColor(0.0, 1,0,0,1);
115    Explosion::explosionParticles->setColor(0.5, .8,.8,0,.5);
116    Explosion::explosionParticles->setColor(0.8, .8,.8,.3,.3);
117    Explosion::explosionParticles->setColor(1.0, 1,1,1,.0);
118  }
119
120  this->emitter->setSystem(Explosion::explosionParticles);
121  this->emitter->updateNode(.01);
122  this->emitter->updateNode(.01);
123  this->toList(OM_DEAD_TICK);
124  this->lifeCycle = 0.0;
125 
126  this->explosionSound.play(this->explosionSoundBuffer, OrxSound::SoundEngine::getInstance()->getEffectsVolume(), 0.01, true);
127}
128
129
130void Explosion::deactivate()
131{
132  this->emitter->setSystem(NULL);
133  this->toList(OM_DEAD);
134  Explosion::fastFactory->kill(this);
135}
136
137
138/**
139 *  signal tick, time dependent things will be handled here
140 * @param time since last tick
141*/
142void Explosion::tick (float dt)
143{
144  this->lifeCycle += dt;
145  if(this->lifeTime < this->lifeCycle)
146    this->deactivate();
147}
Note: See TracBrowser for help on using the repository browser.