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,v 1.9 2002/12/22 22:36:42 sam Exp $ |
---|
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 in 2 frames */ |
---|
142 | xnew = wp->x[i] + 4 * wp->vx[i]; |
---|
143 | ynew = wp->y[i] + 4 * 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 and update speed */ |
---|
173 | wp->vx[i] = (7 * wp->vx[i] |
---|
174 | + (dx * 48) / r00t(dx*dx+dy*dy) ) / 8; |
---|
175 | wp->vy[i] = (7 * wp->vy[i] |
---|
176 | + (dy * 24) / r00t(dx*dx+dy*dy) ) / 8; |
---|
177 | |
---|
178 | break; |
---|
179 | case WEAPON_FRAGBOMB: |
---|
180 | /* If n was set to -1, the fragbomb exploded */ |
---|
181 | if( wp->n[i] == -1 ) |
---|
182 | { |
---|
183 | add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i], 24, 0, WEAPON_SEEKER ); |
---|
184 | add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i], -24, 0, WEAPON_SEEKER ); |
---|
185 | add_weapon( g, g->wp, wp->x[i], wp->y[i] + 24, 0, 24, WEAPON_SEEKER ); |
---|
186 | add_weapon( g, g->wp, wp->x[i], wp->y[i] - 24, 0, -24, WEAPON_SEEKER ); |
---|
187 | add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] + 8, 24, 8, WEAPON_SEEKER ); |
---|
188 | add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] + 8, -24, 8, WEAPON_SEEKER ); |
---|
189 | add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] - 8, 24, -8, WEAPON_SEEKER ); |
---|
190 | add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] - 8, -24, -8, WEAPON_SEEKER ); |
---|
191 | add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] + 16, 16, 16, WEAPON_SEEKER ); |
---|
192 | add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] + 16, -16, 16, WEAPON_SEEKER ); |
---|
193 | add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] - 16, 16, -16, WEAPON_SEEKER ); |
---|
194 | add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] - 16, -16, -16, WEAPON_SEEKER ); |
---|
195 | wp->type[i] = WEAPON_NONE; |
---|
196 | } |
---|
197 | |
---|
198 | wp->x[i] += wp->vx[i]; |
---|
199 | wp->y[i] += wp->vy[i]; |
---|
200 | wp->n[i]++; |
---|
201 | if( wp->y[i] < 0 ) |
---|
202 | { |
---|
203 | wp->type[i] = WEAPON_NONE; |
---|
204 | } |
---|
205 | break; |
---|
206 | case WEAPON_BEAM: |
---|
207 | wp->x[i] = (g->p->x + 2) << 4; |
---|
208 | wp->y[i] = g->p->y << 4; |
---|
209 | wp->n[i]--; |
---|
210 | if( wp->n[i] < 0 ) |
---|
211 | { |
---|
212 | wp->type[i] = WEAPON_NONE; |
---|
213 | } |
---|
214 | break; |
---|
215 | case WEAPON_NUKE: |
---|
216 | wp->n[i]--; |
---|
217 | if( wp->n[i] < 0 ) |
---|
218 | { |
---|
219 | wp->type[i] = WEAPON_NONE; |
---|
220 | } |
---|
221 | break; |
---|
222 | case WEAPON_LIGHTNING: |
---|
223 | case WEAPON_NONE: |
---|
224 | break; |
---|
225 | } |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ) |
---|
230 | { |
---|
231 | int i; |
---|
232 | |
---|
233 | for( i = 0; i < WEAPONS; i++ ) |
---|
234 | { |
---|
235 | if( wp->type[i] == WEAPON_NONE ) |
---|
236 | { |
---|
237 | wp->x[i] = x; |
---|
238 | wp->y[i] = y; |
---|
239 | wp->vx[i] = vx; |
---|
240 | wp->vy[i] = vy; |
---|
241 | wp->type[i] = type; |
---|
242 | wp->n[i] = 0; |
---|
243 | switch( type ) |
---|
244 | { |
---|
245 | case WEAPON_LASER: |
---|
246 | break; |
---|
247 | case WEAPON_FRAGBOMB: |
---|
248 | break; |
---|
249 | case WEAPON_SEEKER: |
---|
250 | case WEAPON_BOMB: |
---|
251 | wp->x2[i] = x; |
---|
252 | wp->y2[i] = y; |
---|
253 | wp->x3[i] = x; |
---|
254 | wp->y3[i] = y; |
---|
255 | wp->n[i] = 20; |
---|
256 | break; |
---|
257 | case WEAPON_BEAM: |
---|
258 | wp->n[i] = 25; |
---|
259 | break; |
---|
260 | case WEAPON_NUKE: |
---|
261 | wp->n[i] = 25; |
---|
262 | break; |
---|
263 | case WEAPON_NONE: |
---|
264 | break; |
---|
265 | } |
---|
266 | break; |
---|
267 | } |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | static void draw_bomb( int x, int y, int vx, int vy ) |
---|
272 | { |
---|
273 | vy *= 2; |
---|
274 | gfx_color( CYAN ); |
---|
275 | |
---|
276 | if( vx > vy ) |
---|
277 | { |
---|
278 | if( vx > -vy ) /* right quarter */ |
---|
279 | { |
---|
280 | if( vy > vx/4 ) |
---|
281 | { |
---|
282 | /* -1pi/6 */ |
---|
283 | gfx_goto( x-4, y-1 ); |
---|
284 | gfx_putstr( "/`-." ); |
---|
285 | gfx_goto( x-4, y ); |
---|
286 | gfx_putstr( "`-._\\" ); |
---|
287 | gfx_color( WHITE ); |
---|
288 | gfx_goto( x-1, y ); |
---|
289 | gfx_putstr( "_\\" ); |
---|
290 | gfx_goto( x, y+1 ); |
---|
291 | gfx_putchar( '`' ); |
---|
292 | } |
---|
293 | else if( vy < -vx/4 ) |
---|
294 | { |
---|
295 | /* 1pi/6 */ |
---|
296 | gfx_goto( x-4, y ); |
---|
297 | gfx_putstr( ",-' " ); |
---|
298 | gfx_goto( x-4, y+1 ); |
---|
299 | gfx_putstr( "\\,-'" ); |
---|
300 | gfx_color( WHITE ); |
---|
301 | gfx_goto( x-1, y-1 ); |
---|
302 | gfx_putstr( "_," ); |
---|
303 | gfx_goto( x, y ); |
---|
304 | gfx_putchar( '/' ); |
---|
305 | } |
---|
306 | else |
---|
307 | { |
---|
308 | /* 0pi/6 */ |
---|
309 | gfx_goto( x-4, y-1 ); |
---|
310 | gfx_putstr( "____" ); |
---|
311 | gfx_goto( x-5, y ); |
---|
312 | gfx_putstr( "|____" ); |
---|
313 | gfx_color( WHITE ); |
---|
314 | gfx_goto( x, y ); |
---|
315 | gfx_putchar( '>' ); |
---|
316 | } |
---|
317 | } |
---|
318 | else /* top quarter */ |
---|
319 | { |
---|
320 | if( vx > -vy/4 ) |
---|
321 | { |
---|
322 | /* 2pi/6 */ |
---|
323 | gfx_goto( x-2, y ); |
---|
324 | gfx_putstr( "/ " ); |
---|
325 | gfx_goto( x-3, y+1 ); |
---|
326 | gfx_putstr( "/ /" ); |
---|
327 | gfx_goto( x-3, y+2 ); |
---|
328 | gfx_putstr( "`'" ); |
---|
329 | gfx_color( WHITE ); |
---|
330 | gfx_goto( x-1, y-1 ); |
---|
331 | gfx_putstr( "_," ); |
---|
332 | gfx_goto( x, y ); |
---|
333 | gfx_putchar( '|' ); |
---|
334 | } |
---|
335 | else if( vx < vy/4 ) |
---|
336 | { |
---|
337 | /* 4pi/6 */ |
---|
338 | gfx_goto( x+1, y ); |
---|
339 | gfx_putstr( " \\" ); |
---|
340 | gfx_goto( x+1, y+1 ); |
---|
341 | gfx_putstr( "\\ \\" ); |
---|
342 | gfx_goto( x+2, y+2 ); |
---|
343 | gfx_putstr( "`'" ); |
---|
344 | gfx_color( WHITE ); |
---|
345 | gfx_goto( x, y-1 ); |
---|
346 | gfx_putstr( "._" ); |
---|
347 | gfx_goto( x, y ); |
---|
348 | gfx_putchar( '|' ); |
---|
349 | } |
---|
350 | else |
---|
351 | { |
---|
352 | /* 3pi/6 */ |
---|
353 | gfx_goto( x-1, y+1 ); |
---|
354 | gfx_putstr( "| |" ); |
---|
355 | gfx_goto( x-1, y+2 ); |
---|
356 | gfx_putstr( "|_|" ); |
---|
357 | gfx_color( WHITE ); |
---|
358 | gfx_goto( x-1, y ); |
---|
359 | gfx_putstr( ",^." ); |
---|
360 | } |
---|
361 | } |
---|
362 | } |
---|
363 | else |
---|
364 | { |
---|
365 | if( vx > -vy ) /* bottom quarter */ |
---|
366 | { |
---|
367 | if( vx > vy/4 ) |
---|
368 | { |
---|
369 | /* -2pi/6 */ |
---|
370 | gfx_goto( x-2, y-2 ); |
---|
371 | gfx_putstr( ",." ); |
---|
372 | gfx_goto( x-2, y-1 ); |
---|
373 | gfx_putstr( "\\ \\" ); |
---|
374 | gfx_goto( x-1, y ); |
---|
375 | gfx_putchar( '\\' ); |
---|
376 | gfx_color( WHITE ); |
---|
377 | gfx_goto( x, y ); |
---|
378 | gfx_putstr( "_|" ); |
---|
379 | } |
---|
380 | else if( vx < -vy/4 ) |
---|
381 | { |
---|
382 | /* -4pi/6 */ |
---|
383 | gfx_goto( x+1, y-2 ); |
---|
384 | gfx_putstr( ",." ); |
---|
385 | gfx_goto( x, y-1 ); |
---|
386 | gfx_putstr( "/ /" ); |
---|
387 | gfx_goto( x+1, y ); |
---|
388 | gfx_putchar( '/' ); |
---|
389 | gfx_color( WHITE ); |
---|
390 | gfx_goto( x-1, y ); |
---|
391 | gfx_putstr( "|_/" ); |
---|
392 | } |
---|
393 | else |
---|
394 | { |
---|
395 | /* -3pi/6 */ |
---|
396 | gfx_goto( x, y-3 ); |
---|
397 | gfx_putchar( '_' ); |
---|
398 | gfx_goto( x-1, y-2 ); |
---|
399 | gfx_putstr( "| |" ); |
---|
400 | gfx_goto( x-1, y-1 ); |
---|
401 | gfx_putstr( "| |" ); |
---|
402 | gfx_color( WHITE ); |
---|
403 | gfx_goto( x-1, y ); |
---|
404 | gfx_putstr( "`v'" ); |
---|
405 | } |
---|
406 | } |
---|
407 | else /* left quarter */ |
---|
408 | { |
---|
409 | if( vy > -vx/4 ) |
---|
410 | { |
---|
411 | /* -5pi/6 */ |
---|
412 | gfx_goto( x+1, y-1 ); |
---|
413 | gfx_putstr( ",-'\\" ); |
---|
414 | gfx_goto( x+2, y ); |
---|
415 | gfx_putstr( ",-'" ); |
---|
416 | gfx_goto( x, y+1 ); |
---|
417 | gfx_putchar( '\'' ); |
---|
418 | gfx_color( WHITE ); |
---|
419 | gfx_goto( x, y ); |
---|
420 | gfx_putstr( "/_" ); |
---|
421 | } |
---|
422 | else if( vy < vx/4 ) |
---|
423 | { |
---|
424 | /* 5pi/6 */ |
---|
425 | gfx_goto( x+1, y ); |
---|
426 | gfx_putstr( " `-." ); |
---|
427 | gfx_goto( x+1, y+1 ); |
---|
428 | gfx_putstr( "`-./" ); |
---|
429 | gfx_color( WHITE ); |
---|
430 | gfx_goto( x, y-1 ); |
---|
431 | gfx_putstr( "._" ); |
---|
432 | gfx_goto( x, y ); |
---|
433 | gfx_putchar( '\\' ); |
---|
434 | } |
---|
435 | else |
---|
436 | { |
---|
437 | /* 6pi/6 */ |
---|
438 | gfx_goto( x+1, y-1 ); |
---|
439 | gfx_putstr( "____" ); |
---|
440 | gfx_goto( x+1, y ); |
---|
441 | gfx_putstr( "____|" ); |
---|
442 | gfx_color( WHITE ); |
---|
443 | gfx_goto( x, y ); |
---|
444 | gfx_putchar( '<' ); |
---|
445 | } |
---|
446 | } |
---|
447 | } |
---|
448 | } |
---|
449 | |
---|
450 | static void draw_fragbomb( int x, int y, int frame ) |
---|
451 | { |
---|
452 | gfx_color( WHITE ); |
---|
453 | |
---|
454 | gfx_color( frame & 1 ? CYAN : WHITE ); |
---|
455 | gfx_goto( x-2, y ); |
---|
456 | gfx_putstr( "( )" ); |
---|
457 | gfx_goto( x-1, y+1 ); |
---|
458 | gfx_putstr( "`--'" ); |
---|
459 | |
---|
460 | gfx_color( frame & 1 ? WHITE : CYAN ); |
---|
461 | gfx_goto( x-1, y-1 ); |
---|
462 | gfx_putstr( ",--." ); |
---|
463 | gfx_goto( x, y ); |
---|
464 | gfx_putstr( "'," ); |
---|
465 | |
---|
466 | switch( frame % 4 ) |
---|
467 | { |
---|
468 | case 0: |
---|
469 | gfx_color( CYAN ); |
---|
470 | gfx_goto( x, y + 2 ); |
---|
471 | gfx_putchar( 'O' ); |
---|
472 | gfx_goto( x + 2, y + 2 ); |
---|
473 | gfx_putchar( 'o' ); |
---|
474 | gfx_goto( x + 1, y + 3 ); |
---|
475 | gfx_putchar( 'o' ); |
---|
476 | gfx_color( GRAY ); |
---|
477 | gfx_goto( x - 1, y + 3 ); |
---|
478 | gfx_putchar( '°' ); |
---|
479 | gfx_goto( x + 2, y + 4 ); |
---|
480 | gfx_putchar( '°' ); |
---|
481 | gfx_goto( x, y + 4 ); |
---|
482 | gfx_putchar( '.' ); |
---|
483 | gfx_goto( x + 1, y + 5 ); |
---|
484 | gfx_putchar( '.' ); |
---|
485 | break; |
---|
486 | case 1: |
---|
487 | gfx_color( CYAN ); |
---|
488 | //gfx_goto( x, y + 1 ); |
---|
489 | //gfx_putchar( 'O' ); |
---|
490 | gfx_goto( x + 1, y + 2 ); |
---|
491 | gfx_putchar( 'O' ); |
---|
492 | gfx_goto( x, y + 3 ); |
---|
493 | gfx_putchar( 'o' ); |
---|
494 | gfx_color( GRAY ); |
---|
495 | gfx_goto( x + 2, y + 3 ); |
---|
496 | gfx_putchar( '°' ); |
---|
497 | gfx_goto( x + 1, y + 4 ); |
---|
498 | gfx_putchar( '°' ); |
---|
499 | gfx_goto( x - 1, y + 4 ); |
---|
500 | gfx_putchar( '.' ); |
---|
501 | gfx_goto( x + 2, y + 5 ); |
---|
502 | gfx_putchar( '.' ); |
---|
503 | break; |
---|
504 | case 2: |
---|
505 | gfx_color( CYAN ); |
---|
506 | //gfx_goto( x - 1, y + 1 ); |
---|
507 | //gfx_putchar( 'O' ); |
---|
508 | gfx_goto( x + 2, y + 2 ); |
---|
509 | gfx_putchar( 'O' ); |
---|
510 | gfx_goto( x, y + 2 ); |
---|
511 | gfx_putchar( 'o' ); |
---|
512 | gfx_goto( x + 1, y + 3 ); |
---|
513 | gfx_putchar( 'o' ); |
---|
514 | gfx_color( GRAY ); |
---|
515 | gfx_goto( x, y + 4 ); |
---|
516 | gfx_putchar( '°' ); |
---|
517 | gfx_goto( x + 2, y + 4 ); |
---|
518 | gfx_putchar( '.' ); |
---|
519 | gfx_goto( x + 1, y + 5 ); |
---|
520 | gfx_putchar( '.' ); |
---|
521 | break; |
---|
522 | case 3: |
---|
523 | gfx_color( CYAN ); |
---|
524 | //gfx_goto( x + 2, y + 1 ); |
---|
525 | //gfx_putchar( 'O' ); |
---|
526 | gfx_goto( x + 1, y + 2 ); |
---|
527 | gfx_putchar( 'O' ); |
---|
528 | gfx_goto( x - 1, y + 2 ); |
---|
529 | gfx_putchar( 'o' ); |
---|
530 | gfx_goto( x + 2, y + 3 ); |
---|
531 | gfx_putchar( 'o' ); |
---|
532 | gfx_color( GRAY ); |
---|
533 | gfx_goto( x, y + 3 ); |
---|
534 | gfx_putchar( '°' ); |
---|
535 | gfx_goto( x + 1, y + 4 ); |
---|
536 | gfx_putchar( '°' ); |
---|
537 | gfx_goto( x, y + 5 ); |
---|
538 | gfx_putchar( '.' ); |
---|
539 | break; |
---|
540 | } |
---|
541 | } |
---|
542 | |
---|
543 | static void draw_beam( int x, int y, int frame ) |
---|
544 | { |
---|
545 | int r = (29 - frame) * (29 - frame) / 8; |
---|
546 | int i; |
---|
547 | |
---|
548 | switch( frame ) |
---|
549 | { |
---|
550 | case 24: |
---|
551 | gfx_color( WHITE ); |
---|
552 | gfx_goto( x, y-3 ); |
---|
553 | gfx_putstr( "__" ); |
---|
554 | gfx_goto( x-1, y-2 ); |
---|
555 | gfx_putchar( '\'' ); |
---|
556 | gfx_goto( x+2, y-2 ); |
---|
557 | gfx_putchar( '`' ); |
---|
558 | break; |
---|
559 | case 23: |
---|
560 | gfx_color( CYAN ); |
---|
561 | gfx_goto( x, y-3 ); |
---|
562 | gfx_putstr( "__" ); |
---|
563 | gfx_color( WHITE ); |
---|
564 | gfx_goto( x-2, y-2 ); |
---|
565 | gfx_putstr( "-'" ); |
---|
566 | gfx_goto( x+2, y-2 ); |
---|
567 | gfx_putstr( "`-" ); |
---|
568 | break; |
---|
569 | case 22: |
---|
570 | gfx_color( CYAN ); |
---|
571 | gfx_goto( x, y-3 ); |
---|
572 | gfx_putstr( "__" ); |
---|
573 | gfx_goto( x-1, y-2 ); |
---|
574 | gfx_putchar( '\'' ); |
---|
575 | gfx_goto( x+2, y-2 ); |
---|
576 | gfx_putchar( '`' ); |
---|
577 | gfx_color( WHITE ); |
---|
578 | gfx_goto( x-3, y-2 ); |
---|
579 | gfx_putstr( ",-" ); |
---|
580 | gfx_goto( x+3, y-2 ); |
---|
581 | gfx_putstr( "-." ); |
---|
582 | break; |
---|
583 | case 21: |
---|
584 | gfx_color( CYAN ); |
---|
585 | gfx_goto( x-1, y-3 ); |
---|
586 | gfx_putstr( "____" ); |
---|
587 | gfx_goto( x-2, y-2 ); |
---|
588 | gfx_putchar( '\'' ); |
---|
589 | gfx_goto( x+3, y-2 ); |
---|
590 | gfx_putchar( '`' ); |
---|
591 | gfx_color( WHITE ); |
---|
592 | gfx_goto( x-4, y-2 ); |
---|
593 | gfx_putstr( ",-" ); |
---|
594 | gfx_goto( x+4, y-2 ); |
---|
595 | gfx_putstr( "-." ); |
---|
596 | break; |
---|
597 | case 20: |
---|
598 | gfx_color( WHITE ); |
---|
599 | gfx_goto( x, y-3 ); |
---|
600 | gfx_putstr( "%%" ); |
---|
601 | gfx_goto( x-4, y-2 ); |
---|
602 | gfx_putchar( ',' ); |
---|
603 | gfx_goto( x+5, y-2 ); |
---|
604 | gfx_putchar( '.' ); |
---|
605 | gfx_color( CYAN ); |
---|
606 | gfx_goto( x-1, y-3 ); |
---|
607 | gfx_putchar( ':' ); |
---|
608 | gfx_goto( x+2, y-3 ); |
---|
609 | gfx_putchar( ':' ); |
---|
610 | gfx_goto( x-3, y-2 ); |
---|
611 | gfx_putstr( "-'" ); |
---|
612 | gfx_goto( x+3, y-2 ); |
---|
613 | gfx_putstr( "`-" ); |
---|
614 | break; |
---|
615 | case 19: |
---|
616 | gfx_color( WHITE ); |
---|
617 | gfx_goto( x, y-4 ); |
---|
618 | gfx_putstr( "%%" ); |
---|
619 | gfx_goto( x, y-3 ); |
---|
620 | gfx_putstr( "##" ); |
---|
621 | gfx_color( CYAN ); |
---|
622 | gfx_goto( x-1, y-4 ); |
---|
623 | gfx_putchar( ':' ); |
---|
624 | gfx_goto( x+2, y-4 ); |
---|
625 | gfx_putchar( ':' ); |
---|
626 | gfx_goto( x-1, y-3 ); |
---|
627 | gfx_putchar( '%' ); |
---|
628 | gfx_goto( x+2, y-3 ); |
---|
629 | gfx_putchar( '%' ); |
---|
630 | gfx_goto( x-4, y-2 ); |
---|
631 | gfx_putstr( ",-'" ); |
---|
632 | gfx_goto( x+3, y-2 ); |
---|
633 | gfx_putstr( "`-." ); |
---|
634 | gfx_color( BLUE ); |
---|
635 | gfx_goto( x-2, y-3 ); |
---|
636 | gfx_putchar( ':' ); |
---|
637 | gfx_goto( x+3, y-3 ); |
---|
638 | gfx_putchar( ':' ); |
---|
639 | break; |
---|
640 | case 18: |
---|
641 | default: |
---|
642 | r = (18 - frame) * (18 - frame); |
---|
643 | gfx_color( WHITE ); |
---|
644 | gfx_goto( x-1, y-5-r ); |
---|
645 | gfx_putstr( ":%%:" ); |
---|
646 | gfx_goto( x-1, y-4-r ); |
---|
647 | gfx_putstr( "%##%" ); |
---|
648 | gfx_color( CYAN ); |
---|
649 | gfx_goto( x-2, y-4-r ); |
---|
650 | gfx_putchar( ':' ); |
---|
651 | gfx_goto( x+3, y-4-r ); |
---|
652 | gfx_putchar( ':' ); |
---|
653 | gfx_goto( x-2, y-2 ); |
---|
654 | gfx_putchar( '\'' ); |
---|
655 | gfx_goto( x+3, y-2 ); |
---|
656 | gfx_putchar( '`' ); |
---|
657 | gfx_color( BLUE ); |
---|
658 | gfx_goto( x-3, y-2 ); |
---|
659 | gfx_putchar( ':' ); |
---|
660 | gfx_goto( x+4, y-2 ); |
---|
661 | gfx_putchar( ':' ); |
---|
662 | for( i = 0; i <= r; i++ ) |
---|
663 | { |
---|
664 | gfx_color( WHITE ); |
---|
665 | gfx_goto( x-1, y-3-i ); |
---|
666 | gfx_putstr( (i+frame) % 5 ? "####" : "%%%%" ); |
---|
667 | gfx_color( CYAN ); |
---|
668 | gfx_goto( x-2, y-3-i ); |
---|
669 | gfx_putchar( '%' ); |
---|
670 | gfx_goto( x+3, y-3-i ); |
---|
671 | gfx_putchar( '%' ); |
---|
672 | gfx_color( BLUE ); |
---|
673 | gfx_goto( x-3, y-3-i ); |
---|
674 | gfx_putchar( ':' ); |
---|
675 | gfx_goto( x+4, y-3-i ); |
---|
676 | gfx_putchar( ':' ); |
---|
677 | } |
---|
678 | break; |
---|
679 | } |
---|
680 | } |
---|
681 | |
---|
682 | static void draw_nuke( int x, int y, int frame ) |
---|
683 | { |
---|
684 | int r = (29 - frame) * (29 - frame) / 8; |
---|
685 | |
---|
686 | /* Lots of duplicate pixels, but we don't care */ |
---|
687 | gfx_color( BLUE ); |
---|
688 | draw_circle( x, y, r++, ':' ); |
---|
689 | gfx_color( CYAN ); |
---|
690 | draw_circle( x, y, r++, '%' ); |
---|
691 | gfx_color( WHITE ); |
---|
692 | draw_circle( x, y, r++, '#' ); |
---|
693 | draw_circle( x, y, r++, '#' ); |
---|
694 | } |
---|
695 | |
---|
696 | static void draw_circle( int x, int y, int r, char c ) |
---|
697 | { |
---|
698 | int test, dx, dy; |
---|
699 | |
---|
700 | /* Optimized Bresenham. Kick ass. */ |
---|
701 | for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++ ) |
---|
702 | { |
---|
703 | gfx_putcharTO( x + dx, y + dy / 2, c ); |
---|
704 | gfx_putcharTO( x - dx, y + dy / 2, c ); |
---|
705 | gfx_putcharTO( x + dx, y - dy / 2, c ); |
---|
706 | gfx_putcharTO( x - dx, y - dy / 2, c ); |
---|
707 | |
---|
708 | gfx_putcharTO( x + dy, y + dx / 2, c ); |
---|
709 | gfx_putcharTO( x - dy, y + dx / 2, c ); |
---|
710 | gfx_putcharTO( x + dy, y - dx / 2, c ); |
---|
711 | gfx_putcharTO( x - dy, y - dx / 2, c ); |
---|
712 | |
---|
713 | test += test > 0 ? dx - dy-- : dx; |
---|
714 | } |
---|
715 | } |
---|
716 | |
---|