1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: common.h 71 2003-10-02 01:08:13Z 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 | /* |
---|
24 | * Compile-time limits |
---|
25 | */ |
---|
26 | #define STARS 50 |
---|
27 | #define WEAPONS 200 |
---|
28 | #define BONUS 30 |
---|
29 | #define ALIENS 30 |
---|
30 | #define EXPLOSIONS 200 |
---|
31 | |
---|
32 | /* |
---|
33 | * Game defines |
---|
34 | */ |
---|
35 | #define MAX_LIFE 1000 |
---|
36 | #define MAX_SPECIAL 200 |
---|
37 | |
---|
38 | #define COST_NUKE (100*MAX_SPECIAL/100) |
---|
39 | #define COST_BEAM (75*MAX_SPECIAL/100) |
---|
40 | #define COST_FRAGBOMB (50*MAX_SPECIAL/100) |
---|
41 | |
---|
42 | /* |
---|
43 | * Graphics primitives |
---|
44 | */ |
---|
45 | #ifdef USE_SLANG |
---|
46 | # include <slang.h> |
---|
47 | # define gfx_color(x) SLsmg_set_color(x) |
---|
48 | # define gfx_goto(x,y) SLsmg_gotorc(y,x) |
---|
49 | # define gfx_putchar(x) SLsmg_write_char(x) |
---|
50 | # define gfx_putstr(x) SLsmg_write_string(x) |
---|
51 | #elif USE_NCURSES |
---|
52 | # include <curses.h> |
---|
53 | # define gfx_color(x) attrset(COLOR_PAIR(x)) |
---|
54 | # define gfx_goto(x,y) move(y,x) |
---|
55 | # define gfx_putchar(x) addch(x) |
---|
56 | # define gfx_putstr(x) addstr(x) |
---|
57 | #else |
---|
58 | # define gfx_color(x) (void)(x) |
---|
59 | # define gfx_goto(x,y) do{ (void)(x); (void)(y); } while(0) |
---|
60 | # define gfx_putchar(x) (void)(x) |
---|
61 | # define gfx_putstr(x) (void)(x) |
---|
62 | #endif |
---|
63 | |
---|
64 | #define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) |
---|
65 | |
---|
66 | /* |
---|
67 | * Useful macros |
---|
68 | */ |
---|
69 | #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) |
---|
70 | #define GET_MAX(a,b) ((a)>(b)?(a):(b)) |
---|
71 | #define GET_MIN(a,b) ((a)<(b)?(a):(b)) |
---|
72 | |
---|
73 | /* |
---|
74 | * Game structures |
---|
75 | */ |
---|
76 | typedef struct |
---|
77 | { |
---|
78 | int w, h, *left, *right; |
---|
79 | |
---|
80 | } tunnel; |
---|
81 | |
---|
82 | typedef struct |
---|
83 | { |
---|
84 | int x, y, z, c; |
---|
85 | char ch; |
---|
86 | |
---|
87 | } starfield; |
---|
88 | |
---|
89 | typedef struct |
---|
90 | { |
---|
91 | enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS]; |
---|
92 | int x[EXPLOSIONS]; |
---|
93 | int y[EXPLOSIONS]; |
---|
94 | int vx[EXPLOSIONS]; |
---|
95 | int vy[EXPLOSIONS]; |
---|
96 | int n[EXPLOSIONS]; |
---|
97 | |
---|
98 | } explosions; |
---|
99 | |
---|
100 | typedef struct |
---|
101 | { |
---|
102 | enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS]; |
---|
103 | int x[WEAPONS]; |
---|
104 | int y[WEAPONS]; |
---|
105 | int x2[WEAPONS]; |
---|
106 | int y2[WEAPONS]; |
---|
107 | int x3[WEAPONS]; |
---|
108 | int y3[WEAPONS]; |
---|
109 | int vx[WEAPONS]; |
---|
110 | int vy[WEAPONS]; |
---|
111 | int n[WEAPONS]; |
---|
112 | |
---|
113 | } weapons; |
---|
114 | |
---|
115 | typedef struct |
---|
116 | { |
---|
117 | enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS]; |
---|
118 | int x[BONUS]; |
---|
119 | int y[BONUS]; |
---|
120 | int n[BONUS]; |
---|
121 | |
---|
122 | } bonus; |
---|
123 | |
---|
124 | typedef struct |
---|
125 | { |
---|
126 | int x, y; |
---|
127 | int vx, vy; |
---|
128 | int weapon, special; |
---|
129 | int life, dead; |
---|
130 | |
---|
131 | } player; |
---|
132 | |
---|
133 | typedef struct |
---|
134 | { |
---|
135 | enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS]; |
---|
136 | int x[ALIENS]; |
---|
137 | int y[ALIENS]; |
---|
138 | int life[ALIENS]; |
---|
139 | int img[ALIENS]; |
---|
140 | |
---|
141 | } aliens; |
---|
142 | |
---|
143 | typedef struct |
---|
144 | { |
---|
145 | int w, h; |
---|
146 | int x, y; |
---|
147 | int frame; |
---|
148 | |
---|
149 | } box; |
---|
150 | |
---|
151 | typedef struct |
---|
152 | { |
---|
153 | int w, h; |
---|
154 | |
---|
155 | starfield *sf; |
---|
156 | weapons *wp; |
---|
157 | explosions *ex; |
---|
158 | tunnel *t; |
---|
159 | player *p; |
---|
160 | aliens *al; |
---|
161 | bonus *bo; |
---|
162 | |
---|
163 | } game; |
---|
164 | |
---|
165 | #define BLACK 1 |
---|
166 | #define GREEN 2 |
---|
167 | #define YELLOW 3 |
---|
168 | #define WHITE 4 |
---|
169 | #define RED 5 |
---|
170 | #define GRAY 6 |
---|
171 | #define LIGHTGRAY 7 |
---|
172 | #define BLUE 8 |
---|
173 | #define CYAN 9 |
---|
174 | #define MAGENTA 10 |
---|
175 | |
---|
176 | /* |
---|
177 | * From aliens.c |
---|
178 | */ |
---|
179 | void init_aliens( game *g, aliens *al ); |
---|
180 | void draw_aliens( game *g, aliens *al ); |
---|
181 | void update_aliens( game *g, aliens *al ); |
---|
182 | void add_alien( game *g, aliens *al, int x, int y, int type ); |
---|
183 | |
---|
184 | /* |
---|
185 | * From bonus.c |
---|
186 | */ |
---|
187 | void init_bonus( game *g, bonus *bo ); |
---|
188 | void draw_bonus( game *g, bonus *bo ); |
---|
189 | void update_bonus( game *g, bonus *bo ); |
---|
190 | void add_bonus( game *g, bonus *bo, int x, int y, int type ); |
---|
191 | |
---|
192 | /* |
---|
193 | * From box.c |
---|
194 | */ |
---|
195 | box * create_box( game *g, int x, int y, int w, int h ); |
---|
196 | void draw_box( game *g, box *b ); |
---|
197 | void free_box( box *b ); |
---|
198 | |
---|
199 | /* |
---|
200 | * From ceo.c |
---|
201 | */ |
---|
202 | void ceo_alert( void ); |
---|
203 | |
---|
204 | /* |
---|
205 | * From collide.c |
---|
206 | */ |
---|
207 | void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ); |
---|
208 | void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ); |
---|
209 | void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ); |
---|
210 | |
---|
211 | /* |
---|
212 | * From explosions.c |
---|
213 | */ |
---|
214 | void init_explosions( game *g, explosions *ex ); |
---|
215 | void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ); |
---|
216 | void draw_explosions( game *g, explosions *ex ); |
---|
217 | void update_explosions( game *g, explosions *ex ); |
---|
218 | |
---|
219 | /* |
---|
220 | * From graphics.c |
---|
221 | */ |
---|
222 | int init_graphics( void ); |
---|
223 | void init_game( game *g ); |
---|
224 | char get_key( void ); |
---|
225 | void gfx_delay( void ); |
---|
226 | void clear_graphics( void ); |
---|
227 | void refresh_graphics( void ); |
---|
228 | void end_graphics( void ); |
---|
229 | |
---|
230 | /* |
---|
231 | * From math.c |
---|
232 | */ |
---|
233 | int r00t( int a ); |
---|
234 | |
---|
235 | /* |
---|
236 | * From overlay.c |
---|
237 | */ |
---|
238 | void draw_status( game *g ); |
---|
239 | |
---|
240 | /* |
---|
241 | * From player.c |
---|
242 | */ |
---|
243 | player * create_player( game *g ); |
---|
244 | void free_player( player *p ); |
---|
245 | void draw_player( game *g, player *p ); |
---|
246 | void update_player( game *g, player *p ); |
---|
247 | |
---|
248 | /* |
---|
249 | * From starfield.c |
---|
250 | */ |
---|
251 | starfield * create_starfield( game *g ); |
---|
252 | void draw_starfield( game *g, starfield *s ); |
---|
253 | void update_starfield( game *g, starfield *s ); |
---|
254 | void free_starfield( game *g, starfield *s ); |
---|
255 | |
---|
256 | /* |
---|
257 | * From tunnel.c |
---|
258 | */ |
---|
259 | tunnel * create_tunnel( game *g, int w, int h ); |
---|
260 | void free_tunnel( tunnel *t ); |
---|
261 | void draw_tunnel( game *g, tunnel *t ); |
---|
262 | void update_tunnel( game *g, tunnel *t ); |
---|
263 | |
---|
264 | /* |
---|
265 | * From weapons.c |
---|
266 | */ |
---|
267 | void init_weapons( game *g, weapons *wp ); |
---|
268 | void draw_weapons( game *g, weapons *wp ); |
---|
269 | void update_weapons( game *g, weapons *wp ); |
---|
270 | void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ); |
---|
271 | |
---|