disable the unrecognized nls and x flags
[AROS-Contrib.git] / Games / XInvaders3D / effects.c
bloba4afe47ebc4fb6f75183bc8efd94e54b08c916cd
1 /*------------------------------------------------------------------
2 effects.c:
4 XINVADERS 3D - 3d Shoot'em up
5 Copyright (C) 2000 Don Llopis
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 ------------------------------------------------------------------*/
22 #include "game.h"
24 /*------------------------------------------------------------------
25 * Stars
28 ------------------------------------------------------------------*/
30 enum stars_enum
32 MAX_STARS = 100
35 struct STARSSTRUCT
37 VECTOR4 pos;
38 VECTOR4 thrustz;
39 int thrust;
40 unsigned int color;
41 } stars[MAX_STARS];
43 VECTOR4 star_start = { 0.0f, 0.0f, -2000.0f, 1.0f };
44 VECTOR4 star_thrust[4] = {{ 0.0f, 0.0f, 50.0f, 1.0f },
45 { 0.0f, 0.0f, 25.0f, 1.0f },
46 { 0.0f, 0.0f, 15.0f, 1.0f },
47 { 0.0f, 0.0f, 10.0f, 1.0f } };
50 void Stars_init ( void )
52 int i, j, k, m;
53 for ( i=0; i<MAX_STARS; i++ )
55 m = rand () % 4;
56 j = rand () % 800;
57 k = rand () % 800;
58 Vector_copy ( star_start, stars[i].pos );
60 stars[i].pos[XPOS] = (float)j;
61 stars[i].pos[YPOS] = (float)k;
63 if ( (i % 3) == 0 )
65 stars[i].pos[XPOS] *= -1.0f;
66 if ( (i%2) == 0 )
68 stars[i].pos[YPOS] *= -1.0f;
72 stars[i].thrust = m;
73 stars[i].color = WHITE - (m*15);
77 void Stars_draw ( MATRIX4 r )
79 VECTOR4 tmp;
80 int i, j, m, p[2];
82 for ( i=0; i<MAX_STARS; i++ )
84 j = stars[i].thrust;
85 stars[i].pos[ZPOS] += star_thrust[j][ZPOS] * gv->fadjust;
87 if ( stars[i].pos[ZPOS] > -1.0f )
89 m = rand() % 4;
90 stars[i].thrust = m;
91 stars[i].color = WHITE - (m*15);
92 stars[i].pos[ZPOS] = -2000.0f;
94 Matrix_vec_mult ( r, stars[i].pos, tmp );
95 Camera_project_point ( tmp, p );
96 Draw_point ( p[0], p[1], stars[i].color );
100 /*------------------------------------------------------------------
101 * Explosions
104 ------------------------------------------------------------------*/
106 #define EXPLOSION_ROT 0.23f
108 enum explosions_enum
110 MAX_EXPLOSIONS = 10,
111 MAX_PARTICLES = 4,
112 EXPLOSIONS_LIFE = 1500, /* 1.5 sec */
113 EXPLOSION_BLEND_TIME = 375, /* 0.375 sec */
114 EXPLOSION_COLOR_INC = 15
117 struct EXPLOSIONSTRUCT
119 VECTOR4 pos[MAX_PARTICLES];
120 int thrust[MAX_PARTICLES];
121 long frame;
122 long blend;
123 int color;
124 int active;
125 } explosions[MAX_EXPLOSIONS];
127 static int ecur; /* EXPLOSION index */
128 static int ecount; /* EXPLOSION count */
129 static int pcur; /* THURST index */
130 static float erot; /* EXPLOSIONS rotation */
132 /* shard/particle thrust vectors */
133 VECTOR4 pthrust[8] = { {-2.0f, 0.0f, 0.0f, 1.0f},
134 {0.0f, -2.0f, 0.0f, 1.0f},
135 {2.0f, 0.0f, 0.0f, 1.0f},
136 {0.0f, 2.0f, 0.0f, 1.0f},
137 {-2.0f, 2.0f, 0.0f, 1.0f},
138 {2.0f, -2.0f, 0.0f, 1.0f},
139 {-2.0f, -2.0f, 0.0f, 1.0f},
140 {2.0f, 2.0f, 0.0f, 1.0f} };
143 VECTOR4 shard[3] = { {-5.0f, 0.0f, 0.0f, 1.0f},
144 { 0.0f, 5.0f, 0.0f, 1.0f},
145 { 5.0f, -5.0f, 0.0f, 1.0f}};
148 void Explosions_clear ( void )
150 int i, j;
152 ecur = 0;
153 ecount = 0;
154 pcur = 0;
156 erot = 0.0f;
158 for ( i=0; i<MAX_EXPLOSIONS; i++ )
160 explosions[i].active = FALSE;
161 explosions[i].frame = 0L;
162 for (j=0; j<MAX_PARTICLES; j++ )
163 Vector_init ( explosions[i].pos[j] );
167 int Explosions_count ( void )
169 return ecount;
172 void Explosions_add ( OBJECT *obj )
174 explosions[ecur].active = TRUE;
175 explosions[ecur].frame = 0;
176 explosions[ecur].color = GREEN;
177 explosions[ecur].blend = 0;
179 /* ok there are currently only 4 */
180 Vector_copy ( obj->pos, explosions[ecur].pos[0] );
181 Vector_copy ( obj->pos, explosions[ecur].pos[1] );
182 Vector_copy ( obj->pos, explosions[ecur].pos[2] );
183 Vector_copy ( obj->pos, explosions[ecur].pos[3] );
185 explosions[ecur].thrust[0] = pcur;
186 explosions[ecur].thrust[1] = pcur+1;
187 explosions[ecur].thrust[2] = pcur+2;
188 explosions[ecur].thrust[3] = pcur+3;
190 ecur++;
191 pcur += 4;
192 ecount++;
194 if ( ecur > MAX_EXPLOSIONS-1 )
195 ecur = 0;
197 if ( pcur == 8 )
198 pcur = 0;
201 void Explosions_draw ( MATRIX4 r )
203 int i, j, k, p0[6];
204 VECTOR4 tmp[3], shard_tmp[3];
205 MATRIX4 tmp_mat, tmp_mat2, erot_mat;
207 erot += EXPLOSION_ROT * gv->fadjust;
208 Matrix_x_rot ( tmp_mat, erot );
209 Matrix_z_rot ( tmp_mat2, erot );
210 Matrix_mult ( tmp_mat, tmp_mat2, erot_mat );
211 Matrix_vec_multn ( erot_mat, shard, shard_tmp, 3 );
213 for ( i=0; i<MAX_EXPLOSIONS; i++ )
215 if ( explosions[i].active )
217 explosions[i].frame += gv->msec;
218 if ( explosions[i].frame > EXPLOSIONS_LIFE )
220 explosions[i].active = FALSE;
221 ecount--;
223 explosions[i].blend += gv->msec;
224 if ( explosions[i].blend > EXPLOSION_BLEND_TIME )
226 explosions[i].blend -= EXPLOSION_BLEND_TIME;
227 explosions[i].color -= EXPLOSION_COLOR_INC;
230 for ( j=0; j<MAX_PARTICLES; j++ )
232 k = explosions[i].thrust[j];
233 explosions[i].pos[j][XPOS] += pthrust[k][XPOS] * gv->fadjust;
234 explosions[i].pos[j][YPOS] += pthrust[k][YPOS] * gv->fadjust;
235 explosions[i].pos[j][ZPOS] += pthrust[k][ZPOS] * gv->fadjust;
237 Matrix_vec_mult ( r, explosions[i].pos[j], tmp[0] );
238 Matrix_copy ( r, tmp_mat );
239 Matrix_set_trans ( tmp_mat, tmp[0] );
241 Matrix_vec_multn ( tmp_mat, shard_tmp, tmp, 3 );
242 Camera_project_points ( tmp, p0, 3 );
244 Draw_line ( p0[0], p0[1], p0[2], p0[3], explosions[i].color );
245 Draw_line ( p0[2], p0[3], p0[4], p0[5], explosions[i].color );
246 Draw_line ( p0[4], p0[5], p0[0], p0[1], explosions[i].color );
252 /*------------------------------------------------------------------
253 * Jump-gate
256 ------------------------------------------------------------------*/
258 enum jumpgate_enum
260 MAX_JUMPGATES = 4,
261 JUMPGATE_TIME = 5000,
262 JUMPGATE_ANIM = 250,
263 JUMPGATE_FRAMES = 3
266 struct JUMPGATESTRUCT
268 int active;
269 long time;
270 long anim;
271 long frame;
272 int dir;
273 VECTOR4 pos;
274 } jgates[MAX_JUMPGATES];
276 static int jgcur; /* JUMPGATE index */
277 static int jcount; /* JUMPGATE counter */
279 static VECTOR4 jgvert[32] =
281 {-10.0f, 0.0f, 10.0f, 1.0f},
282 {-0.0f, 10.0f, -10.0f, 1.0f},
283 {10.0f, 0.0f, -10.0f, 1.0f},
284 {0.0f, -10.0f, 10.0f, 1.0f},
286 {-30.0f, 0.0f, 30.0f, 1.0f},
287 {0.0f, 30.0f, -30.0f, 1.0f},
288 {30.0f, 0.0f, -30.0f, 1.0f},
289 {0.0f, -30.0f, 30.0f, 1.0f},
291 {-50.0f, 0.0f, 50.0f, 1.0f},
292 {0.0f, 50.0f, -50.0f, 1.0f},
293 {50.0f, 0.0f, -50.0f, 1.0f},
294 {0.0f, -50.0f, 50.0f, 1.0f},
296 {-70.0f, 0.0f, 70.0f, 1.0f},
297 {0.0f, 70.0f, -70.0f, 1.0f},
298 {70.0f, 0.0f, -70.0f, 1.0f},
299 {0.0f, -70.0f, 70.0f, 1.0f},
301 {-10.0f, 0.0f, -10.0f, 1.0f},
302 {0.0f, 10.0f, 10.0f, 1.0f},
303 {10.0f, 0.0f, 10.0f, 1.0f},
304 {0.0f, -10.0f, -10.0f, 1.0f},
306 {-30.0f, 0.0f, -30.0f, 1.0f},
307 {0.0f, 30.0f, 30.0f, 1.0f},
308 {30.0f, 0.0f, 30.0f, 1.0f},
309 {0.0f, -30.0f, -30.0f, 1.0f},
311 {-50.0f, 0.0f, -50.0f, 1.0f},
312 {0.0f, 50.0f, 50.0f, 1.0f},
313 {50.0f, 0.0f, 50.0f, 1.0f},
314 {0.0f, -50.0f, -50.0f, 1.0f},
316 {-70.0f, 0.0f, -70.0f, 1.0f},
317 {0.0f, 70.0f, 70.0f, 1.0f},
318 {70.0f, 0.0f, 70.0f, 1.0f},
319 {0.0f, -70.0f, -70.0f, 1.0f}
322 void Jumpgate_init ( void )
324 int i;
325 for ( i=0; i<MAX_JUMPGATES; i++ )
327 jgates[i].active = FALSE;
328 jgates[i].time = 0;
329 jgates[i].anim = 0;
330 jgates[i].frame = 0;
331 jgates[i].dir = 0;
332 Vector_init ( jgates[i].pos );
334 jgcur = 0;
335 jcount = 0;
338 void Jumpgate_open ( VECTOR4 pos, int dir )
340 if ( jcount > MAX_JUMPGATES-1 ) return;
342 jgates[jgcur].active = TRUE;
343 jgates[jgcur].time = 0;
344 jgates[jgcur].anim = 0;
345 jgates[jgcur].frame = 0;
346 jgates[jgcur].dir = dir * 16;
347 Vector_copy ( pos, jgates[jgcur].pos );
349 jgcur++;
350 if ( jgcur > MAX_JUMPGATES-1 )
351 jgcur = 0;
353 jcount++;
356 void Jumpgate_animate ( MATRIX4 r )
358 MATRIX4 tmp_mat;
359 VECTOR4 tmp[16];
360 int i, j, p[32], f0;
362 for ( i=0; i<MAX_JUMPGATES; i++ )
365 if ( jgates[i].active )
367 jgates[i].time += gv->msec;
368 jgates[i].anim += gv->msec;
370 if ( jgates[i].anim > JUMPGATE_ANIM )
372 jgates[i].anim -= JUMPGATE_ANIM;
373 jgates[i].frame += 1;
374 if ( jgates[i].frame > JUMPGATE_FRAMES )
375 jgates[i].frame = 0;
378 if ( jgates[i].time > JUMPGATE_TIME )
380 jgates[i].active = FALSE;
381 jcount--;
384 /* draw jumpgate */
385 Matrix_vec_mult ( r, jgates[i].pos, tmp[0] );
386 Matrix_copy ( r, tmp_mat );
387 Matrix_set_trans ( tmp_mat, tmp[0] );
389 f0 = ( jgates[i].frame + 1 ) * 4;
390 Matrix_vec_multn ( tmp_mat,
391 &jgvert[jgates[i].dir], tmp, f0 );
392 Camera_project_points ( tmp, p, f0 );
393 for ( j=0; j<((f0*2)-4); j+=8 )
395 Draw_line ( p[0+j], p[1+j], p[2+j], p[3+j], GREEN );
396 Draw_line ( p[2+j], p[3+j], p[4+j], p[5+j], GREEN );
397 Draw_line ( p[4+j], p[5+j], p[6+j], p[7+j], GREEN );
398 Draw_line ( p[6+j], p[7+j], p[0+j], p[1+j], GREEN );
404 /*------------------------------------------------------------------
405 * One-up!!!
408 ------------------------------------------------------------------*/
410 enum oneup_enum
412 ONEUP_LIFE = 2000,
413 ONEUP_BLEND_TIME = 200
416 struct ONEUPSTRUCT
418 VECTOR4 pos;
419 long frame;
420 long blend;
421 long color;
422 int active;
423 }one_up;
425 static VECTOR4 one_up_vert[10] =
427 {-40.0f, 20.0f, 0.0f, 1.0f} , /* 1 */
428 {-40.0f, -20.0f, 0.0f, 1.0f },
429 {-20.0f, 20.0f, 0.0f, 1.0f }, /* U */
430 {-20.0f, -20.0f, 0.0f, 1.0f },
431 { 10.0f, -20.0f, 0.0f, 1.0f },
432 { 10.0f, 20.0f, 0.0f, 1.0f },
433 { 20.0f, 20.0f, 0.0f, 1.0f }, /* P */
434 { 20.0f, -20.0f, 0.0f, 1.0f },
435 { 60.0f, 0.0f, 0.0f, 1.0f },
436 { 20.0f, 0.0f, 0.0, 1.0f }
439 static VECTOR4 oneup_thrust = { 0.0f, 0.0f, 10.0f, 1.0f };
441 void One_up_init ( void )
443 one_up.active = FALSE;
446 void One_up_add ( OBJECT *obj )
448 if ( one_up.active == FALSE )
450 one_up.active = TRUE;
451 Vector_copy ( obj->pos, one_up.pos );
452 one_up.frame = 0;
453 one_up.blend = 0;
454 one_up.color = WHITE;
458 void One_up_draw ( MATRIX4 r )
460 int p0[20];
461 VECTOR4 tmp[10];
462 MATRIX4 tmp_mat;
464 if ( one_up.active )
466 one_up.pos[ZPOS] += oneup_thrust[ZPOS] * gv->fadjust;
467 if ( one_up.pos[ZPOS] > -50.0f )
468 one_up.active = FALSE;
469 one_up.frame += gv->msec;
470 if ( one_up.frame > ONEUP_LIFE )
472 one_up.active = FALSE;
474 one_up.blend += gv->msec;
475 if ( one_up.blend > ONEUP_BLEND_TIME )
477 one_up.blend -= ONEUP_BLEND_TIME;
478 one_up.color -= 3;
481 /* draw one_up */
482 Matrix_vec_mult ( r, one_up.pos, tmp[0] );
483 Matrix_copy ( r, tmp_mat );
484 Matrix_set_trans ( tmp_mat, tmp[0] );
486 Matrix_vec_multn ( tmp_mat, one_up_vert, tmp, 10 );
487 Camera_project_points ( tmp, p0, 10 );
489 /* draw 1 */
490 Draw_line ( p0[0], p0[1], p0[2], p0[3], one_up.color );
492 /* draw U */
493 Draw_line ( p0[4], p0[5], p0[6], p0[7], one_up.color );
494 Draw_line ( p0[6], p0[7], p0[8], p0[9], one_up.color );
495 Draw_line ( p0[8], p0[9], p0[10], p0[11], one_up.color );
497 /* draw P */
498 Draw_line ( p0[12], p0[13], p0[14], p0[15], one_up.color );
499 Draw_line ( p0[12], p0[13], p0[16], p0[17], one_up.color );
500 Draw_line ( p0[16], p0[17], p0[18], p0[19], one_up.color );