1 /*
2 * XGalaga-SDL - a SDL port of XGalaga, clone of the game Galaga
3 * Copyright (c) 1995-1998 Joe Rumsey (mrogre@mediaone.net)
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 */
20
21 #include "xgalaga.h"
22
23 #define MAXPATH 50
24
25 static int paths[NUMPATHS][MAXPATH][2] = {
26 {
27 /* PEELLEFT = 0*/
28 { 0, 3},
29 { 15,3},
30 { 14,3},
31 { 13,3},
32 { 12,3},
33 { 11,3},
34 { 10,3},
35 { 9,3},
36 { 8,3},
37 { -1,-1},
38 },
39 {
40 /* PEELRIGHT = 1 */
41 { 0,3},
42 { 1,3},
43 { 2,3},
44 { 3,3},
45 { 4,3},
46 { 5,3},
47 { 6,3},
48 { 7,3},
49 { 8,3},
50 { -1,-1},
51 },
52 {
53 /* LOOP = 2 */
54 { 8,2},
55 { 9,2},
56 { 10,2},
57 { 11,2},
58 { 12,2},
59 { 13,2},
60 { 14,2},
61 { 15,2},
62 { 0,2},
63 { 1,2},
64 { 2,2},
65 { 3,2},
66 { 4,2},
67 { 5,2},
68 { 6,2},
69 { 7,2},
70 { 8,2},
71 { -1,-1},
72 },
73 {
74 /* SWOOP1 = 3 */
75 { 8,20},
76 { 9,3},
77 { 10,3},
78 { 11,3},
79 { 12,3},
80 { -1,-1},
81 },
82 {
83 /* SWOOP2 = 4 */
84 { 8,20},
85 { 7,3},
86 { 6,3},
87 { 5,3},
88 { 4,3},
89 { -1,-1},
90 },
91 {
92 /* ZIGZAG = 5 */
93 { 7,15 },
94 { 8,2 },
95 { 9,15 },
96 { 8,2 },
97 { 7,15 },
98 { 8,2 },
99 { 9,15 },
100 { 8,2 },
101 { -1,-1 },
102 },
103 {
104 /* LOOP2 = 6 */
105 { 8,2},
106 { 7,2},
107 { 6,2},
108 { 5,2},
109 { 4,2},
110 { 3,2},
111 { 2,2},
112 { 1,2},
113 { 0,2},
114 { 15,2},
115 { 14,2},
116 { 13,2},
117 { 12,2},
118 { 11,2},
119 { 10,2},
120 { 9,2},
121 { 8,2},
122 { -1,-1},
123 },
124 {
125 /* SPIN = 7 */
126 { 8,1},
127 { 7,1},
128 { 6,1},
129 { 5,1},
130 { 4,1},
131 { 3,1},
132 { 2,1},
133 { 1,1},
134 { 0,1},
135 { 15,1},
136 { 14,1},
137 { 13,1},
138 { 12,1},
139 { 11,1},
140 { 10,1},
141 { 9,1},
142 { 8,1},
143 { -1,-1},
144 },
145 {
146 /* LEFTDIAG */
147 { 8,2},
148 { 9,2},
149 { 10,30},
150 { 9,2},
151 { 8,1},
152 { -1,-1},
153 },
154 {
155 /* RIGHTDIAG */
156 { 8,2},
157 { 7,2},
158 { 6,30},
159 { 7,2},
160 { 8,1},
161 { -1,-1},
162 },
163 {
164 /* ENTER1 */
165 { 8,65},
166 { 9,5},
167 { 10,5},
168 { 11,5},
169 { 12,5},
170 { 13,5},
171 { 14,20},
172 { -1,-1},
173 },
174 {
175 /* ENTER2 */
176 { 8,65},
177 { 7,5},
178 { 6,5},
179 { 5,5},
180 { 4,5},
181 { 3,5},
182 { 2,20},
183 { -1,-1},
184 },
185 {
186 /* ENTER3 */
187 { -1,-1 }
188 },
189
190 {
191 /* ENTER4 */
192 { 10,45},
193 { 11,5},
194 { 12,20},
195 { 13,5},
196 { 14,10},
197 { -1,-1},
198 },
199 {
200 /* ENTER5 */
201 { 6,45},
202 { 5,5},
203 { 4,20},
204 { 3,5},
205 { 2,10},
206 { -1,-1},
207 },
208 {
209 /* ENTER6 */
210 { 8,80},
211 { 6,10},
212 { 4,40},
213 { 0,20},
214 { 14,30},
215 { -1,-1 }
216 },
217 {
218 /* ENTER7 */
219 { 8,80},
220 { 10,10},
221 { 12,40},
222 { 0,20},
223 { 2,30},
224 { -1,-1 }
225 },
226 {
227 /* ENTER8 */
228 { 0,50},
229 { 2,50},
230 { 3,5},
231 { 4,5},
232 { 5,5},
233 { 6,5},
234 { 7,5},
235 { 8,5},
236 { 9,5},
237 { 10,5},
238 { 11,5},
239 { 12,30},
240 { 13,5},
241 { 14,5},
242 { 15,5},
243 { 0,5},
244 { -1,-1}
245 },
246 {
247 /* ENTER9 */
248 { 0,50},
249 { 14,50},
250 { 13,5},
251 { 12,5},
252 { 11,5},
253 { 10,5},
254 { 9,5},
255 { 8,5},
256 { 7,5},
257 { 6,5},
258 { 5,5},
259 { 4,30},
260 { 3,5},
261 { 2,5},
262 { 1,5},
263 { 0,5},
264 { -1,-1}
265 },
266 {
267 /* ENTER10 */
268 { 4,80},
269 { 10,30},
270 { 0,70},
271 { -1,-1}
272 },
273 {
274 /* ENTER11 */
275 { 12,80},
276 { 6,30},
277 { 0,70},
278 { -1,-1}
279 },
280 {
281 /* ENTER12 */
282 { 14,80},
283 { -1, -1}
284 },
285 {
286 /* ENTER13 */
287 { 2,80},
288 { -1,-1}
289 },
290 {
291 /* ENTER14 */
292 { 4,8},
293 { 3,6},
294 { 2,8},
295 { 1,10},
296 { 2,8},
297 { 3,6},
298 { 4,4},
299 { 5,6},
300 { 6,8},
301 { 7,10},
302 { 6,8},
303 { 5,6},
304 { 4,4},
305 { 3,6},
306 { 2,8},
307 { 1,10},
308 { 0,20},
309 { -1,-1}
310 },
311 {
312 /* ENTER15 */
313 { 12,60},
314 { 11,3},
315 { 10,3},
316 { 9,3},
317 { 8,3},
318 { 7,3},
319 { 6,3},
320 { 5,3},
321 { 4,3},
322 { 3,3},
323 { 2,3},
324 { 1,3},
325 { 0,3},
326 { 15,3},
327 { 14,3},
328 { 13,3},
329 { 12,3},
330 { 11,3},
331 { 10,3},
332 { 9,3},
333 { 8,3},
334 { 7,3},
335 { 6,3},
336 { 5,3},
337 { 4,3},
338 { 3,3},
339 { 2,3},
340 { 1,3},
341 { 0,3},
342 { 15,3},
343 { 14,3},
344 { 13,3},
345 { 12,3},
346 { 11,3},
347 { 10,3},
348 { 9,3},
349 { 8,3},
350 { 7,3},
351 { 6,3},
352 { 5,3},
353 { 4,3},
354 { 3,3},
355 { 2,3},
356 { 1,3},
357 { 0,20},
358 { -1,-1}
359 },
360 {
361 /* ENTER16 */
362 { 4,60},
363 { 5,3},
364 { 6,3},
365 { 7,3},
366 { 8,3},
367 { 9,3},
368 { 10,3},
369 { 11,3},
370 { 12,3},
371 { 13,3},
372 { 14,3},
373 { 15,3},
374 { 0,3},
375 { 1,3},
376 { 2,3},
377 { 3,3},
378 { 4,3},
379 { 5,3},
380 { 6,3},
381 { 7,3},
382 { 8,3},
383 { 9,3},
384 { 10,3},
385 { 11,3},
386 { 12,3},
387 { 13,3},
388 { 14,3},
389 { 15,3},
390 { 0,3},
391 { 1,3},
392 { 2,3},
393 { 3,3},
394 { 4,3},
395 { 5,3},
396 { 6,3},
397 { 7,3},
398 { 8,3},
399 { 9,3},
400 { 10,3},
401 { 11,3},
402 { 12,3},
403 { 13,3},
404 { 14,3},
405 { 15,3},
406 { 0,20},
407 { -1, -1 }
408 },
409 {
410 /* ENTER17 */
411 { 7,15},
412 { 8,3},
413 { 9,15},
414 { 8,3},
415 { 7,15},
416 { 8,3},
417 { 9,15},
418 { 8,3},
419 { 7,15},
420 { 8,3},
421 { 9,15},
422 { 8,3},
423 { -1,-1},
424 },
425 {
426 /* ENTER18 */
427 { 12,60},
428 { 4,30},
429 { 12,30},
430 { 4,30},
431 { 12,30},
432 { 8,20},
433 { -1,-1 }
434 },
435 {
436 /* ENTER19 */
437 { 10,80},
438 { -1,-1},
439 },
440 {
441 /* ENTER20 */
442 { 6,80},
443 { -1,-1},
444 },
445 };
446
path_dir(int path,int pos,int * dir,int * steer)447 void path_dir(int path, int pos, int *dir, int *steer)
448 {
449 *dir = paths[path][pos][0];
450 *steer = paths[path][pos][1];
451 }
452
enter_path_dir(int path,int pos,int * dir,int * steer)453 void enter_path_dir(int path, int pos, int *dir, int *steer)
454 {
455 *dir = get_dir(path,pos);
456 *steer = get_duration(path, pos);
457 }
458
start_path(int path,struct alien * al)459 void start_path(int path, struct alien *al)
460 {
461 int i;
462
463 for(i=0;(i<MAXPATH) && (paths[path][i][0] >= 0);i++) {
464 if(paths[path][i][0] == al->dir)
465 break;
466 if(paths[path][i][0] < 0) {
467 al->steer = TURNSPEED;
468 al->path = -1;
469 return;
470 }
471 }
472 if(i >= MAXPATH) {
473 al->steer = TURNSPEED;
474 al->path = -1;
475 return;
476 }
477
478 al->path = path;
479 al->path_pos = i;
480 al->steer = paths[path][i][1];
481 }
482
new_alien(int anum,struct alien * al)483 void new_alien(int anum, struct alien *al)
484 {
485 if(get_shape(anum) >= 0) {
486 al->alive = 1;
487 al->dying = 0;
488 al->entering = 1;
489 get_xy(anum, &al->x, &al->y);
490 al->enterdelay = get_delay(anum);
491 al->enterdelay /= 1 + ((metaLevel -1) * .5);
492 al->path = get_path(anum);
493 al->path_pos = 0;
494 al->dir = get_dir(al->path, 0);
495 al->steer = get_duration(al->path, 0);
496 if(metaLevel > 1)
497 al->steer /= 1 + ((metaLevel - 1) * .5);
498 al->escorting = -1;
499 al->shape = getImage(alien_shape[get_shape(anum)]);
500 } else {
501 al->alive = 0;
502 }
503 }
504