Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10673 was 10665, checked in by snellen, 18 years ago

explosion is now scriptable

File size: 4.1 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
27ObjectListDefinition(Explosion);
28CREATE_FAST_FACTORY_STATIC(Explosion);
29
30#include "script_class.h"
31CREATE_SCRIPTABLE_CLASS(Explosion,
32                        // Coordinates
33                            addMethod("getAbsCoorX", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorX))
34                            ->addMethod("getAbsCoorY", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorY))
35                            ->addMethod("getAbsCoorZ", Executor0ret<PNode, lua_State*, float>(&PNode::getAbsCoorZ))
36                            ->addMethod("setAbsCoor", Executor3<PNode, lua_State*,float,float,float>(&PNode::setAbsCoor))
37                            ->addMethod("setAbsDir", Executor4<PNode, lua_State*,float,float,float,float>(&PNode::setAbsDir))
38                        //Explode !
39                            ->addMethod("explode", Executor3<Explosion, lua_State*, float, float, float>(&Explosion::explode))
40                       );
41
42/**
43 *  standard constructor
44*/
45Explosion::Explosion ()
46{
47  this->registerObject(this, Explosion::_objectList);
48  this->toList(OM_DEAD_TICK);
49
50  this->emitter = new BoxEmitter(Vector(10,10,10), 200, 45, M_2_PI);
51  this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
52  this->emitter->setParent(this);
53  this->emitter->setSpread(M_PI, M_PI);
54
55  this->lifeCycle = 0.0f;
56  this->lifeTime = .5f;
57
58}
59
60
61/**
62 *  standard deconstructor
63*/
64Explosion::~Explosion ()
65{
66  delete this->emitter;
67
68  /* this is normaly done by World.cc by deleting the ParticleEngine */
69  if (Explosion::explosionParticles != NULL && Explosion::objectList().size() <= 1)
70     Explosion::explosionParticles = NULL;
71}
72
73SpriteParticles* Explosion::explosionParticles = NULL;
74
75void Explosion::explode(PNode* position, const Vector& size)
76{
77  Explosion* explosion = dynamic_cast<Explosion*>(Explosion::fastFactory->resurrect());
78  explosion->setAbsCoor(position->getAbsCoor());
79  explosion->emitter->setSize(size);
80  explosion->activate();
81}
82
83
84void Explosion::explode(float x, float y, float z)
85{
86  Explosion* explosion = dynamic_cast<Explosion*>(Explosion::fastFactory->resurrect());
87  explosion->setAbsCoor(this->getAbsCoor());
88  explosion->emitter->setSize(Vector(x,y,z));
89  explosion->activate();
90}
91
92
93void Explosion::activate()
94{
95  if (unlikely(Explosion::explosionParticles == NULL))
96  {
97    Explosion::explosionParticles = new SpriteParticles(5000);
98    Explosion::explosionParticles->setName("ExplosionExplosionParticles");
99    Explosion::explosionParticles->setMaterialTexture("textures/radial-trans-noise.png");
100    Explosion::explosionParticles->setLifeSpan(1.5, .3);
101    Explosion::explosionParticles->setRadius(0.0, 10);
102    Explosion::explosionParticles->setRadius(.5, 30.0);
103    Explosion::explosionParticles->setRadius(1.0, 10.0);
104    Explosion::explosionParticles->setColor(0.0, 1,0,0,1);
105    Explosion::explosionParticles->setColor(0.5, .8,.8,0,.5);
106    Explosion::explosionParticles->setColor(0.8, .8,.8,.3,.3);
107    Explosion::explosionParticles->setColor(1.0, 1,1,1,.0);
108  }
109
110  this->emitter->setSystem(Explosion::explosionParticles);
111  this->emitter->updateNode(.01);
112  this->emitter->updateNode(.01);
113  this->toList(OM_DEAD_TICK);
114  this->lifeCycle = 0.0;
115}
116
117
118void Explosion::deactivate()
119{
120  this->emitter->setSystem(NULL);
121  this->toList(OM_DEAD);
122  Explosion::fastFactory->kill(this);
123}
124
125
126/**
127 *  signal tick, time dependent things will be handled here
128 * @param time since last tick
129*/
130void Explosion::tick (float dt)
131{
132  this->lifeCycle += dt;
133  if(this->lifeTime < this->lifeCycle)
134    this->deactivate();
135}
Note: See TracBrowser for help on using the repository browser.