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

Last change on this file since 80 was 80, checked in by Sam Hocevar, 17 years ago
  • libee is now standalone.
  • Property svn:keywords set to Id
File size: 4.7 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 80 2003-11-09 12:40:53Z 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#include "ee.h"
46
47/*
48 * Useful macros
49 */
50#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
51#define GET_MAX(a,b) ((a)>(b)?(a):(b))
52#define GET_MIN(a,b) ((a)<(b)?(a):(b))
53
54/*
55 * Game structures
56 */
57typedef struct
58{
59    int w, h, *left, *right;
60
61} tunnel;
62
63typedef struct
64{
65    int x, y, z, c;
66    char ch;
67
68} starfield;
69
70typedef struct
71{
72    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
73    int x[EXPLOSIONS];
74    int y[EXPLOSIONS];
75    int vx[EXPLOSIONS];
76    int vy[EXPLOSIONS];
77    int n[EXPLOSIONS];
78
79} explosions;
80
81typedef struct
82{
83    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS];
84    int x[WEAPONS];
85    int y[WEAPONS];
86    int x2[WEAPONS];
87    int y2[WEAPONS];
88    int x3[WEAPONS];
89    int y3[WEAPONS];
90    int vx[WEAPONS];
91    int vy[WEAPONS];
92    int n[WEAPONS];
93
94} weapons;
95
96typedef struct
97{
98    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
99    int x[BONUS];
100    int y[BONUS];
101    int n[BONUS];
102
103} bonus;
104
105typedef struct
106{
107    int x, y;
108    int vx, vy;
109    int weapon, special;
110    int life, dead;
111
112} player;
113
114typedef struct
115{
116    enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS];
117    int x[ALIENS];
118    int y[ALIENS];
119    int life[ALIENS];
120    int img[ALIENS];
121
122} aliens;
123
124typedef struct
125{
126    int w, h;
127    int x, y;
128    int frame;
129
130} box;
131
132typedef struct
133{
134    int w, h;
135
136    starfield *sf;
137    weapons *wp;
138    explosions *ex;
139    tunnel *t;
140    player *p;
141    aliens *al;
142    bonus *bo;
143
144} game;
145
146/*
147 * From aliens.c
148 */
149void init_aliens( game *g, aliens *al );
150void draw_aliens( game *g, aliens *al );
151void update_aliens( game *g, aliens *al );
152void add_alien( game *g, aliens *al, int x, int y, int type );
153
154/*
155 * From bonus.c
156 */
157void init_bonus( game *g, bonus *bo );
158void draw_bonus( game *g, bonus *bo );
159void update_bonus( game *g, bonus *bo );
160void add_bonus( game *g, bonus *bo, int x, int y, int type );
161
162/*
163 * From box.c
164 */
165box * create_box( game *g, int x, int y, int w, int h );
166void draw_box( game *g, box *b );
167void free_box( box *b );
168
169/*
170 * From ceo.c
171 */
172void ceo_alert( game *g );
173
174/*
175 * From collide.c
176 */
177void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
178void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
179void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
180
181/*
182 * From explosions.c
183 */
184void init_explosions( game *g, explosions *ex );
185void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
186void draw_explosions( game *g, explosions *ex );
187void update_explosions( game *g, explosions *ex );
188
189/*
190 * From math.c
191 */
192int r00t( int a );
193
194/*
195 * From overlay.c
196 */
197void draw_status( game *g );
198
199/*
200 * From player.c
201 */
202player * create_player( game *g );
203void free_player( player *p );
204void draw_player( game *g, player *p );
205void update_player( game *g, player *p );
206
207/*
208 * From starfield.c
209 */
210starfield * create_starfield( game *g );
211void draw_starfield( game *g, starfield *s );
212void update_starfield( game *g, starfield *s );
213void free_starfield( game *g, starfield *s );
214
215/*
216 * From tunnel.c
217 */
218tunnel * create_tunnel( game *g, int w, int h );
219void free_tunnel( tunnel *t );
220void draw_tunnel( game *g, tunnel *t );
221void update_tunnel( game *g, tunnel *t );
222
223/*
224 * From weapons.c
225 */
226void init_weapons( game *g, weapons *wp );
227void draw_weapons( game *g, weapons *wp );
228void update_weapons( game *g, weapons *wp );
229void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
230
Note: See TracBrowser for help on using the repository browser.