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

Last change on this file since 76 was 76, checked in by Sam Hocevar, 17 years ago
  • libee/ee.c: + First file in libee, from src/graphics.c. + Disable cursor upon initialisation. + Added delay code for constant framerate.
  • src/common.h: + Minor compilation fix for latest ncurses.
  • Property svn:keywords set to Id
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 76 2003-11-09 11:26:08Z 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#define box box_other
53#   include <curses.h>
54#undef box
55#   define gfx_color(x) attrset(COLOR_PAIR(x))
56#   define gfx_goto(x,y) move(y,x)
57#   define gfx_putchar(x) addch(x)
58#   define gfx_putstr(x) addstr(x)
59#else
60#   define gfx_color(x) (void)(x)
61#   define gfx_goto(x,y) do{ (void)(x); (void)(y); } while(0)
62#   define gfx_putchar(x) (void)(x)
63#   define gfx_putstr(x) (void)(x)
64#endif
65
66#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0)
67
68/*
69 * Useful macros
70 */
71#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
72#define GET_MAX(a,b) ((a)>(b)?(a):(b))
73#define GET_MIN(a,b) ((a)<(b)?(a):(b))
74
75/*
76 * Game structures
77 */
78typedef struct
79{
80    int w, h, *left, *right;
81
82} tunnel;
83
84typedef struct
85{
86    int x, y, z, c;
87    char ch;
88
89} starfield;
90
91typedef struct
92{
93    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
94    int x[EXPLOSIONS];
95    int y[EXPLOSIONS];
96    int vx[EXPLOSIONS];
97    int vy[EXPLOSIONS];
98    int n[EXPLOSIONS];
99
100} explosions;
101
102typedef struct
103{
104    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS];
105    int x[WEAPONS];
106    int y[WEAPONS];
107    int x2[WEAPONS];
108    int y2[WEAPONS];
109    int x3[WEAPONS];
110    int y3[WEAPONS];
111    int vx[WEAPONS];
112    int vy[WEAPONS];
113    int n[WEAPONS];
114
115} weapons;
116
117typedef struct
118{
119    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
120    int x[BONUS];
121    int y[BONUS];
122    int n[BONUS];
123
124} bonus;
125
126typedef struct
127{
128    int x, y;
129    int vx, vy;
130    int weapon, special;
131    int life, dead;
132
133} player;
134
135typedef struct
136{
137    enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS];
138    int x[ALIENS];
139    int y[ALIENS];
140    int life[ALIENS];
141    int img[ALIENS];
142
143} aliens;
144
145typedef struct
146{
147    int w, h;
148    int x, y;
149    int frame;
150
151} box;
152
153typedef struct
154{
155    int w, h;
156
157    starfield *sf;
158    weapons *wp;
159    explosions *ex;
160    tunnel *t;
161    player *p;
162    aliens *al;
163    bonus *bo;
164
165} game;
166
167#define BLACK 1
168#define GREEN 2
169#define YELLOW 3
170#define WHITE 4
171#define RED 5
172#define GRAY 6
173#define LIGHTGRAY 7
174#define BLUE 8
175#define CYAN 9
176#define MAGENTA 10
177
178/*
179 * From aliens.c
180 */
181void init_aliens( game *g, aliens *al );
182void draw_aliens( game *g, aliens *al );
183void update_aliens( game *g, aliens *al );
184void add_alien( game *g, aliens *al, int x, int y, int type );
185
186/*
187 * From bonus.c
188 */
189void init_bonus( game *g, bonus *bo );
190void draw_bonus( game *g, bonus *bo );
191void update_bonus( game *g, bonus *bo );
192void add_bonus( game *g, bonus *bo, int x, int y, int type );
193
194/*
195 * From box.c
196 */
197box * create_box( game *g, int x, int y, int w, int h );
198void draw_box( game *g, box *b );
199void free_box( box *b );
200
201/*
202 * From ceo.c
203 */
204void ceo_alert( game *g );
205
206/*
207 * From collide.c
208 */
209void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
210void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
211void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
212
213/*
214 * From explosions.c
215 */
216void init_explosions( game *g, explosions *ex );
217void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
218void draw_explosions( game *g, explosions *ex );
219void update_explosions( game *g, explosions *ex );
220
221/*
222 * From graphics.c
223 */
224int init_graphics( void );
225void init_game( game *g );
226char get_key( void );
227void clear_graphics( game *g );
228void refresh_graphics( void );
229void end_graphics( void );
230
231/*
232 * From math.c
233 */
234int r00t( int a );
235
236/*
237 * From overlay.c
238 */
239void draw_status( game *g );
240
241/*
242 * From player.c
243 */
244player * create_player( game *g );
245void free_player( player *p );
246void draw_player( game *g, player *p );
247void update_player( game *g, player *p );
248
249/*
250 * From starfield.c
251 */
252starfield * create_starfield( game *g );
253void draw_starfield( game *g, starfield *s );
254void update_starfield( game *g, starfield *s );
255void free_starfield( game *g, starfield *s );
256
257/*
258 * From tunnel.c
259 */
260tunnel * create_tunnel( game *g, int w, int h );
261void free_tunnel( tunnel *t );
262void draw_tunnel( game *g, tunnel *t );
263void update_tunnel( game *g, tunnel *t );
264
265/*
266 * From weapons.c
267 */
268void init_weapons( game *g, weapons *wp );
269void draw_weapons( game *g, weapons *wp );
270void update_weapons( game *g, weapons *wp );
271void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
272
Note: See TracBrowser for help on using the repository browser.