1 /*
2  * Copyright (c) 2000 Mark B. Allan. All rights reserved.
3  *
4  * "Chromium B.S.U." is free software; you can redistribute
5  * it and/or use it and/or modify it under the terms of the
6  * "Clarified Artistic License"
7  */
8 #include "Explosions.h"
9 
10 #include <cstdlib>
11 
12 #ifdef HAVE_CONFIG_H
13 #include <chromium-bsu-config.h>
14 #endif
15 
16 #include "compatibility.h"
17 
18 #if defined(HAVE_APPLE_OPENGL_FRAMEWORK) || defined(HAVE_OPENGL_GL_H)
19 #include <OpenGL/gl.h>
20 #else
21 #include <GL/gl.h>
22 #endif
23 
24 #include "extern.h"
25 #include "Global.h"
26 #include "HeroAircraft.h"
27 #include "Image.h"
28 
29 //====================================================================
Explosions()30 Explosions::Explosions()
31 {
32 	game = Global::getInstance();
33 
34 	int		i;
35 	for(i = 0; i < (int)NumExploTypes; i++)
36 	{
37 		tex[i]  = 0;
38 		exploRoot[i] = new Explo();
39 		exploSize[i][0] = 0.5;
40 		exploSize[i][1] = 0.5;
41 		exploStay[i] = 20.0;
42 		exploPause[i][0] = 0;
43 		exploPause[i][1] = 0;
44 		exploPause[i][2] = 0;
45 	}
46 	exploPool = new Explo();
47 
48 	loadTextures();
49 
50 	exploSize[EnemyDestroyed][0] = 1.35;
51 	exploSize[EnemyDestroyed][1] = 1.35;
52 	exploStay[EnemyDestroyed]	= 30.0;
53 
54 	exploSize[EnemyDamage][0]	= 1.0;
55 	exploSize[EnemyDamage][1]	= 1.0;
56 	exploStay[EnemyDamage]		= 20.0;
57 	exploPause[EnemyDamage][1]	= 3;
58 
59 	exploSize[EnemyAmmo00][0]	= 1.5;
60 	exploSize[EnemyAmmo00][1]	= 1.5;
61 	exploStay[EnemyAmmo00]		= 15.0;
62 	exploPause[EnemyAmmo00][1]	= 1;
63 
64 	exploSize[EnemyAmmo01][0]	= 0.5;
65 	exploSize[EnemyAmmo01][1]	= 0.5;
66 	exploStay[EnemyAmmo01]		= 10.0;
67 	exploPause[EnemyAmmo01][1]	= 3;
68 
69 	exploSize[EnemyAmmo02][0]	= 1.7;
70 	exploSize[EnemyAmmo02][1]	= 1.7;
71 	exploStay[EnemyAmmo02]		= 10.0;
72 	exploPause[EnemyAmmo02][1]	= 2;
73 
74 	exploSize[EnemyAmmo03][0]	= 1.7;
75 	exploSize[EnemyAmmo03][1]	= 1.7;
76 	exploStay[EnemyAmmo03]		= 10.0;
77 	exploPause[EnemyAmmo03][1]	= 2;
78 
79 	exploSize[EnemyAmmo04][0]	= 2.0;
80 	exploSize[EnemyAmmo04][1]	= 1.5;
81 	exploStay[EnemyAmmo04]		= 10.0;
82 	exploPause[EnemyAmmo04][1]	= 5;
83 
84 	exploSize[HeroDestroyed][0] = 1.5;
85 	exploSize[HeroDestroyed][1] = 1.5;
86 	exploStay[HeroDestroyed]	= 25.0;
87 
88 	exploSize[HeroDamage][0]	= 1.1;
89 	exploSize[HeroDamage][1]	= 1.1;
90 	exploStay[HeroDamage]		= 25.0;
91 	exploPause[HeroDamage][1]	= 3;
92 
93 	exploSize[HeroAmmo00][0]	= 0.25;
94 	exploSize[HeroAmmo00][1]	= 0.25;
95 	exploStay[HeroAmmo00]		= 10.0;
96 
97 	exploSize[HeroAmmo01][0]	= 0.5;
98 	exploSize[HeroAmmo01][1]	= 1.0;
99 	exploStay[HeroAmmo01]		= 15.0;
100 	exploPause[HeroAmmo01][1]	= 1;
101 
102 	exploSize[HeroAmmo02][0]	= 0.9;
103 	exploSize[HeroAmmo02][1]	= 1.0;
104 	exploStay[HeroAmmo02]		= 23.0;
105 
106 	exploSize[HeroShields][0]	= 1.6;
107 	exploSize[HeroShields][1]	= 1.6;
108 	exploStay[HeroShields]		= 25.0;
109 	exploPause[HeroShields][1]	= 5;
110 
111 	exploSize[PowerBurst][0]	= 1.8;
112 	exploSize[PowerBurst][1]	= 1.8;
113 	exploStay[PowerBurst]		= 35.0;
114 
115 	exploSize[AddLife][0]		= 2.5;
116 	exploSize[AddLife][1]		= 2.5;
117 	exploStay[AddLife]			= 25.0;
118 
119 	exploSize[LoseLife][0]		= 3.5;
120 	exploSize[LoseLife][1]		= 3.5;
121 	exploStay[LoseLife]			= 35.0;
122 
123 	exploSize[ScoreLife][0]		= 3.5;
124 	exploSize[ScoreLife][1]		= 3.5;
125 	exploStay[ScoreLife]		= 35.0;
126 
127 	exploSize[Electric][0]		= 1.7;
128 	exploSize[Electric][1]		= 0.5;
129 	exploStay[Electric]			= 43.0;
130 	exploPause[Electric][1]		= 0;
131 
132 	exploSize[Glitter][0]		= 0.8;
133 	exploSize[Glitter][1]		= 1.0;
134 	exploStay[Glitter]			= 20.0;
135 	exploPause[Glitter][1]		= 0;
136 
137 }
138 
~Explosions()139 Explosions::~Explosions()
140 {
141 	Explo *cur;
142 	Explo *del;
143 
144 	clear();	//-- move all explosions into the pool
145 
146 	cur = exploPool->next;
147 	while(cur)
148 	{
149 		del = cur;
150 		cur = cur->next;
151 		delete del;
152 	}
153 
154 	for(int i = 0; i < (int)NumExploTypes; i++)
155 		delete exploRoot[i];
156 	delete exploPool;
157 
158 	deleteTextures();
159 }
160 
161 //----------------------------------------------------------
loadTextures()162 void	Explosions::loadTextures()
163 {
164 	tex[EnemyDestroyed]	= Image::load(dataLoc("png/enemyExplo.png"), IMG_NOMIPMAPS, IMG_ALPHA, GL_CLAMP, GL_NEAREST, GL_LINEAR);
165 	tex[EnemyDamage]	= tex[EnemyDestroyed];
166 	tex[EnemyAmmo00]	= Image::load(dataLoc("png/enemyAmmoExplo00.png"));
167 	tex[EnemyAmmo01]	= Image::load(dataLoc("png/enemyAmmoExplo01.png"), IMG_NOMIPMAPS, IMG_ALPHA, GL_CLAMP, GL_NEAREST, GL_LINEAR);
168 	tex[EnemyAmmo02]	= Image::load(dataLoc("png/enemyAmmoExplo02.png"));
169 	tex[EnemyAmmo03]	= Image::load(dataLoc("png/enemyAmmoExplo03.png"));
170 	tex[EnemyAmmo04]	= Image::load(dataLoc("png/enemyAmmoExplo04.png"));
171 	tex[HeroDestroyed]	= Image::load(dataLoc("png/enemyExplo.png"), IMG_NOMIPMAPS, IMG_ALPHA, GL_CLAMP, GL_NEAREST, GL_LINEAR);
172 	tex[HeroDamage]		= tex[HeroDestroyed];
173 	tex[HeroAmmo00]		= Image::load(dataLoc("png/heroAmmoExplo00.png"), IMG_NOMIPMAPS, IMG_ALPHA, GL_CLAMP, GL_NEAREST, GL_NEAREST);
174 	tex[HeroAmmo01]		= Image::load(dataLoc("png/heroAmmoExplo01.png"), IMG_NOMIPMAPS, IMG_ALPHA, GL_CLAMP, GL_NEAREST, GL_LINEAR);
175 	tex[HeroAmmo02]		= Image::load(dataLoc("png/heroAmmoExplo02.png"), IMG_NOMIPMAPS, IMG_ALPHA, GL_CLAMP, GL_NEAREST, GL_LINEAR);
176 	tex[HeroShields]	= Image::load(dataLoc("png/heroShields.png"), IMG_NOMIPMAPS, IMG_BLEND3, GL_CLAMP, GL_LINEAR, GL_LINEAR);
177 //	tex[HeroShields]	= Image::load(dataLoc("png/heroShields.png"), IMG_NOMIPMAPS, IMG_BLEND1, GL_CLAMP, GL_LINEAR, GL_LINEAR);
178 	tex[PowerBurst]		= Image::load(dataLoc("png/powerUpTex.png"), IMG_NOMIPMAPS, IMG_BLEND3, GL_CLAMP, GL_LINEAR, GL_LINEAR);
179 	tex[AddLife]		= Image::load(dataLoc("png/life.png"));
180 	tex[LoseLife]		= tex[AddLife];
181 	tex[ScoreLife]		= tex[AddLife];
182 	tex[Electric]		= Image::load(dataLoc("png/electric.png"), IMG_NOMIPMAPS, IMG_BLEND3, GL_REPEAT, GL_LINEAR, GL_LINEAR);
183 	tex[Glitter]		= Image::load(dataLoc("png/glitter.png"));
184 }
185 
186 //----------------------------------------------------------
deleteTextures()187 void	Explosions::deleteTextures()
188 {
189 	for(int i = 0; i < (int)NumExploTypes; i++)
190 	{
191 		glDeleteTextures(1, &tex[i]);
192 		tex[i] = 0;
193 	}
194 }
195 
196 //----------------------------------------------------------
clear()197 void	Explosions::clear()
198 {
199 	int i;
200 	Explo *cur;
201 	Explo *del;
202 
203 	for(i = 0; i < NumExploTypes; i++)
204 	{
205 		cur = exploRoot[i]->next;
206 		while(cur)
207 		{
208 			del = cur;
209 			cur = cur->next;
210 			killExplo(del);
211 		}
212 		exploRoot[i]->next = 0;
213 	}
214 }
215 
216 //----------------------------------------------------------
getNewExplo()217 Explo *Explosions::getNewExplo()
218 {
219 	Explo *retExplo;
220 	if(exploPool->next)
221 	{
222 		retExplo = exploPool->next;
223 		exploPool->next = retExplo->next;
224 	}
225 	else
226 	{
227 		retExplo = new Explo();
228 	}
229 	return retExplo;
230 }
231 
232 //----------------------------------------------------------
killExplo(Explo * dead)233 void Explosions::killExplo(Explo *dead)
234 {
235 	dead->back = 0;
236 	dead->next = exploPool->next;
237 	exploPool->next = dead;
238 }
239 
240 //----------------------------------------------------------
addExplo(ExploType t,float p[3],int a,float s)241 Explo *Explosions::addExplo(ExploType t, float p[3], int a, float s)
242 {
243 	Explo *newExplo	= 0;
244 	Explo *first	= 0;
245 
246 	if((exploPause[t][0]) <= 0)
247 	{
248 		exploPause[t][2] = 1; //-- set flag to init explo pause count
249 		newExplo = getNewExplo();
250 		newExplo->init(p, a, s);
251 		newExplo->back = exploRoot[t];
252 		newExplo->next = exploRoot[t]->next;
253 		first = exploRoot[t]->next;
254 		if(first)
255 			first->back = newExplo;
256 		exploRoot[t]->next = newExplo;
257 	}
258 	return newExplo;
259 }
260 
261 //----------------------------------------------------------
addElectric(float p[3],float v[3],float clr[4],int age,float size)262 Explo *Explosions::addElectric(float p[3], float v[3], float clr[4], int age, float size)
263 {
264 	Explo *newExplo	= 0;
265 	Explo *first	= 0;
266 
267 	exploPause[Electric][2] = 1; //-- set flag to init explo pause count
268 	newExplo = getNewExplo();
269 	newExplo->init(p, v, clr, age, size);
270 	newExplo->back = exploRoot[Electric];
271 	newExplo->next = exploRoot[Electric]->next;
272 	first = exploRoot[Electric]->next;
273 	if(first)
274 		first->back = newExplo;
275 	exploRoot[Electric]->next = newExplo;
276 	return newExplo;
277 }
278 
279 //----------------------------------------------------------
addGlitter(float p[3],float v[3],float clr[4],int age,float size)280 Explo *Explosions::addGlitter(float p[3], float v[3], float clr[4], int age, float size)
281 {
282 	Explo *newExplo	= 0;
283 	Explo *first	= 0;
284 
285 	exploPause[Glitter][2] = 1; //-- set flag to init explo pause count
286 	newExplo = getNewExplo();
287 	newExplo->init(p, v, clr, age, size);
288 	newExplo->back = exploRoot[Glitter];
289 	newExplo->next = exploRoot[Glitter]->next;
290 	first = exploRoot[Glitter]->next;
291 	if(first)
292 		first->back = newExplo;
293 	exploRoot[Glitter]->next = newExplo;
294 	return newExplo;
295 }
296 
297 //----------------------------------------------------------
update()298 void	Explosions::update()
299 {
300 	Explo	*explo;
301 	Explo	*backExplo;
302 	Explo	*nextExplo;
303 	for(int i = 0; i < NumExploTypes; i++)
304 	{
305 		if(exploPause[i][0] > 0.0)
306 			exploPause[i][0] -= game->speedAdj;
307 		else
308 			exploPause[i][0] = 0.0;
309 		if(exploPause[i][2]) //-- if flag was set, init count
310 		{
311 			exploPause[i][0] = exploPause[i][1];
312 			exploPause[i][2] = 0.0;
313 		}
314 
315 		explo = exploRoot[i]->next;
316 		while(explo)
317 		{
318 			explo->age++;
319 			if(explo->age > 0)
320 			{
321 				explo->pos[0] += explo->vel[0]*game->speedAdj;
322 				explo->pos[1] += explo->vel[1]*game->speedAdj;
323 				explo->pos[2] += explo->vel[2]*game->speedAdj;
324 			}
325 			if(explo->age > (exploStay[i]/game->speedAdj))
326 			{
327 				backExplo = explo->back;
328 				nextExplo = explo->next;
329 				backExplo->next = nextExplo;
330 				if(nextExplo)
331 					nextExplo->back = backExplo;
332 				killExplo(explo);
333 				explo = nextExplo;
334 			}
335 			else
336 				explo = explo->next;
337 		}
338 	}
339 }
340 
341 //----------------------------------------------------------
drawGL()342 void	Explosions::drawGL()
343 {
344 
345 	if(exploRoot[EnemyDestroyed]->next)	drawExplo(EnemyDestroyed);
346 	if(exploRoot[EnemyDamage]->next)	drawExplo(EnemyDamage);
347 	if(exploRoot[EnemyAmmo00]->next)	drawAmmo(EnemyAmmo00);
348 	if(exploRoot[EnemyAmmo01]->next)	drawAmmo(EnemyAmmo01);
349 	if(exploRoot[EnemyAmmo02]->next)	drawAmmo(EnemyAmmo02);
350 	if(exploRoot[EnemyAmmo03]->next)	drawAmmo(EnemyAmmo03);
351 	if(exploRoot[EnemyAmmo04]->next)	drawAmmo(EnemyAmmo04);
352 
353 	if(exploRoot[HeroDestroyed]->next)	drawExplo(HeroDestroyed);
354 	if(exploRoot[HeroDamage]->next)		drawExplo(HeroDamage);
355 	if(exploRoot[HeroAmmo00]->next)		drawAmmo(HeroAmmo00);
356 	if(exploRoot[HeroAmmo01]->next)		drawAmmo(HeroAmmo01);
357 	if(exploRoot[HeroAmmo02]->next)		drawAmmo(HeroAmmo02);
358 
359 	if(exploRoot[HeroShields]->next)	drawShields(HeroShields);
360 	if(exploRoot[PowerBurst]->next)		drawBurst(PowerBurst);
361 
362 	if(exploRoot[AddLife]->next)		drawLife(AddLife);
363 	if(exploRoot[LoseLife]->next)		drawLife(LoseLife);
364 	if(exploRoot[ScoreLife]->next)		drawLife(ScoreLife);
365 
366 	if(exploRoot[Electric]->next)		drawElectric(Electric);
367 	if(exploRoot[Glitter]->next)		drawGlitter(Glitter);
368 }
369 
370 //----------------------------------------------------------
drawExplo(ExploType type)371 void	Explosions::drawExplo(ExploType type)
372 {
373 	float	age;
374 	float	ex, ey;
375 	float	exs, eys;
376 	float	*p;
377 	float	clr, tmp;
378 	float	xoff,yoff;
379 	Explo	*thisExplo;
380 
381 	glColor4f(1.0, 1.0, 1.0, 1.0);
382 
383 	glBindTexture(GL_TEXTURE_2D, tex[type]);
384 	thisExplo = exploRoot[type]->next;
385 	glBegin(GL_QUADS);
386 	while(thisExplo)
387 	{
388 		age = thisExplo->age*game->speedAdj;
389 		if( age >= 0)
390 		{
391 			clr = age/exploStay[type];
392 			ex = thisExplo->size*exploSize[type][0]*clr;
393 			ey = thisExplo->size*exploSize[type][1]*clr;
394 //			ex = thisExplo->size*exploSize[type][0]*((thisExplo->age)/(exploStay[type]));
395 //			ey = thisExplo->size*exploSize[type][1]*((thisExplo->age)/(exploStay[type]));
396 			exs = ex * 0.7;
397 			eys = ey * 0.7;
398 			tmp = clr*clr;
399 			clr = 1.2-clr;
400 			tmp = 0.5+clr*0.5;
401 			glColor4f(tmp, tmp, tmp, clr);
402 
403 			if(type == HeroDamage)
404 				p = game->hero->pos;
405 			else
406 				p = thisExplo->pos;
407 
408 			if(type == EnemyDestroyed)
409 			{
410 				xoff = 0.1;
411 				yoff = 0.3;
412 				glTexCoord2f(0.0, 1.0); glVertex3f(p[0]-exs+xoff, p[1]+eys+yoff, p[2]);
413 				glTexCoord2f(0.0, 0.0); glVertex3f(p[0]-exs+xoff, p[1]-eys+yoff, p[2]);
414 				glTexCoord2f(1.0, 0.0); glVertex3f(p[0]+exs+xoff, p[1]-eys+yoff, p[2]);
415 				glTexCoord2f(1.0, 1.0); glVertex3f(p[0]+exs+xoff, p[1]+eys+yoff, p[2]);
416 
417 				xoff = -0.2;
418 				yoff = -0.4;
419 				glTexCoord2f(0.0, 1.0); glVertex3f(p[0]-exs+xoff, p[1]+eys+yoff, p[2]);
420 				glTexCoord2f(0.0, 0.0); glVertex3f(p[0]-exs+xoff, p[1]-eys+yoff, p[2]);
421 				glTexCoord2f(1.0, 0.0); glVertex3f(p[0]+exs+xoff, p[1]-eys+yoff, p[2]);
422 				glTexCoord2f(1.0, 1.0); glVertex3f(p[0]+exs+xoff, p[1]+eys+yoff, p[2]);
423 			}
424 			xoff =  0.0;
425 			yoff = -0.3;
426 			glTexCoord2f(0.0, 1.0); glVertex3f(p[0]-ex+xoff, p[1]+ey+yoff, p[2]);
427 			glTexCoord2f(0.0, 0.0); glVertex3f(p[0]-ex+xoff, p[1]-ey+yoff, p[2]);
428 			glTexCoord2f(1.0, 0.0); glVertex3f(p[0]+ex+xoff, p[1]-ey+yoff, p[2]);
429 			glTexCoord2f(1.0, 1.0); glVertex3f(p[0]+ex+xoff, p[1]+ey+yoff, p[2]);
430 		}
431 
432 		thisExplo = thisExplo->next; //ADVANCE
433 	}
434 	glEnd();
435 
436 }
437 
438 //----------------------------------------------------------
drawAmmo(ExploType type)439 void	Explosions::drawAmmo(ExploType type)
440 {
441 	float	age;
442 	float	ex, ey;
443 	float	clr;//,tmp;
444 	float	*pos;
445 	Explo	*thisExplo;
446 
447 	glBindTexture(GL_TEXTURE_2D, tex[type]);
448 	thisExplo = exploRoot[type]->next;
449 	glBegin(GL_QUADS);
450 	while(thisExplo)
451 	{
452 		age = thisExplo->age*game->speedAdj;
453 		ex = exploSize[type][0]*((age+5.0f)/(exploStay[type]+5.0f));
454 		ey = exploSize[type][1]*((age+5.0f)/(exploStay[type]+5.0f));
455 		clr = age/exploStay[type];
456 		//tmp = clr*clr*clr;
457 		if( (clr = (1.2-clr)) > 1.0)
458 			clr = 1.0;
459 		glColor4f(1.0, 1.0, 1.0, clr);
460 		pos = thisExplo->pos;
461 		glTexCoord2f(0.0, 0.0); glVertex3f(pos[0]-ex, pos[1]+ey, pos[2]);
462 		glTexCoord2f(0.0, 1.0); glVertex3f(pos[0]-ex, pos[1]-ey, pos[2]);
463 		glTexCoord2f(1.0, 1.0); glVertex3f(pos[0]+ex, pos[1]-ey, pos[2]);
464 		glTexCoord2f(1.0, 0.0); glVertex3f(pos[0]+ex, pos[1]+ey, pos[2]);
465 		thisExplo = thisExplo->next; //ADVANCE
466 	}
467 	glEnd();
468 }
469 
470 //----------------------------------------------------------
drawBurst(ExploType type)471 void	Explosions::drawBurst(ExploType type)
472 {
473 	float	age;
474 	float	ex, ey;
475 	float	clr,tmp;
476 	float	*pos;
477 	Explo	*thisExplo;
478 
479 	glBindTexture(GL_TEXTURE_2D, tex[type]);
480 	thisExplo = exploRoot[type]->next;
481 	while(thisExplo)
482 	{
483 		age = thisExplo->age*game->speedAdj;
484 		tmp = 1.0-age/exploStay[type];
485 		clr = tmp;
486 		ex = thisExplo->size*exploSize[type][0]*clr;
487 		ey = thisExplo->size*exploSize[type][1]*clr;
488 		clr = tmp*0.75;
489 		glColor4f(clr+0.5, clr+0.2, clr+0.1, clr);
490 		pos = thisExplo->pos;
491 		glPushMatrix();
492 		glTranslatef(pos[0], pos[1], pos[2]);
493 		glRotatef(IRAND, 0.0, 0.0, 1.0);
494 		glBegin(GL_QUADS);
495 		glTexCoord2f(0.0, 0.0); glVertex3f( -ex,  ey, 0.0);
496 		glTexCoord2f(0.0, 1.0); glVertex3f( -ex, -ey, 0.0);
497 		glTexCoord2f(1.0, 1.0); glVertex3f(  ex, -ey, 0.0);
498 		glTexCoord2f(1.0, 0.0); glVertex3f(  ex,  ey, 0.0);
499 		glEnd();
500 		glRotatef(IRAND, 0.0, 0.0, 1.0);
501 		glBegin(GL_QUADS);
502 		glTexCoord2f(0.0, 0.0); glVertex3f( -ex,  ey, 0.0);
503 		glTexCoord2f(0.0, 1.0); glVertex3f( -ex, -ey, 0.0);
504 		glTexCoord2f(1.0, 1.0); glVertex3f(  ex, -ey, 0.0);
505 		glTexCoord2f(1.0, 0.0); glVertex3f(  ex,  ey, 0.0);
506 		glEnd();
507 		glPopMatrix();
508 		thisExplo = thisExplo->next; //ADVANCE
509 	}
510 }
511 
512 //----------------------------------------------------------
drawShields(ExploType type)513 void	Explosions::drawShields(ExploType type)
514 {
515 	float	age;
516 	float	ex, ey;
517 	float	clr,tmp;
518 	float	*pos;
519 	Explo	*thisExplo;
520 
521 	if(!game->hero->isVisible())
522 		return;
523 	glBindTexture(GL_TEXTURE_2D, tex[type]);
524 	thisExplo = exploRoot[type]->next;
525 	while(thisExplo)
526 	{
527 		age = thisExplo->age*game->speedAdj;
528 		tmp = age/exploStay[type];
529 		clr = 1.0-tmp;
530 		tmp = 0.5+(clr*0.5);
531 		ex = exploSize[type][0]*tmp;
532 		ey = exploSize[type][1]*tmp;
533 		glColor4f(clr, clr, 1.0, clr*0.7);
534 		pos = game->hero->pos;
535 		glPushMatrix();
536 		glTranslatef(pos[0], pos[1], pos[2]);
537 		glRotatef(IRAND, 0.0, 0.0, 1.0);
538 		glBegin(GL_QUADS);
539 		glTexCoord2f(0.0, 0.0); glVertex3f( -ex,  ey, 0.0);
540 		glTexCoord2f(0.0, 1.0); glVertex3f( -ex, -ey, 0.0);
541 		glTexCoord2f(1.0, 1.0); glVertex3f(  ex, -ey, 0.0);
542 		glTexCoord2f(1.0, 0.0); glVertex3f(  ex,  ey, 0.0);
543 		glEnd();
544 		glPopMatrix();
545 		thisExplo = thisExplo->next; //ADVANCE
546 	}
547 }
548 
549 //----------------------------------------------------------
drawLife(ExploType type)550 void	Explosions::drawLife(ExploType type)
551 {
552 	float	age;
553 	float	ex, ey;
554 	float	*p;
555 	float	clr[4] = { 1.0, 1.0, 1.0, 1.0 };
556 	float	tmp;
557 	Explo	*thisExplo;
558 
559 	glBindTexture(GL_TEXTURE_2D, tex[type]);
560 	thisExplo = exploRoot[type]->next;
561 	glBegin(GL_QUADS);
562 	while(thisExplo)
563 	{
564 		age = thisExplo->age*game->speedAdj;
565 		if(age >= 0)
566 		{
567 			p = thisExplo->pos;
568 			tmp = age/exploStay[type];
569 			if(type == AddLife)
570 			{
571 				clr[0] = clr[1] = tmp;
572 				clr[2] = 1.0;
573 				clr[3] = tmp+0.2;
574 				tmp = 1.0-tmp;
575 			}
576 			else if(type == LoseLife)
577 			{
578 				clr[0] = 1.0;
579 				clr[1] = clr[2] = 0.1;
580 				clr[3] = 1.0-tmp;
581 			}
582 			else
583 			{
584 				clr[0] = clr[1] = clr[2] = 1.0;
585 				clr[3] = 1.0-tmp;
586 			}
587 			ex = thisExplo->size*exploSize[type][0]*tmp;
588 			ey = thisExplo->size*exploSize[type][1]*tmp;
589 			glColor4fv(clr);
590 			glTexCoord2f(0.0, 1.0); glVertex3f(p[0]-ex, p[1]+ey, p[2]);
591 			glTexCoord2f(0.0, 0.0); glVertex3f(p[0]-ex, p[1]-ey, p[2]);
592 			glTexCoord2f(1.0, 0.0); glVertex3f(p[0]+ex, p[1]-ey, p[2]);
593 			glTexCoord2f(1.0, 1.0); glVertex3f(p[0]+ex, p[1]+ey, p[2]);
594 		}
595 
596 		thisExplo = thisExplo->next; //ADVANCE
597 	}
598 	glEnd();
599 
600 }
601 
602 //----------------------------------------------------------
drawElectric(ExploType type)603 void	Explosions::drawElectric(ExploType type)
604 {
605 	float	age;
606 	float	ex, ey;
607 	float	alpha,tmp;
608 	float	*clr;
609 	float	*pos;
610 	Explo	*thisExplo;
611 	float	tOff;
612 
613 	glBindTexture(GL_TEXTURE_2D, tex[type]);
614 	thisExplo = exploRoot[type]->next;
615 	while(thisExplo)
616 	{
617 		age = thisExplo->age*game->speedAdj;
618 		if(age >= 0)
619 		{
620 			tmp = age/exploStay[type];
621 			alpha = 1.0-tmp;
622 			alpha = 5.0*(alpha*alpha);
623 			clr = thisExplo->clr;
624 			glColor4f(clr[0], clr[1], clr[2], clr[3]*alpha);
625 			ex = exploSize[type][0];
626 			ey = exploSize[type][1]*tmp;
627 			tmp = (1.0-game->speedAdj)+(game->speedAdj*1.075);
628 			thisExplo->vel[0] *= tmp;
629 			thisExplo->vel[1] *= tmp;
630 			thisExplo->vel[2] *= tmp;
631 			pos = thisExplo->pos;
632 			tOff = FRAND;
633 			glPushMatrix();
634 				glTranslatef(pos[0], pos[1], pos[2]);
635 				glBegin(GL_QUADS);
636 				glTexCoord2f(0.0, 0.0+tOff); glVertex3f( -ex,  ey, 0.0);
637 				glTexCoord2f(0.0, 0.2+tOff); glVertex3f( -ex, -ey, 0.0);
638 				glTexCoord2f(1.0, 0.2+tOff); glVertex3f(  ex, -ey, 0.0);
639 				glTexCoord2f(1.0, 0.0+tOff); glVertex3f(  ex,  ey, 0.0);
640 				glEnd();
641 			glPopMatrix();
642 		}
643 		thisExplo = thisExplo->next; //ADVANCE
644 	}
645 }
646 
647 //----------------------------------------------------------
drawGlitter(ExploType type)648 void	Explosions::drawGlitter(ExploType type)
649 {
650 	float	age;
651 	float	ex, ey;
652 	float	alpha,tmp;
653 	float	*clr;
654 	float	*pos;
655 	Explo	*thisExplo;
656 
657 	glBindTexture(GL_TEXTURE_2D, tex[type]);
658 	thisExplo = exploRoot[type]->next;
659 	while(thisExplo)
660 	{
661 		age = thisExplo->age*game->speedAdj;
662 		if( age >= 0)
663 		{
664 			tmp = age/exploStay[type];
665 			alpha = 1.0-tmp;
666 			//alpha = 5.0*(alpha*alpha);
667 			clr = thisExplo->clr;
668 			glColor4f(clr[0], clr[1], clr[2], clr[3]*alpha);
669 			tmp = alpha*alpha;
670 			ex = tmp*thisExplo->size*exploSize[type][0];
671 			ey = tmp*thisExplo->size*exploSize[type][1]+(0.02*age);
672 			pos = thisExplo->pos;
673 			glPushMatrix();
674 				glTranslatef(pos[0], pos[1], pos[2]);
675 				glBegin(GL_QUADS);
676 				glTexCoord2f(0.0, 0.0); glVertex3f( -ex,  ey, 0.0);
677 				glTexCoord2f(0.0, 1.0); glVertex3f( -ex, -ey, 0.0);
678 				glTexCoord2f(1.0, 1.0); glVertex3f(  ex, -ey, 0.0);
679 				glTexCoord2f(1.0, 0.0); glVertex3f(  ex,  ey, 0.0);
680 				glEnd();
681 			glPopMatrix();
682 
683 		}
684 		thisExplo = thisExplo->next; //ADVANCE
685 	}
686 }
687 
688 
689 //====================================================================
690 int Explo::exploCount = 0;
Explo()691 Explo::Explo()
692 {
693 	age		= 0;
694 	back	= 0;
695 	next 	= 0;
696 	size	= 1;
697 	exploCount++;
698 }
699 
~Explo()700 Explo::~Explo()
701 {
702 	exploCount--;
703 }
704 
init(float p[3],int a,float s)705 void Explo::init(float p[3], int a, float s)
706 {
707 	pos[0]	= p[0];
708 	pos[1]	= p[1];
709 	pos[2]	= p[2];
710 	vel[0]	= 0.0;
711 	vel[1]	= 0.0;
712 	vel[2]	= 0.0;
713 	clr[0]	= 1.0;
714 	clr[1]	= 1.0;
715 	clr[2]	= 1.0;
716 	clr[3]	= 1.0;
717 	age		= (int)(a/(Global::getInstance()->speedAdj) );
718 	size	= s;
719 	back	= 0;
720 	next 	= 0;
721 }
722 
init(float p[3],float v[3],float c[4],int a,float s)723 void Explo::init(float p[3], float v[3], float c[4], int a, float s)
724 {
725 	pos[0]	= p[0];
726 	pos[1]	= p[1];
727 	pos[2]	= p[2];
728 	vel[0]	= v[0];
729 	vel[1]	= v[1];
730 	vel[2]	= v[2];
731 	clr[0]	= c[0];
732 	clr[1]	= c[1];
733 	clr[2]	= c[2];
734 	clr[3]	= c[3];
735 	age		= (int)(a/(Global::getInstance()->speedAdj) );
736 	size	= s;
737 	back	= 0;
738 	next 	= 0;
739 }
740 
741