1 /*------------------------------------------------------------------
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 ------------------------------------------------------------------*/
24 /*------------------------------------------------------------------
28 ------------------------------------------------------------------*/
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 )
53 for ( i
=0; i
<MAX_STARS
; i
++ )
58 Vector_copy ( star_start
, stars
[i
].pos
);
60 stars
[i
].pos
[XPOS
] = (float)j
;
61 stars
[i
].pos
[YPOS
] = (float)k
;
65 stars
[i
].pos
[XPOS
] *= -1.0f
;
68 stars
[i
].pos
[YPOS
] *= -1.0f
;
73 stars
[i
].color
= WHITE
- (m
*15);
77 void Stars_draw ( MATRIX4 r
)
82 for ( i
=0; i
<MAX_STARS
; i
++ )
85 stars
[i
].pos
[ZPOS
] += star_thrust
[j
][ZPOS
] * gv
->fadjust
;
87 if ( stars
[i
].pos
[ZPOS
] > -1.0f
)
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 /*------------------------------------------------------------------
104 ------------------------------------------------------------------*/
106 #define EXPLOSION_ROT 0.23f
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
];
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 )
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 )
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;
194 if ( ecur
> MAX_EXPLOSIONS
-1 )
201 void Explosions_draw ( MATRIX4 r
)
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
;
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 /*------------------------------------------------------------------
256 ------------------------------------------------------------------*/
261 JUMPGATE_TIME
= 5000,
266 struct JUMPGATESTRUCT
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 )
325 for ( i
=0; i
<MAX_JUMPGATES
; i
++ )
327 jgates
[i
].active
= FALSE
;
332 Vector_init ( jgates
[i
].pos
);
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
);
350 if ( jgcur
> MAX_JUMPGATES
-1 )
356 void Jumpgate_animate ( MATRIX4 r
)
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
)
378 if ( jgates
[i
].time
> JUMPGATE_TIME
)
380 jgates
[i
].active
= FALSE
;
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 /*------------------------------------------------------------------
408 ------------------------------------------------------------------*/
413 ONEUP_BLEND_TIME
= 200
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
);
454 one_up
.color
= WHITE
;
458 void One_up_draw ( MATRIX4 r
)
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
;
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 );
490 Draw_line ( p0
[0], p0
[1], p0
[2], p0
[3], one_up
.color
);
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
);
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
);