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

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