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 90 2003-11-09 13:32:04Z 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_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 | ee_color(GREEN); |
---|
75 | ee_goto(ex->x[i] + 3, ex->y[i]); |
---|
76 | switch(ee_rand(0,3)) |
---|
77 | { |
---|
78 | case 0: |
---|
79 | ee_putchar('p'); |
---|
80 | ee_putchar('i'); |
---|
81 | ee_putchar('f'); |
---|
82 | break; |
---|
83 | case 1: |
---|
84 | ee_putchar('p'); |
---|
85 | ee_putchar('a'); |
---|
86 | ee_putchar('f'); |
---|
87 | break; |
---|
88 | case 2: |
---|
89 | ee_putchar('p'); |
---|
90 | ee_putchar('o'); |
---|
91 | ee_putchar('u'); |
---|
92 | ee_putchar('f'); |
---|
93 | break; |
---|
94 | } |
---|
95 | ee_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 | ee_color(EE_YELLOW); |
---|
142 | ee_goto(x, y); |
---|
143 | ee_putchar('+'); |
---|
144 | break; |
---|
145 | case 5: |
---|
146 | ee_color(EE_YELLOW); |
---|
147 | ee_goto(x, y); |
---|
148 | ee_putchar('o'); |
---|
149 | break; |
---|
150 | case 4: |
---|
151 | ee_color(EE_YELLOW); |
---|
152 | ee_goto(x, y-1); |
---|
153 | ee_putchar('_'); |
---|
154 | ee_goto(x-1, y); |
---|
155 | ee_putstr(")_("); |
---|
156 | break; |
---|
157 | case 3: |
---|
158 | ee_color(EE_YELLOW); |
---|
159 | ee_goto(x-1, y-1); |
---|
160 | ee_putstr("._,"); |
---|
161 | ee_goto(x-1, y); |
---|
162 | ee_putstr(")_("); |
---|
163 | ee_goto(x-1, y+1); |
---|
164 | ee_putstr("\' `"); |
---|
165 | break; |
---|
166 | case 2: |
---|
167 | ee_color(EE_YELLOW); |
---|
168 | ee_goto(x-1, y-1); |
---|
169 | ee_putstr(".v,"); |
---|
170 | ee_goto(x-1, y); |
---|
171 | ee_putstr("> <"); |
---|
172 | ee_goto(x-1, y+1); |
---|
173 | ee_putstr("\'^`"); |
---|
174 | break; |
---|
175 | case 1: |
---|
176 | ee_color(EE_WHITE); |
---|
177 | ee_goto(x-1, y-1); |
---|
178 | ee_putstr(". ,"); |
---|
179 | ee_goto(x-1, y); |
---|
180 | ee_putstr(" "); |
---|
181 | ee_goto(x-1, y+1); |
---|
182 | ee_putstr("\' `"); |
---|
183 | break; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | static void draw_medium_explosion(int x, int y, int frame) |
---|
188 | { |
---|
189 | ee_color(EE_YELLOW); |
---|
190 | |
---|
191 | switch(frame) |
---|
192 | { |
---|
193 | case 10: |
---|
194 | ee_goto(x, y); |
---|
195 | ee_putchar('+'); |
---|
196 | break; |
---|
197 | case 9: |
---|
198 | ee_goto(x, y); |
---|
199 | ee_putchar('o'); |
---|
200 | break; |
---|
201 | case 8: |
---|
202 | ee_goto(x, y-1); |
---|
203 | ee_putchar('_'); |
---|
204 | ee_goto(x-1, y); |
---|
205 | ee_putstr(")_("); |
---|
206 | break; |
---|
207 | case 7: |
---|
208 | ee_goto(x-1, y-1); |
---|
209 | ee_putstr("._,"); |
---|
210 | ee_goto(x-1, y); |
---|
211 | ee_putstr(")_("); |
---|
212 | ee_goto(x-1, y+1); |
---|
213 | ee_putstr("\' `"); |
---|
214 | break; |
---|
215 | case 6: |
---|
216 | ee_goto(x-1, y-1); |
---|
217 | ee_putstr(".v,"); |
---|
218 | ee_goto(x-1, y); |
---|
219 | ee_putstr("> <"); |
---|
220 | ee_goto(x-1, y+1); |
---|
221 | ee_putstr("\'^`"); |
---|
222 | break; |
---|
223 | case 5: |
---|
224 | ee_color(EE_RED); |
---|
225 | case 4: |
---|
226 | ee_goto(x-2, y-1); |
---|
227 | ee_putstr("_\\~/_"); |
---|
228 | ee_goto(x-2, y); |
---|
229 | ee_putstr("> <"); |
---|
230 | ee_goto(x-2, y+1); |
---|
231 | ee_putstr("~/_\\~"); |
---|
232 | break; |
---|
233 | case 3: |
---|
234 | ee_color(EE_RED); |
---|
235 | case 2: |
---|
236 | ee_goto(x-2, y-1); |
---|
237 | ee_putstr("_\\ /_"); |
---|
238 | ee_goto(x-2, y); |
---|
239 | ee_putstr("_ _"); |
---|
240 | ee_goto(x-2, y+1); |
---|
241 | ee_putstr(" / \\ "); |
---|
242 | break; |
---|
243 | case 1: |
---|
244 | ee_color(EE_WHITE); |
---|
245 | ee_goto(x-2, y-1); |
---|
246 | ee_putstr(". \' ,"); |
---|
247 | ee_goto(x-2, y); |
---|
248 | ee_putstr(" "); |
---|
249 | ee_goto(x-2, y+1); |
---|
250 | ee_putstr("\' . `"); |
---|
251 | break; |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|