1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: weapons.c 72 2003-10-02 01:08:13Z sam $ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <stdlib.h> |
---|
24 | |
---|
25 | #include "common.h" |
---|
26 | |
---|
27 | static void draw_bomb( int x, int y, int vx, int vy ); |
---|
28 | static void draw_nuke( int x, int y, int frame ); |
---|
29 | static void draw_beam( int x, int y, int frame ); |
---|
30 | static void draw_circle( int x, int y, int r, char c ); |
---|
31 | static void draw_fragbomb( int x, int y, int frame ); |
---|
32 | |
---|
33 | void init_weapons( game *g, weapons *wp ) |
---|
34 | { |
---|
35 | int i; |
---|
36 | |
---|
37 | for( i = 0; i < WEAPONS; i++ ) |
---|
38 | { |
---|
39 | wp->type[i] = WEAPON_NONE; |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | void draw_weapons( game *g, weapons *wp ) |
---|
44 | { |
---|
45 | int i; |
---|
46 | |
---|
47 | for( i = 0; i < WEAPONS; i++ ) |
---|
48 | { |
---|
49 | switch( wp->type[i] ) |
---|
50 | { |
---|
51 | case WEAPON_LASER: |
---|
52 | gfx_color( WHITE ); |
---|
53 | gfx_goto( wp->x[i] >> 4, wp->y[i] >> 4 ); |
---|
54 | gfx_putchar( '|' ); |
---|
55 | gfx_color( CYAN ); |
---|
56 | gfx_goto( wp->x[i] >> 4, (wp->y[i] >> 4) + 1 ); |
---|
57 | gfx_putchar( '|' ); |
---|
58 | break; |
---|
59 | case WEAPON_SEEKER: |
---|
60 | gfx_color( CYAN ); |
---|
61 | gfx_goto( wp->x3[i] >> 4, wp->y3[i] >> 4 ); |
---|
62 | gfx_putchar( '.' ); |
---|
63 | gfx_goto( wp->x2[i] >> 4, wp->y2[i] >> 4 ); |
---|
64 | gfx_putchar( 'o' ); |
---|
65 | gfx_color( WHITE ); |
---|
66 | gfx_goto( wp->x[i] >> 4, wp->y[i] >> 4 ); |
---|
67 | gfx_putchar( '@' ); |
---|
68 | break; |
---|
69 | case WEAPON_BOMB: |
---|
70 | gfx_color( GRAY ); |
---|
71 | gfx_goto( (wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4 ); |
---|
72 | gfx_putchar( '.' ); |
---|
73 | gfx_goto( (wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4 ); |
---|
74 | gfx_putchar( '.' ); |
---|
75 | gfx_goto( (wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4 ); |
---|
76 | gfx_putchar( '.' ); |
---|
77 | gfx_goto( wp->x3[i] >> 4, wp->y3[i] >> 4 ); |
---|
78 | gfx_putchar( '.' ); |
---|
79 | gfx_goto( wp->x2[i] >> 4, wp->y2[i] >> 4 ); |
---|
80 | gfx_putchar( '.' ); |
---|
81 | draw_bomb( wp->x[i] >> 4, wp->y[i] >> 4, wp->vx[i], wp->vy[i] ); |
---|
82 | break; |
---|
83 | case WEAPON_FRAGBOMB: |
---|
84 | draw_fragbomb( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] ); |
---|
85 | break; |
---|
86 | case WEAPON_BEAM: |
---|
87 | draw_beam( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] ); |
---|
88 | break; |
---|
89 | case WEAPON_NUKE: |
---|
90 | draw_nuke( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] ); |
---|
91 | break; |
---|
92 | case WEAPON_LIGHTNING: |
---|
93 | case WEAPON_NONE: |
---|
94 | break; |
---|
95 | } |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | void update_weapons( game *g, weapons *wp ) |
---|
100 | { |
---|
101 | int i, j, dist, xmin, ymin, dx, dy, xnew, ynew; |
---|
102 | |
---|
103 | for( i = 0; i < WEAPONS; i++ ) |
---|
104 | { |
---|
105 | switch( wp->type[i] ) |
---|
106 | { |
---|
107 | case WEAPON_LASER: |
---|
108 | wp->x[i] += wp->vx[i]; |
---|
109 | wp->y[i] += wp->vy[i]; |
---|
110 | if( wp->y[i] < 0 ) |
---|
111 | { |
---|
112 | wp->type[i] = WEAPON_NONE; |
---|
113 | } |
---|
114 | break; |
---|
115 | case WEAPON_BOMB: |
---|
116 | case WEAPON_SEEKER: |
---|
117 | /* Update tail */ |
---|
118 | wp->x3[i] = wp->x2[i]; |
---|
119 | wp->y3[i] = wp->y2[i]; |
---|
120 | |
---|
121 | wp->x2[i] = wp->x[i]; |
---|
122 | wp->y2[i] = wp->y[i]; |
---|
123 | |
---|
124 | wp->x[i] += wp->vx[i]; |
---|
125 | wp->y[i] += wp->vy[i]; |
---|
126 | |
---|
127 | if( wp->y[i] < 0 ) |
---|
128 | { |
---|
129 | wp->type[i] = WEAPON_NONE; |
---|
130 | break; |
---|
131 | } |
---|
132 | |
---|
133 | if( wp->n[i] < 0 ) |
---|
134 | { |
---|
135 | /* Stop updating direction */ |
---|
136 | break; |
---|
137 | } |
---|
138 | |
---|
139 | wp->n[i]--; |
---|
140 | |
---|
141 | /* Estimate our position next frames */ |
---|
142 | xnew = wp->x[i] + wp->vx[i]; |
---|
143 | ynew = wp->y[i] + wp->vy[i]; |
---|
144 | |
---|
145 | xmin = xnew; |
---|
146 | ymin = - (g->h << 4); |
---|
147 | dist = (xnew - xmin) * (xnew - xmin) |
---|
148 | + 4 * (ynew - ymin) * (ynew - ymin); |
---|
149 | |
---|
150 | /* Find the nearest alien */ |
---|
151 | for( j = 0; j < ALIENS; j++ ) |
---|
152 | { |
---|
153 | if( g->al->type[j] != ALIEN_NONE ) |
---|
154 | { |
---|
155 | int alx = g->al->x[j] << 4; |
---|
156 | int aly = g->al->y[j] << 4; |
---|
157 | int new = (xnew - alx) * (xnew - alx) |
---|
158 | + 4 * (ynew - aly) * (ynew - aly); |
---|
159 | if( new <= dist ) |
---|
160 | { |
---|
161 | dist = new; |
---|
162 | xmin = alx; |
---|
163 | ymin = aly; |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | /* Find our new direction */ |
---|
169 | dx = xmin - wp->x[i]; |
---|
170 | dy = ymin - wp->y[i]; |
---|
171 | |
---|
172 | /* Normalize direction */ |
---|
173 | if( dx | dy ) |
---|
174 | { |
---|
175 | int norm = r00t( dx * dx + 4 * dy * dy ); |
---|
176 | dx = dx * 32 / norm; |
---|
177 | dy = dy * 32 / norm; |
---|
178 | } |
---|
179 | |
---|
180 | /* Find our new speed */ |
---|
181 | dx = (dx + 3 * wp->vx[i]) / 4; |
---|
182 | dy = (dy + 3 * wp->vy[i]) / 4; |
---|
183 | |
---|
184 | /* Normalize speed */ |
---|
185 | if( dx | dy ) |
---|
186 | { |
---|
187 | int norm = r00t( dx * dx + 4 * dy * dy ); |
---|
188 | wp->vx[i] = dx * 32 / norm; |
---|
189 | wp->vy[i] = dy * 32 / norm; |
---|
190 | } |
---|
191 | |
---|
192 | break; |
---|
193 | |
---|
194 | case WEAPON_FRAGBOMB: |
---|
195 | /* If n was set to -1, the fragbomb just exploded */ |
---|
196 | if( wp->n[i] == -1 ) |
---|
197 | { |
---|
198 | int coords[] = |
---|
199 | { |
---|
200 | 32, 0, -32, 0, 0, 16, 0, -16, |
---|
201 | 28, 8, -28, 8, 28, -8, -28, -8, |
---|
202 | 24, 12, -24, 12, 24, -12, -24, -12, |
---|
203 | 16, 14, -16, 14, 16, -14, -16, -14 |
---|
204 | }; |
---|
205 | |
---|
206 | for( j = 0 ; j < sizeof(coords) / sizeof(int) ; j += 2 ) |
---|
207 | { |
---|
208 | add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1] / 2, coords[j], coords[j+1], WEAPON_SEEKER ); |
---|
209 | add_weapon( g, g->wp, wp->x[i] + coords[j] / 2, wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER ); |
---|
210 | } |
---|
211 | |
---|
212 | wp->type[i] = WEAPON_NONE; |
---|
213 | } |
---|
214 | |
---|
215 | wp->x[i] += wp->vx[i]; |
---|
216 | wp->y[i] += wp->vy[i]; |
---|
217 | wp->n[i]++; |
---|
218 | if( wp->y[i] < 0 ) |
---|
219 | { |
---|
220 | wp->type[i] = WEAPON_NONE; |
---|
221 | } |
---|
222 | break; |
---|
223 | |
---|
224 | case WEAPON_BEAM: |
---|
225 | wp->x[i] = (g->p->x + 2) << 4; |
---|
226 | wp->y[i] = g->p->y << 4; |
---|
227 | wp->n[i]--; |
---|
228 | if( wp->n[i] < 0 ) |
---|
229 | { |
---|
230 | wp->type[i] = WEAPON_NONE; |
---|
231 | } |
---|
232 | break; |
---|
233 | case WEAPON_NUKE: |
---|
234 | wp->n[i]--; |
---|
235 | if( wp->n[i] < 0 ) |
---|
236 | { |
---|
237 | wp->type[i] = WEAPON_NONE; |
---|
238 | } |
---|
239 | break; |
---|
240 | case WEAPON_LIGHTNING: |
---|
241 | case WEAPON_NONE: |
---|
242 | break; |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ) |
---|
248 | { |
---|
249 | int i; |
---|
250 | |
---|
251 | for( i = 0; i < WEAPONS; i++ ) |
---|
252 | { |
---|
253 | if( wp->type[i] == WEAPON_NONE ) |
---|
254 | { |
---|
255 | wp->x[i] = x; |
---|
256 | wp->y[i] = y; |
---|
257 | wp->vx[i] = vx; |
---|
258 | wp->vy[i] = vy; |
---|
259 | wp->type[i] = type; |
---|
260 | wp->n[i] = 0; |
---|
261 | switch( type ) |
---|
262 | { |
---|
263 | case WEAPON_LASER: |
---|
264 | break; |
---|
265 | case WEAPON_FRAGBOMB: |
---|
266 | break; |
---|
267 | case WEAPON_SEEKER: |
---|
268 | case WEAPON_BOMB: |
---|
269 | wp->x2[i] = x; |
---|
270 | wp->y2[i] = y; |
---|
271 | wp->x3[i] = x; |
---|
272 | wp->y3[i] = y; |
---|
273 | wp->n[i] = 20; |
---|
274 | break; |
---|
275 | case WEAPON_BEAM: |
---|
276 | wp->n[i] = 25; |
---|
277 | break; |
---|
278 | case WEAPON_NUKE: |
---|
279 | wp->n[i] = 25; |
---|
280 | break; |
---|
281 | case WEAPON_NONE: |
---|
282 | break; |
---|
283 | } |
---|
284 | break; |
---|
285 | } |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | static void draw_bomb( int x, int y, int vx, int vy ) |
---|
290 | { |
---|
291 | vy *= 2; |
---|
292 | gfx_color( CYAN ); |
---|
293 | |
---|
294 | if( vx > vy ) |
---|
295 | { |
---|
296 | if( vx > -vy ) /* right quarter */ |
---|
297 | { |
---|
298 | if( vy > vx/4 ) |
---|
299 | { |
---|
300 | /* -1pi/6 */ |
---|
301 | gfx_goto( x-4, y-1 ); |
---|
302 | gfx_putstr( "/`-." ); |
---|
303 | gfx_goto( x-4, y ); |
---|
304 | gfx_putstr( "`-._\\" ); |
---|
305 | gfx_color( WHITE ); |
---|
306 | gfx_goto( x-1, y ); |
---|
307 | gfx_putstr( "_\\" ); |
---|
308 | gfx_goto( x, y+1 ); |
---|
309 | gfx_putchar( '`' ); |
---|
310 | } |
---|
311 | else if( vy < -vx/4 ) |
---|
312 | { |
---|
313 | /* 1pi/6 */ |
---|
314 | gfx_goto( x-4, y ); |
---|
315 | gfx_putstr( ",-' " ); |
---|
316 | gfx_goto( x-4, y+1 ); |
---|
317 | gfx_putstr( "\\,-'" ); |
---|
318 | gfx_color( WHITE ); |
---|
319 | gfx_goto( x-1, y-1 ); |
---|
320 | gfx_putstr( "_," ); |
---|
321 | gfx_goto( x, y ); |
---|
322 | gfx_putchar( '/' ); |
---|
323 | } |
---|
324 | else |
---|
325 | { |
---|
326 | /* 0pi/6 */ |
---|
327 | gfx_goto( x-4, y-1 ); |
---|
328 | gfx_putstr( "____" ); |
---|
329 | gfx_goto( x-5, y ); |
---|
330 | gfx_putstr( "|____" ); |
---|
331 | gfx_color( WHITE ); |
---|
332 | gfx_goto( x, y ); |
---|
333 | gfx_putchar( '>' ); |
---|
334 | } |
---|
335 | } |
---|
336 | else /* top quarter */ |
---|
337 | { |
---|
338 | if( vx > -vy/4 ) |
---|
339 | { |
---|
340 | /* 2pi/6 */ |
---|
341 | gfx_goto( x-2, y ); |
---|
342 | gfx_putstr( "/ " ); |
---|
343 | gfx_goto( x-3, y+1 ); |
---|
344 | gfx_putstr( "/ /" ); |
---|
345 | gfx_goto( x-3, y+2 ); |
---|
346 | gfx_putstr( "`'" ); |
---|
347 | gfx_color( WHITE ); |
---|
348 | gfx_goto( x-1, y-1 ); |
---|
349 | gfx_putstr( "_," ); |
---|
350 | gfx_goto( x, y ); |
---|
351 | gfx_putchar( '|' ); |
---|
352 | } |
---|
353 | else if( vx < vy/4 ) |
---|
354 | { |
---|
355 | /* 4pi/6 */ |
---|
356 | gfx_goto( x+1, y ); |
---|
357 | gfx_putstr( " \\" ); |
---|
358 | gfx_goto( x+1, y+1 ); |
---|
359 | gfx_putstr( "\\ \\" ); |
---|
360 | gfx_goto( x+2, y+2 ); |
---|
361 | gfx_putstr( "`'" ); |
---|
362 | gfx_color( WHITE ); |
---|
363 | gfx_goto( x, y-1 ); |
---|
364 | gfx_putstr( "._" ); |
---|
365 | gfx_goto( x, y ); |
---|
366 | gfx_putchar( '|' ); |
---|
367 | } |
---|
368 | else |
---|
369 | { |
---|
370 | /* 3pi/6 */ |
---|
371 | gfx_goto( x-1, y+1 ); |
---|
372 | gfx_putstr( "| |" ); |
---|
373 | gfx_goto( x-1, y+2 ); |
---|
374 | gfx_putstr( "|_|" ); |
---|
375 | gfx_color( WHITE ); |
---|
376 | gfx_goto( x-1, y ); |
---|
377 | gfx_putstr( ",^." ); |
---|
378 | } |
---|
379 | } |
---|
380 | } |
---|
381 | else |
---|
382 | { |
---|
383 | if( vx > -vy ) /* bottom quarter */ |
---|
384 | { |
---|
385 | if( vx > vy/4 ) |
---|
386 | { |
---|
387 | /* -2pi/6 */ |
---|
388 | gfx_goto( x-2, y-2 ); |
---|
389 | gfx_putstr( ",." ); |
---|
390 | gfx_goto( x-2, y-1 ); |
---|
391 | gfx_putstr( "\\ \\" ); |
---|
392 | gfx_goto( x-1, y ); |
---|
393 | gfx_putchar( '\\' ); |
---|
394 | gfx_color( WHITE ); |
---|
395 | gfx_goto( x, y ); |
---|
396 | gfx_putstr( "_|" ); |
---|
397 | } |
---|
398 | else if( vx < -vy/4 ) |
---|
399 | { |
---|
400 | /* -4pi/6 */ |
---|
401 | gfx_goto( x+1, y-2 ); |
---|
402 | gfx_putstr( ",." ); |
---|
403 | gfx_goto( x, y-1 ); |
---|
404 | gfx_putstr( "/ /" ); |
---|
405 | gfx_goto( x+1, y ); |
---|
406 | gfx_putchar( '/' ); |
---|
407 | gfx_color( WHITE ); |
---|
408 | gfx_goto( x-1, y ); |
---|
409 | gfx_putstr( "|_/" ); |
---|
410 | } |
---|
411 | else |
---|
412 | { |
---|
413 | /* -3pi/6 */ |
---|
414 | gfx_goto( x, y-3 ); |
---|
415 | gfx_putchar( '_' ); |
---|
416 | gfx_goto( x-1, y-2 ); |
---|
417 | gfx_putstr( "| |" ); |
---|
418 | gfx_goto( x-1, y-1 ); |
---|
419 | gfx_putstr( "| |" ); |
---|
420 | gfx_color( WHITE ); |
---|
421 | gfx_goto( x-1, y ); |
---|
422 | gfx_putstr( "`v'" ); |
---|
423 | } |
---|
424 | } |
---|
425 | else /* left quarter */ |
---|
426 | { |
---|
427 | if( vy > -vx/4 ) |
---|
428 | { |
---|
429 | /* -5pi/6 */ |
---|
430 | gfx_goto( x+1, y-1 ); |
---|
431 | gfx_putstr( ",-'\\" ); |
---|
432 | gfx_goto( x+2, y ); |
---|
433 | gfx_putstr( ",-'" ); |
---|
434 | gfx_goto( x, y+1 ); |
---|
435 | gfx_putchar( '\'' ); |
---|
436 | gfx_color( WHITE ); |
---|
437 | gfx_goto( x, y ); |
---|
438 | gfx_putstr( "/_" ); |
---|
439 | } |
---|
440 | else if( vy < vx/4 ) |
---|
441 | { |
---|
442 | /* 5pi/6 */ |
---|
443 | gfx_goto( x+1, y ); |
---|
444 | gfx_putstr( " `-." ); |
---|
445 | gfx_goto( x+1, y+1 ); |
---|
446 | gfx_putstr( "`-./" ); |
---|
447 | gfx_color( WHITE ); |
---|
448 | gfx_goto( x, y-1 ); |
---|
449 | gfx_putstr( "._" ); |
---|
450 | gfx_goto( x, y ); |
---|
451 | gfx_putchar( '\\' ); |
---|
452 | } |
---|
453 | else |
---|
454 | { |
---|
455 | /* 6pi/6 */ |
---|
456 | gfx_goto( x+1, y-1 ); |
---|
457 | gfx_putstr( "____" ); |
---|
458 | gfx_goto( x+1, y ); |
---|
459 | gfx_putstr( "____|" ); |
---|
460 | gfx_color( WHITE ); |
---|
461 | gfx_goto( x, y ); |
---|
462 | gfx_putchar( '<' ); |
---|
463 | } |
---|
464 | } |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | static void draw_fragbomb( int x, int y, int frame ) |
---|
469 | { |
---|
470 | gfx_color( WHITE ); |
---|
471 | |
---|
472 | gfx_color( frame & 1 ? CYAN : WHITE ); |
---|
473 | gfx_goto( x-2, y ); |
---|
474 | gfx_putstr( "( )" ); |
---|
475 | gfx_goto( x-1, y+1 ); |
---|
476 | gfx_putstr( "`--'" ); |
---|
477 | |
---|
478 | gfx_color( frame & 1 ? WHITE : CYAN ); |
---|
479 | gfx_goto( x-1, y-1 ); |
---|
480 | gfx_putstr( ",--." ); |
---|
481 | gfx_goto( x, y ); |
---|
482 | gfx_putstr( "'," ); |
---|
483 | |
---|
484 | switch( frame % 4 ) |
---|
485 | { |
---|
486 | case 0: |
---|
487 | gfx_color( CYAN ); |
---|
488 | gfx_goto( x, y + 2 ); |
---|
489 | gfx_putchar( 'O' ); |
---|
490 | gfx_goto( x + 2, y + 2 ); |
---|
491 | gfx_putchar( 'o' ); |
---|
492 | gfx_goto( x + 1, y + 3 ); |
---|
493 | gfx_putchar( 'o' ); |
---|
494 | gfx_color( GRAY ); |
---|
495 | gfx_goto( x - 1, y + 3 ); |
---|
496 | gfx_putchar( ':' ); |
---|
497 | gfx_goto( x + 2, y + 4 ); |
---|
498 | gfx_putchar( ':' ); |
---|
499 | gfx_goto( x, y + 4 ); |
---|
500 | gfx_putchar( '.' ); |
---|
501 | gfx_goto( x + 1, y + 5 ); |
---|
502 | gfx_putchar( '.' ); |
---|
503 | break; |
---|
504 | case 1: |
---|
505 | gfx_color( CYAN ); |
---|
506 | //gfx_goto( x, y + 1 ); |
---|
507 | //gfx_putchar( 'O' ); |
---|
508 | gfx_goto( x + 1, y + 2 ); |
---|
509 | gfx_putchar( 'O' ); |
---|
510 | gfx_goto( x, y + 3 ); |
---|
511 | gfx_putchar( 'o' ); |
---|
512 | gfx_color( GRAY ); |
---|
513 | gfx_goto( x + 2, y + 3 ); |
---|
514 | gfx_putchar( ':' ); |
---|
515 | gfx_goto( x + 1, y + 4 ); |
---|
516 | gfx_putchar( ':' ); |
---|
517 | gfx_goto( x - 1, y + 4 ); |
---|
518 | gfx_putchar( '.' ); |
---|
519 | gfx_goto( x + 2, y + 5 ); |
---|
520 | gfx_putchar( '.' ); |
---|
521 | break; |
---|
522 | case 2: |
---|
523 | gfx_color( CYAN ); |
---|
524 | //gfx_goto( x - 1, y + 1 ); |
---|
525 | //gfx_putchar( 'O' ); |
---|
526 | gfx_goto( x + 2, y + 2 ); |
---|
527 | gfx_putchar( 'O' ); |
---|
528 | gfx_goto( x, y + 2 ); |
---|
529 | gfx_putchar( 'o' ); |
---|
530 | gfx_goto( x + 1, y + 3 ); |
---|
531 | gfx_putchar( 'o' ); |
---|
532 | gfx_color( GRAY ); |
---|
533 | gfx_goto( x, y + 4 ); |
---|
534 | gfx_putchar( ':' ); |
---|
535 | gfx_goto( x + 2, y + 4 ); |
---|
536 | gfx_putchar( '.' ); |
---|
537 | gfx_goto( x + 1, y + 5 ); |
---|
538 | gfx_putchar( '.' ); |
---|
539 | break; |
---|
540 | case 3: |
---|
541 | gfx_color( CYAN ); |
---|
542 | //gfx_goto( x + 2, y + 1 ); |
---|
543 | //gfx_putchar( 'O' ); |
---|
544 | gfx_goto( x + 1, y + 2 ); |
---|
545 | gfx_putchar( 'O' ); |
---|
546 | gfx_goto( x - 1, y + 2 ); |
---|
547 | gfx_putchar( 'o' ); |
---|
548 | gfx_goto( x + 2, y + 3 ); |
---|
549 | gfx_putchar( 'o' ); |
---|
550 | gfx_color( GRAY ); |
---|
551 | gfx_goto( x, y + 3 ); |
---|
552 | gfx_putchar( ':' ); |
---|
553 | gfx_goto( x + 1, y + 4 ); |
---|
554 | gfx_putchar( ':' ); |
---|
555 | gfx_goto( x, y + 5 ); |
---|
556 | gfx_putchar( '.' ); |
---|
557 | break; |
---|
558 | } |
---|
559 | } |
---|
560 | |
---|
561 | static void draw_beam( int x, int y, int frame ) |
---|
562 | { |
---|
563 | int r = (29 - frame) * (29 - frame) / 8; |
---|
564 | int i; |
---|
565 | |
---|
566 | switch( frame ) |
---|
567 | { |
---|
568 | case 24: |
---|
569 | gfx_color( WHITE ); |
---|
570 | gfx_goto( x, y-3 ); |
---|
571 | gfx_putstr( "__" ); |
---|
572 | gfx_goto( x-1, y-2 ); |
---|
573 | gfx_putchar( '\'' ); |
---|
574 | gfx_goto( x+2, y-2 ); |
---|
575 | gfx_putchar( '`' ); |
---|
576 | break; |
---|
577 | case 23: |
---|
578 | gfx_color( CYAN ); |
---|
579 | gfx_goto( x, y-3 ); |
---|
580 | gfx_putstr( "__" ); |
---|
581 | gfx_color( WHITE ); |
---|
582 | gfx_goto( x-2, y-2 ); |
---|
583 | gfx_putstr( "-'" ); |
---|
584 | gfx_goto( x+2, y-2 ); |
---|
585 | gfx_putstr( "`-" ); |
---|
586 | break; |
---|
587 | case 22: |
---|
588 | gfx_color( CYAN ); |
---|
589 | gfx_goto( x, y-3 ); |
---|
590 | gfx_putstr( "__" ); |
---|
591 | gfx_goto( x-1, y-2 ); |
---|
592 | gfx_putchar( '\'' ); |
---|
593 | gfx_goto( x+2, y-2 ); |
---|
594 | gfx_putchar( '`' ); |
---|
595 | gfx_color( WHITE ); |
---|
596 | gfx_goto( x-3, y-2 ); |
---|
597 | gfx_putstr( ",-" ); |
---|
598 | gfx_goto( x+3, y-2 ); |
---|
599 | gfx_putstr( "-." ); |
---|
600 | break; |
---|
601 | case 21: |
---|
602 | gfx_color( CYAN ); |
---|
603 | gfx_goto( x-1, y-3 ); |
---|
604 | gfx_putstr( "____" ); |
---|
605 | gfx_goto( x-2, y-2 ); |
---|
606 | gfx_putchar( '\'' ); |
---|
607 | gfx_goto( x+3, y-2 ); |
---|
608 | gfx_putchar( '`' ); |
---|
609 | gfx_color( WHITE ); |
---|
610 | gfx_goto( x-4, y-2 ); |
---|
611 | gfx_putstr( ",-" ); |
---|
612 | gfx_goto( x+4, y-2 ); |
---|
613 | gfx_putstr( "-." ); |
---|
614 | break; |
---|
615 | case 20: |
---|
616 | gfx_color( WHITE ); |
---|
617 | gfx_goto( x, y-3 ); |
---|
618 | gfx_putstr( "%%" ); |
---|
619 | gfx_goto( x-4, y-2 ); |
---|
620 | gfx_putchar( ',' ); |
---|
621 | gfx_goto( x+5, y-2 ); |
---|
622 | gfx_putchar( '.' ); |
---|
623 | gfx_color( CYAN ); |
---|
624 | gfx_goto( x-1, y-3 ); |
---|
625 | gfx_putchar( ':' ); |
---|
626 | gfx_goto( x+2, y-3 ); |
---|
627 | gfx_putchar( ':' ); |
---|
628 | gfx_goto( x-3, y-2 ); |
---|
629 | gfx_putstr( "-'" ); |
---|
630 | gfx_goto( x+3, y-2 ); |
---|
631 | gfx_putstr( "`-" ); |
---|
632 | break; |
---|
633 | case 19: |
---|
634 | gfx_color( WHITE ); |
---|
635 | gfx_goto( x, y-4 ); |
---|
636 | gfx_putstr( "%%" ); |
---|
637 | gfx_goto( x, y-3 ); |
---|
638 | gfx_putstr( "##" ); |
---|
639 | gfx_color( CYAN ); |
---|
640 | gfx_goto( x-1, y-4 ); |
---|
641 | gfx_putchar( ':' ); |
---|
642 | gfx_goto( x+2, y-4 ); |
---|
643 | gfx_putchar( ':' ); |
---|
644 | gfx_goto( x-1, y-3 ); |
---|
645 | gfx_putchar( '%' ); |
---|
646 | gfx_goto( x+2, y-3 ); |
---|
647 | gfx_putchar( '%' ); |
---|
648 | gfx_goto( x-4, y-2 ); |
---|
649 | gfx_putstr( ",-'" ); |
---|
650 | gfx_goto( x+3, y-2 ); |
---|
651 | gfx_putstr( "`-." ); |
---|
652 | gfx_color( BLUE ); |
---|
653 | gfx_goto( x-2, y-3 ); |
---|
654 | gfx_putchar( ':' ); |
---|
655 | gfx_goto( x+3, y-3 ); |
---|
656 | gfx_putchar( ':' ); |
---|
657 | break; |
---|
658 | case 18: |
---|
659 | default: |
---|
660 | r = (18 - frame) * (18 - frame); |
---|
661 | gfx_color( WHITE ); |
---|
662 | gfx_goto( x-1, y-5-r ); |
---|
663 | gfx_putstr( ":%%:" ); |
---|
664 | gfx_goto( x-1, y-4-r ); |
---|
665 | gfx_putstr( "%##%" ); |
---|
666 | gfx_color( CYAN ); |
---|
667 | gfx_goto( x-2, y-4-r ); |
---|
668 | gfx_putchar( ':' ); |
---|
669 | gfx_goto( x+3, y-4-r ); |
---|
670 | gfx_putchar( ':' ); |
---|
671 | gfx_goto( x-2, y-2 ); |
---|
672 | gfx_putchar( '\'' ); |
---|
673 | gfx_goto( x+3, y-2 ); |
---|
674 | gfx_putchar( '`' ); |
---|
675 | gfx_color( BLUE ); |
---|
676 | gfx_goto( x-3, y-2 ); |
---|
677 | gfx_putchar( ':' ); |
---|
678 | gfx_goto( x+4, y-2 ); |
---|
679 | gfx_putchar( ':' ); |
---|
680 | for( i = 0; i <= r; i++ ) |
---|
681 | { |
---|
682 | gfx_color( WHITE ); |
---|
683 | gfx_goto( x-1, y-3-i ); |
---|
684 | gfx_putstr( (i+frame) % 5 ? "####" : "%%%%" ); |
---|
685 | gfx_color( CYAN ); |
---|
686 | gfx_goto( x-2, y-3-i ); |
---|
687 | gfx_putchar( '%' ); |
---|
688 | gfx_goto( x+3, y-3-i ); |
---|
689 | gfx_putchar( '%' ); |
---|
690 | gfx_color( BLUE ); |
---|
691 | gfx_goto( x-3, y-3-i ); |
---|
692 | gfx_putchar( ':' ); |
---|
693 | gfx_goto( x+4, y-3-i ); |
---|
694 | gfx_putchar( ':' ); |
---|
695 | } |
---|
696 | break; |
---|
697 | } |
---|
698 | } |
---|
699 | |
---|
700 | static void draw_nuke( int x, int y, int frame ) |
---|
701 | { |
---|
702 | int r = (29 - frame) * (29 - frame) / 8; |
---|
703 | |
---|
704 | /* Lots of duplicate pixels, but we don't care */ |
---|
705 | gfx_color( BLUE ); |
---|
706 | draw_circle( x, y, r++, ':' ); |
---|
707 | gfx_color( CYAN ); |
---|
708 | draw_circle( x, y, r++, '%' ); |
---|
709 | gfx_color( WHITE ); |
---|
710 | draw_circle( x, y, r++, '#' ); |
---|
711 | draw_circle( x, y, r++, '#' ); |
---|
712 | } |
---|
713 | |
---|
714 | static void draw_circle( int x, int y, int r, char c ) |
---|
715 | { |
---|
716 | int test, dx, dy; |
---|
717 | |
---|
718 | /* Optimized Bresenham. Kick ass. */ |
---|
719 | for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++ ) |
---|
720 | { |
---|
721 | gfx_putcharTO( x + dx, y + dy / 2, c ); |
---|
722 | gfx_putcharTO( x - dx, y + dy / 2, c ); |
---|
723 | gfx_putcharTO( x + dx, y - dy / 2, c ); |
---|
724 | gfx_putcharTO( x - dx, y - dy / 2, c ); |
---|
725 | |
---|
726 | gfx_putcharTO( x + dy, y + dx / 2, c ); |
---|
727 | gfx_putcharTO( x - dy, y + dx / 2, c ); |
---|
728 | gfx_putcharTO( x + dy, y - dx / 2, c ); |
---|
729 | gfx_putcharTO( x - dy, y - dx / 2, c ); |
---|
730 | |
---|
731 | test += test > 0 ? dx - dy-- : dx; |
---|
732 | } |
---|
733 | } |
---|
734 | |
---|