source: ttyvaders/trunk/common.h @ 12

Last change on this file since 12 was 12, checked in by Sam Hocevar, 20 years ago
  • First commit. Scrolling works, some weaponry, controls, tunnel blowing, the nuke is still ugly, almost no collision detection. Nice demo :)
File size: 2.7 KB
Line 
1
2#define STARS 50
3#define SHOTS 50
4#define ROCKS 10
5#define ALIENS 10
6#define EXPLOSIONS 20
7
8#ifdef USE_SLANG
9#   include <slang.h>
10#   define GFX_COLOR(x) SLsmg_set_color(x)
11#   define GFX_GOTO(x,y) SLsmg_gotorc(y,x)
12#   define GFX_WRITE(x) SLsmg_write_char(x)
13#else
14#   include <curses.h>
15#   define GFX_COLOR(x) attrset(COLOR_PAIR(x))
16#   define GFX_GOTO(x,y) move(y,x)
17#   define GFX_WRITE(x) addch(x)
18#endif
19
20#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
21
22typedef struct
23{
24    int w, h;
25
26} game;
27
28typedef struct
29{
30    int w, h, *left, *right;
31
32} tunnel;
33
34typedef struct
35{
36    int x[STARS];
37    int y[STARS];
38    int z[STARS];
39    char ch[STARS];
40    int c[STARS];
41
42} starfield;
43
44typedef struct
45{
46    int x[EXPLOSIONS];
47    int y[EXPLOSIONS];
48    int vx[EXPLOSIONS];
49    int vy[EXPLOSIONS];
50    int type[EXPLOSIONS];
51    int n[EXPLOSIONS];
52
53} explosions;
54
55typedef struct
56{
57    int x[SHOTS];
58    int y[SHOTS];
59    int v[SHOTS];
60
61} weapons;
62
63typedef struct
64{
65    int x, y;
66    int dir;
67    int weapon;
68
69} player;
70
71typedef struct
72{
73    int x[ALIENS];
74    int y[ALIENS];
75    int life[ALIENS];
76    int img[ALIENS];
77
78} aliens;
79
80#define BLACK 1
81#define GREEN 2
82#define YELLOW 3
83#define WHITE 4
84#define RED 5
85#define GRAY 6
86#define LIGHTGRAY 7
87#define BLUE 8
88#define CYAN 9
89#define MAGENTA 10
90
91void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
92void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
93void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
94
95void init_aliens( game *g, aliens *al );
96void draw_aliens( game *g, aliens *al );
97void update_aliens( game *g, aliens *al );
98void add_alien( game *g, aliens *al, int x, int y );
99
100int init_graphics( void );
101void init_game( game *g );
102char get_key( void );
103void clear_graphics( void );
104void refresh_graphics( void );
105void end_graphics( void );
106
107player * create_player( game *g );
108void free_player( player *p );
109void draw_player( game *g, player *p );
110void update_player( game *g, player *p );
111
112void init_weapons( game *g, weapons *wp );
113void draw_weapons( game *g, weapons *wp );
114void update_weapons( game *g, weapons *wp );
115void add_weapon( game *g, weapons *wp, int x, int y );
116
117void init_starfield( game *g, starfield *s );
118void draw_starfield( game *g, starfield *s );
119void update_starfield( game *g, starfield *s );
120
121tunnel * create_tunnel( game *g, int w, int h );
122void free_tunnel( tunnel *t );
123void draw_tunnel( game *g, tunnel *t );
124void update_tunnel( game *g, tunnel *t );
125
126void init_explosions( game *g, explosions *ex );
127void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
128void draw_explosions( game *g, explosions *ex );
129void update_explosions( game *g, explosions *ex );
130
Note: See TracBrowser for help on using the repository browser.