1 | |
---|
2 | #include <stdlib.h> |
---|
3 | #include <math.h> |
---|
4 | |
---|
5 | #include "common.h" |
---|
6 | |
---|
7 | static void draw_small_explosion( int x, int y, int frame ); |
---|
8 | static void draw_big_explosion( int x, int y, int frame ); |
---|
9 | static void draw_huge_explosion( int x, int y, int frame ); |
---|
10 | |
---|
11 | void init_explosions( game *g, explosions *ex ) |
---|
12 | { |
---|
13 | int i; |
---|
14 | |
---|
15 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
16 | { |
---|
17 | ex->n[i] = 0; |
---|
18 | ex->x[i] = -1; |
---|
19 | ex->y[i] = -1; |
---|
20 | ex->vx[i] = -1; |
---|
21 | ex->vy[i] = -1; |
---|
22 | ex->type[i] = 0; |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ) |
---|
27 | { |
---|
28 | int i; |
---|
29 | |
---|
30 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
31 | { |
---|
32 | if( ex->n[i] <= 0 ) |
---|
33 | { |
---|
34 | ex->x[i] = x; |
---|
35 | ex->y[i] = y; |
---|
36 | ex->vx[i] = vx; |
---|
37 | ex->vy[i] = vy; |
---|
38 | switch( type ) |
---|
39 | { |
---|
40 | case 1: ex->n[i] = 13; break; |
---|
41 | case 2: ex->n[i] = 30; break; |
---|
42 | case 0: default: ex->n[i] = 7; break; |
---|
43 | } |
---|
44 | ex->type[i] = type; |
---|
45 | break; |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | void draw_explosions( game *g, explosions *ex ) |
---|
51 | { |
---|
52 | int i; |
---|
53 | |
---|
54 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
55 | { |
---|
56 | if( ex->n[i] <= 0 ) |
---|
57 | { |
---|
58 | continue; |
---|
59 | } |
---|
60 | |
---|
61 | #if 0 |
---|
62 | GFX_COLOR( GREEN ); |
---|
63 | GFX_GOTO( ex->x[i] + 3, ex->y[i] ); |
---|
64 | switch( GET_RAND(0,3) ) |
---|
65 | { |
---|
66 | case 0: |
---|
67 | GFX_WRITE( 'p' ); |
---|
68 | GFX_WRITE( 'i' ); |
---|
69 | GFX_WRITE( 'f' ); |
---|
70 | break; |
---|
71 | case 1: |
---|
72 | GFX_WRITE( 'p' ); |
---|
73 | GFX_WRITE( 'a' ); |
---|
74 | GFX_WRITE( 'f' ); |
---|
75 | break; |
---|
76 | case 2: |
---|
77 | GFX_WRITE( 'p' ); |
---|
78 | GFX_WRITE( 'o' ); |
---|
79 | GFX_WRITE( 'u' ); |
---|
80 | GFX_WRITE( 'f' ); |
---|
81 | break; |
---|
82 | } |
---|
83 | GFX_WRITE( '!' ); |
---|
84 | #endif |
---|
85 | |
---|
86 | switch( ex->type[i] ) |
---|
87 | { |
---|
88 | case 2: |
---|
89 | draw_huge_explosion( ex->x[i], ex->y[i], ex->n[i] ); |
---|
90 | break; |
---|
91 | case 1: |
---|
92 | draw_big_explosion( ex->x[i], ex->y[i], ex->n[i] ); |
---|
93 | break; |
---|
94 | case 0: |
---|
95 | default: |
---|
96 | draw_small_explosion( ex->x[i], ex->y[i], ex->n[i] ); |
---|
97 | break; |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | void update_explosions( game *g, explosions *ex ) |
---|
104 | { |
---|
105 | int i; |
---|
106 | |
---|
107 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
108 | { |
---|
109 | if( ex->n[i] > 0 ) |
---|
110 | { |
---|
111 | ex->x[i] += ex->vx[i]; |
---|
112 | ex->y[i] += ex->vy[i]; |
---|
113 | ex->n[i]--; |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | static void draw_small_explosion( int x, int y, int frame ) |
---|
119 | { |
---|
120 | switch( frame ) |
---|
121 | { |
---|
122 | default: |
---|
123 | case 6: |
---|
124 | GFX_COLOR( YELLOW ); |
---|
125 | GFX_GOTO( x, y ); |
---|
126 | GFX_WRITE( '+' ); |
---|
127 | break; |
---|
128 | case 5: |
---|
129 | GFX_COLOR( YELLOW ); |
---|
130 | GFX_GOTO( x, y ); |
---|
131 | GFX_WRITE( 'o' ); |
---|
132 | break; |
---|
133 | case 4: |
---|
134 | GFX_COLOR( YELLOW ); |
---|
135 | GFX_GOTO( x, y-1 ); |
---|
136 | GFX_WRITE( '_' ); |
---|
137 | GFX_GOTO( x-1, y ); |
---|
138 | GFX_WRITE( ')' ); |
---|
139 | GFX_WRITE( '_' ); |
---|
140 | GFX_WRITE( '(' ); |
---|
141 | break; |
---|
142 | case 3: |
---|
143 | GFX_COLOR( YELLOW ); |
---|
144 | GFX_GOTO( x-1, y-1 ); |
---|
145 | GFX_WRITE( '.' ); |
---|
146 | GFX_WRITE( '_' ); |
---|
147 | GFX_WRITE( ',' ); |
---|
148 | GFX_GOTO( x-1, y ); |
---|
149 | GFX_WRITE( ')' ); |
---|
150 | GFX_WRITE( '_' ); |
---|
151 | GFX_WRITE( '(' ); |
---|
152 | GFX_GOTO( x-1, y+1 ); |
---|
153 | GFX_WRITE( '\'' ); |
---|
154 | GFX_WRITE( ' ' ); |
---|
155 | GFX_WRITE( '`' ); |
---|
156 | break; |
---|
157 | case 2: |
---|
158 | GFX_COLOR( YELLOW ); |
---|
159 | GFX_GOTO( x-1, y-1 ); |
---|
160 | GFX_WRITE( '.' ); |
---|
161 | GFX_WRITE( 'v' ); |
---|
162 | GFX_WRITE( ',' ); |
---|
163 | GFX_GOTO( x-1, y ); |
---|
164 | GFX_WRITE( '>' ); |
---|
165 | GFX_WRITE( ' ' ); |
---|
166 | GFX_WRITE( '<' ); |
---|
167 | GFX_GOTO( x-1, y+1 ); |
---|
168 | GFX_WRITE( '\'' ); |
---|
169 | GFX_WRITE( '^' ); |
---|
170 | GFX_WRITE( '`' ); |
---|
171 | break; |
---|
172 | case 1: |
---|
173 | GFX_COLOR( WHITE ); |
---|
174 | GFX_GOTO( x-1, y-1 ); |
---|
175 | GFX_WRITE( '.' ); |
---|
176 | GFX_WRITE( ' ' ); |
---|
177 | GFX_WRITE( ',' ); |
---|
178 | GFX_GOTO( x-1, y ); |
---|
179 | GFX_WRITE( ' ' ); |
---|
180 | GFX_WRITE( ' ' ); |
---|
181 | GFX_WRITE( ' ' ); |
---|
182 | GFX_GOTO( x-1, y+1 ); |
---|
183 | GFX_WRITE( '\'' ); |
---|
184 | GFX_WRITE( ' ' ); |
---|
185 | GFX_WRITE( '`' ); |
---|
186 | break; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | static void draw_big_explosion( int x, int y, int frame ) |
---|
191 | { |
---|
192 | GFX_COLOR( YELLOW ); |
---|
193 | |
---|
194 | switch( frame ) |
---|
195 | { |
---|
196 | default: |
---|
197 | case 12: |
---|
198 | GFX_GOTO( x, y ); |
---|
199 | GFX_WRITE( '+' ); |
---|
200 | break; |
---|
201 | case 11: |
---|
202 | GFX_GOTO( x, y ); |
---|
203 | GFX_WRITE( 'o' ); |
---|
204 | break; |
---|
205 | case 10: |
---|
206 | GFX_GOTO( x, y-1 ); |
---|
207 | GFX_WRITE( '_' ); |
---|
208 | GFX_GOTO( x-1, y ); |
---|
209 | GFX_WRITE( ')' ); |
---|
210 | GFX_WRITE( '_' ); |
---|
211 | GFX_WRITE( '(' ); |
---|
212 | break; |
---|
213 | case 9: |
---|
214 | GFX_GOTO( x-1, y-1 ); |
---|
215 | GFX_WRITE( '.' ); |
---|
216 | GFX_WRITE( '_' ); |
---|
217 | GFX_WRITE( ',' ); |
---|
218 | GFX_GOTO( x-1, y ); |
---|
219 | GFX_WRITE( ')' ); |
---|
220 | GFX_WRITE( '_' ); |
---|
221 | GFX_WRITE( '(' ); |
---|
222 | GFX_GOTO( x-1, y+1 ); |
---|
223 | GFX_WRITE( '\'' ); |
---|
224 | GFX_WRITE( ' ' ); |
---|
225 | GFX_WRITE( '`' ); |
---|
226 | break; |
---|
227 | case 8: |
---|
228 | GFX_GOTO( x-1, y-1 ); |
---|
229 | GFX_WRITE( '.' ); |
---|
230 | GFX_WRITE( 'v' ); |
---|
231 | GFX_WRITE( ',' ); |
---|
232 | GFX_GOTO( x-1, y ); |
---|
233 | GFX_WRITE( '>' ); |
---|
234 | GFX_WRITE( ' ' ); |
---|
235 | GFX_WRITE( '<' ); |
---|
236 | GFX_GOTO( x-1, y+1 ); |
---|
237 | GFX_WRITE( '\'' ); |
---|
238 | GFX_WRITE( '^' ); |
---|
239 | GFX_WRITE( '`' ); |
---|
240 | break; |
---|
241 | case 6: |
---|
242 | GFX_COLOR( RED ); |
---|
243 | case 7: |
---|
244 | case 5: |
---|
245 | GFX_GOTO( x-2, y-1 ); |
---|
246 | GFX_WRITE( '_' ); |
---|
247 | GFX_WRITE( '\\' ); |
---|
248 | GFX_WRITE( '~' ); |
---|
249 | GFX_WRITE( '/' ); |
---|
250 | GFX_WRITE( '_' ); |
---|
251 | GFX_GOTO( x-2, y ); |
---|
252 | GFX_WRITE( '>' ); |
---|
253 | GFX_WRITE( ' ' ); |
---|
254 | GFX_WRITE( ' ' ); |
---|
255 | GFX_WRITE( ' ' ); |
---|
256 | GFX_WRITE( '<' ); |
---|
257 | GFX_GOTO( x-2, y+1 ); |
---|
258 | GFX_WRITE( '~' ); |
---|
259 | GFX_WRITE( '/' ); |
---|
260 | GFX_WRITE( '_' ); |
---|
261 | GFX_WRITE( '\\' ); |
---|
262 | GFX_WRITE( '~' ); |
---|
263 | break; |
---|
264 | case 3: |
---|
265 | GFX_COLOR( RED ); |
---|
266 | case 4: |
---|
267 | case 2: |
---|
268 | GFX_GOTO( x-2, y-1 ); |
---|
269 | GFX_WRITE( '_' ); |
---|
270 | GFX_WRITE( '\\' ); |
---|
271 | GFX_WRITE( ' ' ); |
---|
272 | GFX_WRITE( '/' ); |
---|
273 | GFX_WRITE( '_' ); |
---|
274 | GFX_GOTO( x-2, y ); |
---|
275 | GFX_WRITE( '_' ); |
---|
276 | GFX_WRITE( ' ' ); |
---|
277 | GFX_WRITE( ' ' ); |
---|
278 | GFX_WRITE( ' ' ); |
---|
279 | GFX_WRITE( '_' ); |
---|
280 | GFX_GOTO( x-2, y+1 ); |
---|
281 | GFX_WRITE( ' ' ); |
---|
282 | GFX_WRITE( '/' ); |
---|
283 | GFX_WRITE( ' ' ); |
---|
284 | GFX_WRITE( '\\' ); |
---|
285 | GFX_WRITE( ' ' ); |
---|
286 | break; |
---|
287 | case 1: |
---|
288 | GFX_COLOR( WHITE ); |
---|
289 | GFX_GOTO( x-2, y-1 ); |
---|
290 | GFX_WRITE( '.' ); |
---|
291 | GFX_WRITE( ' ' ); |
---|
292 | GFX_WRITE( '\'' ); |
---|
293 | GFX_WRITE( ' ' ); |
---|
294 | GFX_WRITE( ',' ); |
---|
295 | GFX_GOTO( x-2, y ); |
---|
296 | GFX_WRITE( ' ' ); |
---|
297 | GFX_WRITE( ' ' ); |
---|
298 | GFX_WRITE( ' ' ); |
---|
299 | GFX_WRITE( ' ' ); |
---|
300 | GFX_WRITE( ' ' ); |
---|
301 | GFX_GOTO( x-2, y+1 ); |
---|
302 | GFX_WRITE( '\'' ); |
---|
303 | GFX_WRITE( ' ' ); |
---|
304 | GFX_WRITE( '.' ); |
---|
305 | GFX_WRITE( ' ' ); |
---|
306 | GFX_WRITE( '`' ); |
---|
307 | break; |
---|
308 | } |
---|
309 | } |
---|
310 | |
---|
311 | static void draw_circle( int x, int y, float r ); |
---|
312 | |
---|
313 | static void draw_huge_explosion( int x, int y, int frame ) |
---|
314 | { |
---|
315 | float r = 1.5 * (30 - frame); |
---|
316 | |
---|
317 | GFX_COLOR( BLUE ); |
---|
318 | draw_circle( x, y, r ); |
---|
319 | |
---|
320 | r += 0.7; |
---|
321 | |
---|
322 | GFX_COLOR( CYAN ); |
---|
323 | draw_circle( x, y, r ); |
---|
324 | |
---|
325 | r += 0.7; |
---|
326 | |
---|
327 | GFX_COLOR( WHITE ); |
---|
328 | draw_circle( x, y, r ); |
---|
329 | } |
---|
330 | |
---|
331 | static void draw_circle( int x, int y, float r ) |
---|
332 | { |
---|
333 | #if 1 |
---|
334 | float c; |
---|
335 | |
---|
336 | for( c = 0 ; c <= 90 ; c += 1 ) |
---|
337 | { |
---|
338 | float dx = 0.5 + r * 2.0 * sin( c * M_PI / 180.0 ); |
---|
339 | float dy = 0.5 + r * cos( c * M_PI / 180.0 ); |
---|
340 | |
---|
341 | GFX_GOTO( x + dx, y + dy ); |
---|
342 | GFX_WRITE( '#' ); |
---|
343 | GFX_GOTO( x - dx, y + dy ); |
---|
344 | GFX_WRITE( '#' ); |
---|
345 | GFX_GOTO( x + dx, y - dy ); |
---|
346 | GFX_WRITE( '#' ); |
---|
347 | GFX_GOTO( x - dx, y - dy ); |
---|
348 | GFX_WRITE( '#' ); |
---|
349 | } |
---|
350 | #endif |
---|
351 | |
---|
352 | #if 0 |
---|
353 | int dx,dy,a2,b2, S, T; |
---|
354 | float a = r*8, b = r*2; |
---|
355 | |
---|
356 | a2 = a*a; |
---|
357 | b2 = b*b; |
---|
358 | dx = 0; |
---|
359 | dy = b; |
---|
360 | S = a2*(1-2*b) + 2*b2; |
---|
361 | T = b2 - 2*a2*(2*b-1); |
---|
362 | GFX_GOTO( x + dx, y + dy ); |
---|
363 | GFX_WRITE( '#' ); |
---|
364 | GFX_GOTO( x - dx, y + dy ); |
---|
365 | GFX_WRITE( '#' ); |
---|
366 | GFX_GOTO( x + dx, y - dy ); |
---|
367 | GFX_WRITE( '#' ); |
---|
368 | GFX_GOTO( x - dx, y - dy ); |
---|
369 | GFX_WRITE( '#' ); |
---|
370 | |
---|
371 | do |
---|
372 | { |
---|
373 | if (S<0) |
---|
374 | { |
---|
375 | S += 2*b2*(2*x+3); |
---|
376 | T += 4*b2*(x+1); |
---|
377 | dx++; |
---|
378 | } |
---|
379 | else if (T<0) |
---|
380 | { |
---|
381 | S += 2*b2*(2*x+3) - 4*a2*(dy-1); |
---|
382 | T += 4*b2*(x+1) - 2*a2*(2*dy-3); |
---|
383 | dx++; |
---|
384 | dy--; |
---|
385 | } |
---|
386 | else |
---|
387 | { |
---|
388 | S -= 4*a2*(dy-1); |
---|
389 | T -= 2*a2*(2*dy-3); |
---|
390 | dy--; |
---|
391 | } |
---|
392 | GFX_GOTO( x + dx, y + dy ); |
---|
393 | GFX_WRITE( '#' ); |
---|
394 | GFX_GOTO( x - dx, y + dy ); |
---|
395 | GFX_WRITE( '#' ); |
---|
396 | GFX_GOTO( x + dx, y - dy ); |
---|
397 | GFX_WRITE( '#' ); |
---|
398 | GFX_GOTO( x - dx, y - dy ); |
---|
399 | GFX_WRITE( '#' ); |
---|
400 | } |
---|
401 | while (dy>0); |
---|
402 | #endif |
---|
403 | |
---|
404 | } |
---|
405 | |
---|