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 "hbolt.h" |
---|
19 | |
---|
20 | #include "state.h" |
---|
21 | #include "model.h" |
---|
22 | |
---|
23 | #include "particles/dot_emitter.h" |
---|
24 | #include "particles/sprite_particles.h" |
---|
25 | |
---|
26 | #include <cassert> |
---|
27 | #include "debug.h" |
---|
28 | |
---|
29 | #include "static_model.h" |
---|
30 | |
---|
31 | |
---|
32 | #include "class_id_DEPRECATED.h" |
---|
33 | ObjectListDefinition(HBolt); |
---|
34 | CREATE_FAST_FACTORY_STATIC(HBolt); |
---|
35 | |
---|
36 | /** |
---|
37 | * standard constructor |
---|
38 | */ |
---|
39 | HBolt::HBolt () : Projectile() |
---|
40 | { |
---|
41 | this->registerObject(this, HBolt::_objectList); |
---|
42 | |
---|
43 | this->loadModel("models/projectiles/hbolt.obj"); |
---|
44 | |
---|
45 | this->setMinEnergy(10); |
---|
46 | this->setHealthMax(0); |
---|
47 | this->lifeSpan = 7.0; |
---|
48 | |
---|
49 | this->angle = 0; |
---|
50 | this->rotationSpeed = 600; |
---|
51 | |
---|
52 | this->emitter = new DotEmitter(100, 5, M_2_PI); |
---|
53 | this->emitter->setParent(this); |
---|
54 | this->emitter->setSpread(M_PI, M_PI); |
---|
55 | this->emitter->setEmissionRate(300.0); |
---|
56 | this->emitter->setEmissionVelocity(50.0); |
---|
57 | |
---|
58 | this->mat = new Material("hBolt_halo"); |
---|
59 | //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); |
---|
60 | this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE); |
---|
61 | this->mat->setDiffuse(1,1,1); |
---|
62 | this->mat->setDiffuseMap("hbolt_halo.png"); |
---|
63 | // this->mat->setDiffuseMap("hbolt.png",1); |
---|
64 | // this->mat->setDiffuseMap("hbolt_halo.png",2); |
---|
65 | dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat); |
---|
66 | dynamic_cast<StaticModel*>(this->getModel())->finalize(); |
---|
67 | this->mat->select(); |
---|
68 | |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | /** |
---|
73 | * standard deconstructor |
---|
74 | */ |
---|
75 | HBolt::~HBolt () |
---|
76 | { |
---|
77 | // delete this->emitter; |
---|
78 | |
---|
79 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
80 | if (HBolt::explosionParticles != NULL && HBolt::objectList().size() <= 1) |
---|
81 | { |
---|
82 | //if (ClassList::exists(HBolt::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
83 | // delete HBolt::explosionParticles; |
---|
84 | PRINTF(1)("Deleting HBolt Particles\n"); |
---|
85 | HBolt::explosionParticles = NULL; |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|
89 | |
---|
90 | SpriteParticles* HBolt::explosionParticles = NULL; |
---|
91 | |
---|
92 | void HBolt::activate() |
---|
93 | { |
---|
94 | if (unlikely(HBolt::explosionParticles == NULL)) |
---|
95 | { |
---|
96 | HBolt::explosionParticles = new SpriteParticles(1000); |
---|
97 | HBolt::explosionParticles->setName("HBoltExplosionParticles"); |
---|
98 | HBolt::explosionParticles->setLifeSpan(.5, .3); |
---|
99 | HBolt::explosionParticles->setRadius(0.0, 10.0); |
---|
100 | HBolt::explosionParticles->setRadius(.5, 6.0); |
---|
101 | HBolt::explosionParticles->setRadius(1.0, 3.0); |
---|
102 | HBolt::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
103 | HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
104 | HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
105 | } |
---|
106 | |
---|
107 | this->setDamage(100); |
---|
108 | this->setHealth(0); |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | void HBolt::deactivate() |
---|
113 | { |
---|
114 | assert (HBolt::explosionParticles != NULL); |
---|
115 | HBolt::explosionParticles->removeEmitter(this->emitter); |
---|
116 | this->lifeCycle = 0.0; |
---|
117 | |
---|
118 | this->toList(OM_NULL); |
---|
119 | this->removeNode(); |
---|
120 | HBolt::fastFactory->kill(this); |
---|
121 | } |
---|
122 | |
---|
123 | |
---|
124 | void HBolt::collidesWith(WorldEntity* entity, const Vector& location) |
---|
125 | { |
---|
126 | if (this->hitEntity != entity && entity->isA(CL_NPC)) |
---|
127 | this->destroy( entity ); |
---|
128 | this->hitEntity = entity; |
---|
129 | } |
---|
130 | |
---|
131 | |
---|
132 | void HBolt::updateAngle (float time) |
---|
133 | { |
---|
134 | this->angle += this->rotationSpeed * time; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | /** |
---|
139 | * signal tick, time dependent things will be handled here |
---|
140 | * @param dt time since last tick |
---|
141 | */ |
---|
142 | void HBolt::tick (float dt) |
---|
143 | { |
---|
144 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
145 | Vector v = this->velocity * dt; |
---|
146 | this->shiftCoor(v); |
---|
147 | |
---|
148 | if (this->tickLifeCycle(dt)) |
---|
149 | this->deactivate(); |
---|
150 | |
---|
151 | //float w = this->rotationSpeed * M_PI; |
---|
152 | //Quaternion rotation(this->rotationSpeed * dt, this->axis); |
---|
153 | //Quaternion u = this->getRelDir(); |
---|
154 | //this->setRelDir(u * rotation); |
---|
155 | |
---|
156 | this->updateAngle(dt); |
---|
157 | |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * the function gets called, when the projectile is destroyed |
---|
162 | */ |
---|
163 | void HBolt::destroy (WorldEntity* killer) |
---|
164 | { |
---|
165 | Projectile::destroy( killer ); |
---|
166 | PRINTF(5)("DESTROY HBolt\n"); |
---|
167 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
168 | |
---|
169 | this->emitter->setSystem(HBolt::explosionParticles); |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | void HBolt::draw () const |
---|
174 | { |
---|
175 | |
---|
176 | glMatrixMode(GL_MODELVIEW); |
---|
177 | glPushMatrix(); |
---|
178 | |
---|
179 | |
---|
180 | glTranslatef (this->getAbsCoor ().x, |
---|
181 | this->getAbsCoor ().y, |
---|
182 | this->getAbsCoor ().z); |
---|
183 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
184 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
185 | glRotatef(this->angle, 0.0, 0.0, 1.0); |
---|
186 | |
---|
187 | this->getModel()->draw(); |
---|
188 | |
---|
189 | this->mat->select(); |
---|
190 | dynamic_cast<StaticModel*>(this->getModel())->draw(); |
---|
191 | // this->mat->select(); |
---|
192 | // dynamic_cast<StaticModel*>(this->getModel())->draw(); |
---|
193 | this->mat->unselect(); |
---|
194 | |
---|
195 | |
---|
196 | glPopMatrix(); |
---|
197 | } |
---|