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

Last change on this file since 60 was 60, checked in by Sam Hocevar, 17 years ago
  • aliens are now named foo, bar and baz.
  • beginning of life jauges.
File size: 4.9 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.13 2002/12/23 13:46:27 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#define MAX_LIFE 1000
24
25#define STARS 50
26#define WEAPONS 200
27#define BONUS 30
28#define ALIENS 30
29#define EXPLOSIONS 200
30
31#ifdef USE_SLANG
32#   include <slang.h>
33#   define gfx_color(x) SLsmg_set_color(x)
34#   define gfx_goto(x,y) SLsmg_gotorc(y,x)
35#   define gfx_putchar(x) SLsmg_write_char(x)
36#   define gfx_putstr(x) SLsmg_write_string(x)
37#elif USE_NCURSES
38#   include <curses.h>
39#   define gfx_color(x) attrset(COLOR_PAIR(x))
40#   define gfx_goto(x,y) move(y,x)
41#   define gfx_putchar(x) addch(x)
42#   define gfx_putstr(x) addstr(x)
43#else
44#   define gfx_color(x) do{}while(0)
45#   define gfx_goto(x,y) do{}while(0)
46#   define gfx_putchar(x) do{}while(0)
47#   define gfx_putstr(x) do{}while(0)
48#endif
49
50#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0)
51
52#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
53#define GET_MAX(a,b) ((a)>(b)?(a):(b))
54#define GET_MIN(a,b) ((a)<(b)?(a):(b))
55
56typedef struct
57{
58    int w, h, *left, *right;
59
60} tunnel;
61
62typedef struct
63{
64    int x, y, z, c;
65    char ch;
66
67} starfield;
68
69typedef struct
70{
71    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
72    int x[EXPLOSIONS];
73    int y[EXPLOSIONS];
74    int vx[EXPLOSIONS];
75    int vy[EXPLOSIONS];
76    int n[EXPLOSIONS];
77
78} explosions;
79
80typedef struct
81{
82    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS];
83    int x[WEAPONS];
84    int y[WEAPONS];
85    int x2[WEAPONS];
86    int y2[WEAPONS];
87    int x3[WEAPONS];
88    int y3[WEAPONS];
89    int vx[WEAPONS];
90    int vy[WEAPONS];
91    int n[WEAPONS];
92
93} weapons;
94
95typedef struct
96{
97    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
98    int x[BONUS];
99    int y[BONUS];
100    int n[BONUS];
101
102} bonus;
103
104typedef struct
105{
106    int x, y;
107    int vx, vy;
108    int weapon, nuke;
109    int life, dead;
110
111} player;
112
113typedef struct
114{
115    enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS];
116    int x[ALIENS];
117    int y[ALIENS];
118    int life[ALIENS];
119    int img[ALIENS];
120
121} aliens;
122
123typedef struct
124{
125    int w, h;
126
127    starfield *sf;
128    weapons *wp;
129    explosions *ex;
130    tunnel *t;
131    player *p;
132    aliens *al;
133    bonus *bo;
134
135} game;
136
137#define BLACK 1
138#define GREEN 2
139#define YELLOW 3
140#define WHITE 4
141#define RED 5
142#define GRAY 6
143#define LIGHTGRAY 7
144#define BLUE 8
145#define CYAN 9
146#define MAGENTA 10
147
148void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
149void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
150void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
151
152void init_aliens( game *g, aliens *al );
153void draw_aliens( game *g, aliens *al );
154void update_aliens( game *g, aliens *al );
155void add_alien( game *g, aliens *al, int x, int y, int type );
156
157int init_graphics( void );
158void init_game( game *g );
159char get_key( void );
160void clear_graphics( void );
161void refresh_graphics( void );
162void end_graphics( void );
163
164player * create_player( game *g );
165void free_player( player *p );
166void draw_player( game *g, player *p );
167void update_player( game *g, player *p );
168
169void init_weapons( game *g, weapons *wp );
170void draw_weapons( game *g, weapons *wp );
171void update_weapons( game *g, weapons *wp );
172void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
173
174void init_bonus( game *g, bonus *bo );
175void draw_bonus( game *g, bonus *bo );
176void update_bonus( game *g, bonus *bo );
177void add_bonus( game *g, bonus *bo, int x, int y, int type );
178
179starfield * create_starfield( game *g );
180void draw_starfield( game *g, starfield *s );
181void update_starfield( game *g, starfield *s );
182void free_starfield( game *g, starfield *s );
183
184tunnel * create_tunnel( game *g, int w, int h );
185void free_tunnel( tunnel *t );
186void draw_tunnel( game *g, tunnel *t );
187void update_tunnel( game *g, tunnel *t );
188
189void init_explosions( game *g, explosions *ex );
190void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
191void draw_explosions( game *g, explosions *ex );
192void update_explosions( game *g, explosions *ex );
193
194void ceo_alert( void );
195
196int r00t( int a );
197
Note: See TracBrowser for help on using the repository browser.