source: ttyvaders/trunk/src/common.h @ 70

Last change on this file since 70 was 70, checked in by Sam Hocevar, 19 years ago
  • support for boxes
  • application: pause box
File size: 5.8 KB
Line 
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,v 1.16 2003/02/09 11:17:40 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/*
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 */
76typedef struct
77{
78    int w, h, *left, *right;
79
80} tunnel;
81
82typedef struct
83{
84    int x, y, z, c;
85    char ch;
86
87} starfield;
88
89typedef 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
100typedef 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
115typedef 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
124typedef struct
125{
126    int x, y;
127    int vx, vy;
128    int weapon, special;
129    int life, dead;
130
131} player;
132
133typedef 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
143typedef struct
144{
145    int w, h;
146    int x, y;
147    int frame;
148
149} box;
150
151typedef 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 */
179void init_aliens( game *g, aliens *al );
180void draw_aliens( game *g, aliens *al );
181void update_aliens( game *g, aliens *al );
182void add_alien( game *g, aliens *al, int x, int y, int type );
183
184/*
185 * From bonus.c
186 */
187void init_bonus( game *g, bonus *bo );
188void draw_bonus( game *g, bonus *bo );
189void update_bonus( game *g, bonus *bo );
190void add_bonus( game *g, bonus *bo, int x, int y, int type );
191
192/*
193 * From box.c
194 */
195box * create_box( game *g, int x, int y, int w, int h );
196void draw_box( game *g, box *b );
197void free_box( box *b );
198
199/*
200 * From ceo.c
201 */
202void ceo_alert( void );
203
204/*
205 * From collide.c
206 */
207void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
208void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
209void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
210
211/*
212 * From explosions.c
213 */
214void init_explosions( game *g, explosions *ex );
215void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
216void draw_explosions( game *g, explosions *ex );
217void update_explosions( game *g, explosions *ex );
218
219/*
220 * From graphics.c
221 */
222int init_graphics( void );
223void init_game( game *g );
224char get_key( void );
225void gfx_delay( void );
226void clear_graphics( void );
227void refresh_graphics( void );
228void end_graphics( void );
229
230/*
231 * From math.c
232 */
233int r00t( int a );
234
235/*
236 * From overlay.c
237 */
238void draw_status( game *g );
239
240/*
241 * From player.c
242 */
243player * create_player( game *g );
244void free_player( player *p );
245void draw_player( game *g, player *p );
246void update_player( game *g, player *p );
247
248/*
249 * From starfield.c
250 */
251starfield * create_starfield( game *g );
252void draw_starfield( game *g, starfield *s );
253void update_starfield( game *g, starfield *s );
254void free_starfield( game *g, starfield *s );
255
256/*
257 * From tunnel.c
258 */
259tunnel * create_tunnel( game *g, int w, int h );
260void free_tunnel( tunnel *t );
261void draw_tunnel( game *g, tunnel *t );
262void update_tunnel( game *g, tunnel *t );
263
264/*
265 * From weapons.c
266 */
267void init_weapons( game *g, weapons *wp );
268void draw_weapons( game *g, weapons *wp );
269void update_weapons( game *g, weapons *wp );
270void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
271
Note: See TracBrowser for help on using the repository browser.