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 "fast_factory.h" |
---|
21 | |
---|
22 | #include "state.h" |
---|
23 | #include "class_list.h" |
---|
24 | |
---|
25 | #include "dot_emitter.h" |
---|
26 | #include "sprite_particles.h" |
---|
27 | |
---|
28 | |
---|
29 | using namespace std; |
---|
30 | |
---|
31 | CREATE_FAST_FACTORY_STATIC(Explosion, CL_EXPLOSION); |
---|
32 | |
---|
33 | /** |
---|
34 | * standard constructor |
---|
35 | */ |
---|
36 | Explosion::Explosion () |
---|
37 | { |
---|
38 | this->setClassID(CL_EXPLOSION, "Explosion"); |
---|
39 | |
---|
40 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
41 | this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); |
---|
42 | this->emitter->setParent(this); |
---|
43 | this->emitter->setSpread(M_PI, M_PI); |
---|
44 | |
---|
45 | this->lifeCycle = 0.0f; |
---|
46 | this->lifeTime = 4.0f; |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | |
---|
51 | /** |
---|
52 | * standard deconstructor |
---|
53 | */ |
---|
54 | Explosion::~Explosion () |
---|
55 | { |
---|
56 | delete this->emitter; |
---|
57 | |
---|
58 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
59 | if (Explosion::explosionParticles != NULL && ClassList::getList(CL_EXPLOSION)->size() <= 1) |
---|
60 | Explosion::explosionParticles = NULL; |
---|
61 | } |
---|
62 | |
---|
63 | SpriteParticles* Explosion::explosionParticles = NULL; |
---|
64 | |
---|
65 | void Explosion::activate() |
---|
66 | { |
---|
67 | if (unlikely(Explosion::explosionParticles == NULL)) |
---|
68 | { |
---|
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); |
---|
80 | } |
---|
81 | |
---|
82 | this->emitter->setSystem(Explosion::explosionParticles); |
---|
83 | |
---|
84 | this->updateNode(0); |
---|
85 | this->emitter->setEmissionRate(45.0); |
---|
86 | this->emitter->setEmissionVelocity(0.0); |
---|
87 | this->toList(OM_DEAD_TICK); |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | void Explosion::deactivate() |
---|
92 | { |
---|
93 | this->emitter->setSystem(NULL); |
---|
94 | this->lifeCycle = 0.0; |
---|
95 | this->toList(OM_DEAD); |
---|
96 | |
---|
97 | Explosion::fastFactory->kill(this); |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | /** |
---|
102 | * signal tick, time dependent things will be handled here |
---|
103 | * @param time since last tick |
---|
104 | */ |
---|
105 | void Explosion::tick (float dt) |
---|
106 | { |
---|
107 | this->lifeCycle += dt; |
---|
108 | if(this->lifeTime < this->lifeCycle) |
---|
109 | this->deactivate(); |
---|
110 | } |
---|