1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: explosions.c,v 1.4 2002/12/22 18:44:12 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_small_explosion( int x, int y, int frame ); |
---|
28 | static void draw_medium_explosion( int x, int y, int frame ); |
---|
29 | |
---|
30 | void init_explosions( game *g, explosions *ex ) |
---|
31 | { |
---|
32 | int i; |
---|
33 | |
---|
34 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
35 | { |
---|
36 | ex->type[i] = EXPLOSION_NONE; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ) |
---|
41 | { |
---|
42 | int i; |
---|
43 | |
---|
44 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
45 | { |
---|
46 | if( ex->type[i] == EXPLOSION_NONE ) |
---|
47 | { |
---|
48 | ex->type[i] = type; |
---|
49 | ex->x[i] = x; |
---|
50 | ex->y[i] = y; |
---|
51 | ex->vx[i] = vx; |
---|
52 | ex->vy[i] = vy; |
---|
53 | switch( type ) |
---|
54 | { |
---|
55 | case EXPLOSION_MEDIUM: |
---|
56 | ex->n[i] = 11; |
---|
57 | break; |
---|
58 | case EXPLOSION_SMALL: |
---|
59 | ex->n[i] = 7; |
---|
60 | break; |
---|
61 | } |
---|
62 | break; |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | void draw_explosions( game *g, explosions *ex ) |
---|
68 | { |
---|
69 | int i; |
---|
70 | |
---|
71 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
72 | { |
---|
73 | #if 0 |
---|
74 | gfx_color( GREEN ); |
---|
75 | gfx_goto( ex->x[i] + 3, ex->y[i] ); |
---|
76 | switch( GET_RAND(0,3) ) |
---|
77 | { |
---|
78 | case 0: |
---|
79 | gfx_putchar( 'p' ); |
---|
80 | gfx_putchar( 'i' ); |
---|
81 | gfx_putchar( 'f' ); |
---|
82 | break; |
---|
83 | case 1: |
---|
84 | gfx_putchar( 'p' ); |
---|
85 | gfx_putchar( 'a' ); |
---|
86 | gfx_putchar( 'f' ); |
---|
87 | break; |
---|
88 | case 2: |
---|
89 | gfx_putchar( 'p' ); |
---|
90 | gfx_putchar( 'o' ); |
---|
91 | gfx_putchar( 'u' ); |
---|
92 | gfx_putchar( 'f' ); |
---|
93 | break; |
---|
94 | } |
---|
95 | gfx_putchar( '!' ); |
---|
96 | #endif |
---|
97 | |
---|
98 | switch( ex->type[i] ) |
---|
99 | { |
---|
100 | case EXPLOSION_MEDIUM: |
---|
101 | draw_medium_explosion( ex->x[i], ex->y[i], ex->n[i] ); |
---|
102 | break; |
---|
103 | case EXPLOSION_SMALL: |
---|
104 | draw_small_explosion( ex->x[i], ex->y[i], ex->n[i] ); |
---|
105 | break; |
---|
106 | case EXPLOSION_NONE: |
---|
107 | break; |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | void update_explosions( game *g, explosions *ex ) |
---|
113 | { |
---|
114 | int i; |
---|
115 | |
---|
116 | for( i = 0; i < EXPLOSIONS; i++ ) |
---|
117 | { |
---|
118 | switch( ex->type[i] ) |
---|
119 | { |
---|
120 | case EXPLOSION_MEDIUM: |
---|
121 | case EXPLOSION_SMALL: |
---|
122 | ex->x[i] += ex->vx[i]; |
---|
123 | ex->y[i] += ex->vy[i]; |
---|
124 | ex->n[i]--; |
---|
125 | if( ex->n[i] < 0 ) |
---|
126 | { |
---|
127 | ex->type[i] = EXPLOSION_NONE; |
---|
128 | } |
---|
129 | break; |
---|
130 | case EXPLOSION_NONE: |
---|
131 | break; |
---|
132 | } |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | static void draw_small_explosion( int x, int y, int frame ) |
---|
137 | { |
---|
138 | switch( frame ) |
---|
139 | { |
---|
140 | case 6: |
---|
141 | gfx_color( YELLOW ); |
---|
142 | gfx_goto( x, y ); |
---|
143 | gfx_putchar( '+' ); |
---|
144 | break; |
---|
145 | case 5: |
---|
146 | gfx_color( YELLOW ); |
---|
147 | gfx_goto( x, y ); |
---|
148 | gfx_putchar( 'o' ); |
---|
149 | break; |
---|
150 | case 4: |
---|
151 | gfx_color( YELLOW ); |
---|
152 | gfx_goto( x, y-1 ); |
---|
153 | gfx_putchar( '_' ); |
---|
154 | gfx_goto( x-1, y ); |
---|
155 | gfx_putstr( ")_(" ); |
---|
156 | break; |
---|
157 | case 3: |
---|
158 | gfx_color( YELLOW ); |
---|
159 | gfx_goto( x-1, y-1 ); |
---|
160 | gfx_putstr( "._," ); |
---|
161 | gfx_goto( x-1, y ); |
---|
162 | gfx_putstr( ")_(" ); |
---|
163 | gfx_goto( x-1, y+1 ); |
---|
164 | gfx_putstr( "\' `" ); |
---|
165 | break; |
---|
166 | case 2: |
---|
167 | gfx_color( YELLOW ); |
---|
168 | gfx_goto( x-1, y-1 ); |
---|
169 | gfx_putstr( ".v," ); |
---|
170 | gfx_goto( x-1, y ); |
---|
171 | gfx_putstr( "> <" ); |
---|
172 | gfx_goto( x-1, y+1 ); |
---|
173 | gfx_putstr( "\'^`" ); |
---|
174 | break; |
---|
175 | case 1: |
---|
176 | gfx_color( WHITE ); |
---|
177 | gfx_goto( x-1, y-1 ); |
---|
178 | gfx_putstr( ". ," ); |
---|
179 | gfx_goto( x-1, y ); |
---|
180 | gfx_putstr( " " ); |
---|
181 | gfx_goto( x-1, y+1 ); |
---|
182 | gfx_putstr( "\' `" ); |
---|
183 | break; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | static void draw_medium_explosion( int x, int y, int frame ) |
---|
188 | { |
---|
189 | gfx_color( YELLOW ); |
---|
190 | |
---|
191 | switch( frame ) |
---|
192 | { |
---|
193 | case 10: |
---|
194 | gfx_goto( x, y ); |
---|
195 | gfx_putchar( '+' ); |
---|
196 | break; |
---|
197 | case 9: |
---|
198 | gfx_goto( x, y ); |
---|
199 | gfx_putchar( 'o' ); |
---|
200 | break; |
---|
201 | case 8: |
---|
202 | gfx_goto( x, y-1 ); |
---|
203 | gfx_putchar( '_' ); |
---|
204 | gfx_goto( x-1, y ); |
---|
205 | gfx_putstr( ")_(" ); |
---|
206 | break; |
---|
207 | case 7: |
---|
208 | gfx_goto( x-1, y-1 ); |
---|
209 | gfx_putstr( "._," ); |
---|
210 | gfx_goto( x-1, y ); |
---|
211 | gfx_putstr( ")_(" ); |
---|
212 | gfx_goto( x-1, y+1 ); |
---|
213 | gfx_putstr( "\' `" ); |
---|
214 | break; |
---|
215 | case 6: |
---|
216 | gfx_goto( x-1, y-1 ); |
---|
217 | gfx_putstr( ".v," ); |
---|
218 | gfx_goto( x-1, y ); |
---|
219 | gfx_putstr( "> <" ); |
---|
220 | gfx_goto( x-1, y+1 ); |
---|
221 | gfx_putstr( "\'^`" ); |
---|
222 | break; |
---|
223 | case 5: |
---|
224 | gfx_color( RED ); |
---|
225 | case 4: |
---|
226 | gfx_goto( x-2, y-1 ); |
---|
227 | gfx_putstr( "_\\~/_" ); |
---|
228 | gfx_goto( x-2, y ); |
---|
229 | gfx_putstr( "> <" ); |
---|
230 | gfx_goto( x-2, y+1 ); |
---|
231 | gfx_putstr( "~/_\\~" ); |
---|
232 | break; |
---|
233 | case 3: |
---|
234 | gfx_color( RED ); |
---|
235 | case 2: |
---|
236 | gfx_goto( x-2, y-1 ); |
---|
237 | gfx_putstr( "_\\ /_" ); |
---|
238 | gfx_goto( x-2, y ); |
---|
239 | gfx_putstr( "_ _" ); |
---|
240 | gfx_goto( x-2, y+1 ); |
---|
241 | gfx_putstr( " / \\ " ); |
---|
242 | break; |
---|
243 | case 1: |
---|
244 | gfx_color( WHITE ); |
---|
245 | gfx_goto( x-2, y-1 ); |
---|
246 | gfx_putstr( ". \' ," ); |
---|
247 | gfx_goto( x-2, y ); |
---|
248 | gfx_putstr( " " ); |
---|
249 | gfx_goto( x-2, y+1 ); |
---|
250 | gfx_putstr( "\' . `" ); |
---|
251 | break; |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|