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: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | |
---|
15 | */ |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
17 | |
---|
18 | #include "hyperblast.h" |
---|
19 | |
---|
20 | #include "state.h" |
---|
21 | #include "class_list.h" |
---|
22 | |
---|
23 | #include "box_emitter.h" |
---|
24 | #include "spark_particles.h" |
---|
25 | |
---|
26 | |
---|
27 | using namespace std; |
---|
28 | |
---|
29 | CREATE_FAST_FACTORY_STATIC(Hyperblast, CL_HYPERBLAST); |
---|
30 | |
---|
31 | /** |
---|
32 | * standard constructor |
---|
33 | */ |
---|
34 | Hyperblast::Hyperblast () : Projectile() |
---|
35 | { |
---|
36 | this->setClassID(CL_HYPERBLAST, "Hyperblast"); |
---|
37 | |
---|
38 | this->loadModel("models/projectiles/hyperblast.obj", 5); |
---|
39 | |
---|
40 | this->setMinEnergy(50); |
---|
41 | this->setHealthMax(1000); |
---|
42 | this->lifeSpan = 1; |
---|
43 | this->size = 4.0; |
---|
44 | |
---|
45 | this->emitter = new BoxEmitter(Vector(400, 2, 2), 100, 5, M_2_PI); |
---|
46 | this->emitter->setRelCoor(200,0,0); |
---|
47 | this->emitter->setParent(this); |
---|
48 | this->emitter->setSpread(M_PI, M_PI); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * standard deconstructor |
---|
54 | */ |
---|
55 | Hyperblast::~Hyperblast () |
---|
56 | { |
---|
57 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
58 | if (Hyperblast::explosionParticles != NULL && ClassList::getList(CL_HYPERBLAST)->size() <= 1) |
---|
59 | { |
---|
60 | Hyperblast::explosionParticles = NULL; |
---|
61 | } |
---|
62 | |
---|
63 | } |
---|
64 | |
---|
65 | SparkParticles* Hyperblast::explosionParticles = NULL; |
---|
66 | |
---|
67 | void Hyperblast::activate() |
---|
68 | { |
---|
69 | if (unlikely(Hyperblast::explosionParticles == NULL)) |
---|
70 | { |
---|
71 | Hyperblast::explosionParticles = new SparkParticles(2000); |
---|
72 | Hyperblast::explosionParticles->setName("HyperblastExplosionParticles"); |
---|
73 | Hyperblast::explosionParticles->setLifeSpan(2, .3); |
---|
74 | Hyperblast::explosionParticles->setRadius(0.1, .1); |
---|
75 | Hyperblast::explosionParticles->setRadius(0.2, .2); |
---|
76 | Hyperblast::explosionParticles->setRadius(1.0, .1); |
---|
77 | Hyperblast::explosionParticles->setColor(0.0, 1.0, .6, 0 ,1); |
---|
78 | Hyperblast::explosionParticles->setColor(0.5, .8,.1,0,.6); |
---|
79 | Hyperblast::explosionParticles->setColor(0.8, .8,.2,.3,.3); |
---|
80 | Hyperblast::explosionParticles->setColor(1.0, 1,1,1,.0); |
---|
81 | } |
---|
82 | |
---|
83 | this->emitter->setSystem(Hyperblast::explosionParticles); |
---|
84 | this->size = 4.0; |
---|
85 | |
---|
86 | Hyperblast::explosionParticles->debug(); |
---|
87 | this->updateNode(0); |
---|
88 | this->emitter->setEmissionRate(5000.0); |
---|
89 | this->emitter->setEmissionVelocity(50.0); |
---|
90 | |
---|
91 | this->setHealth(200); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | void Hyperblast::deactivate() |
---|
96 | { |
---|
97 | this->emitter->setSystem(NULL); |
---|
98 | this->lifeCycle = 0.0; |
---|
99 | this->toList(OM_NULL); |
---|
100 | |
---|
101 | // GarbageCollector::getInstance()->collect(this); |
---|
102 | this->toList(OM_DEAD); |
---|
103 | Hyperblast::fastFactory->kill(this); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | void Hyperblast::collidesWith(WorldEntity* entity, const Vector& location) |
---|
108 | { |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
112 | * signal tick, time dependent things will be handled here |
---|
113 | * @param time since last tick |
---|
114 | */ |
---|
115 | void Hyperblast::tick (float dt) |
---|
116 | { |
---|
117 | if(this->tickLifeCycle(dt)) |
---|
118 | this->deactivate(); |
---|
119 | |
---|
120 | this->size *=(1 - (5.0*dt)); |
---|
121 | |
---|
122 | if (this->lifeCycle > .1 && this->emitter->getEmissionRate() > 10.0) |
---|
123 | this->emitter->setEmissionRate(0.0); |
---|
124 | } |
---|
125 | |
---|
126 | /** |
---|
127 | * the function gets called, when the projectile is destroyed |
---|
128 | */ |
---|
129 | void Hyperblast::destroy () |
---|
130 | { |
---|
131 | Projectile::destroy(); |
---|
132 | |
---|
133 | PRINTF(5)("DESTROY Hyperblast\n"); |
---|
134 | |
---|
135 | |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | void Hyperblast::draw () const |
---|
140 | { |
---|
141 | if (this->lifeCycle < .1) |
---|
142 | { |
---|
143 | glMatrixMode(GL_MODELVIEW); |
---|
144 | glPushMatrix(); |
---|
145 | |
---|
146 | glTranslatef (this->getAbsCoor ().x, |
---|
147 | this->getAbsCoor ().y, |
---|
148 | this->getAbsCoor ().z); |
---|
149 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
150 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
151 | |
---|
152 | // glScalef(2.0, this->size, this->size); |
---|
153 | this->getModel()->draw(); |
---|
154 | |
---|
155 | glPopMatrix(); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|