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

Last change on this file since 62 was 62, checked in by Sam Hocevar, 18 years ago
  • better handling of special weapon timeout.
  • the bomb is now part of the standard fire button effect.
  • overlay for life and special weapon jauges.
File size: 5.6 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.14 2002/12/23 15:06:13 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) do{}while(0)
59#   define gfx_goto(x,y) do{}while(0)
60#   define gfx_putchar(x) do{}while(0)
61#   define gfx_putstr(x) do{}while(0)
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
147    starfield *sf;
148    weapons *wp;
149    explosions *ex;
150    tunnel *t;
151    player *p;
152    aliens *al;
153    bonus *bo;
154
155} game;
156
157#define BLACK 1
158#define GREEN 2
159#define YELLOW 3
160#define WHITE 4
161#define RED 5
162#define GRAY 6
163#define LIGHTGRAY 7
164#define BLUE 8
165#define CYAN 9
166#define MAGENTA 10
167
168/*
169 * From aliens.c
170 */
171void init_aliens( game *g, aliens *al );
172void draw_aliens( game *g, aliens *al );
173void update_aliens( game *g, aliens *al );
174void add_alien( game *g, aliens *al, int x, int y, int type );
175
176/*
177 * From bonus.c
178 */
179void init_bonus( game *g, bonus *bo );
180void draw_bonus( game *g, bonus *bo );
181void update_bonus( game *g, bonus *bo );
182void add_bonus( game *g, bonus *bo, int x, int y, int type );
183
184/*
185 * From ceo.c
186 */
187void ceo_alert( void );
188
189/*
190 * From collide.c
191 */
192void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
193void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
194void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
195
196/*
197 * From explosions.c
198 */
199void init_explosions( game *g, explosions *ex );
200void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
201void draw_explosions( game *g, explosions *ex );
202void update_explosions( game *g, explosions *ex );
203
204/*
205 * From graphics.c
206 */
207int init_graphics( void );
208void init_game( game *g );
209char get_key( void );
210void clear_graphics( void );
211void refresh_graphics( void );
212void end_graphics( void );
213
214/*
215 * From math.c
216 */
217int r00t( int a );
218
219/*
220 * From overlay.c
221 */
222void draw_overlay( game *g );
223
224/*
225 * From player.c
226 */
227player * create_player( game *g );
228void free_player( player *p );
229void draw_player( game *g, player *p );
230void update_player( game *g, player *p );
231
232/*
233 * From starfield.c
234 */
235starfield * create_starfield( game *g );
236void draw_starfield( game *g, starfield *s );
237void update_starfield( game *g, starfield *s );
238void free_starfield( game *g, starfield *s );
239
240/*
241 * From tunnel.c
242 */
243tunnel * create_tunnel( game *g, int w, int h );
244void free_tunnel( tunnel *t );
245void draw_tunnel( game *g, tunnel *t );
246void update_tunnel( game *g, tunnel *t );
247
248/*
249 * From weapons.c
250 */
251void init_weapons( game *g, weapons *wp );
252void draw_weapons( game *g, weapons *wp );
253void update_weapons( game *g, weapons *wp );
254void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
255
Note: See TracBrowser for help on using the repository browser.