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