source: ttyvaders/trunk/common.h @ 16

Last change on this file since 16 was 16, checked in by Sam Hocevar, 18 years ago
  • moved nuke from explosions to weapons.
  • used a cool Bresenham algorithm to draw the nuke circles.
  • nuke collides with aliens.
File size: 2.8 KB
Line 
1
2#define STARS 50
3#define WEAPONS 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 GFX_WRITETO(x,y,c) do{ GFX_GOTO(x,y); GFX_WRITE(c); }while(0)
21
22#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
23
24typedef struct
25{
26    int w, h;
27
28} game;
29
30typedef struct
31{
32    int w, h, *left, *right;
33
34} tunnel;
35
36typedef struct
37{
38    int x[STARS];
39    int y[STARS];
40    int z[STARS];
41    char ch[STARS];
42    int c[STARS];
43
44} starfield;
45
46typedef struct
47{
48    int x[EXPLOSIONS];
49    int y[EXPLOSIONS];
50    int vx[EXPLOSIONS];
51    int vy[EXPLOSIONS];
52    int type[EXPLOSIONS];
53    int n[EXPLOSIONS];
54
55} explosions;
56
57typedef struct
58{
59    int x[WEAPONS];
60    int y[WEAPONS];
61    int v[WEAPONS];
62    int n[WEAPONS];
63    int type[WEAPONS];
64
65} weapons;
66
67typedef struct
68{
69    int x, y;
70    int dir;
71    int weapon, nuke;
72
73} player;
74
75typedef struct
76{
77    int x[ALIENS];
78    int y[ALIENS];
79    int life[ALIENS];
80    int img[ALIENS];
81
82} aliens;
83
84#define BLACK 1
85#define GREEN 2
86#define YELLOW 3
87#define WHITE 4
88#define RED 5
89#define GRAY 6
90#define LIGHTGRAY 7
91#define BLUE 8
92#define CYAN 9
93#define MAGENTA 10
94
95void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex );
96void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex );
97void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex );
98
99void init_aliens( game *g, aliens *al );
100void draw_aliens( game *g, aliens *al );
101void update_aliens( game *g, aliens *al );
102void add_alien( game *g, aliens *al, int x, int y );
103
104int init_graphics( void );
105void init_game( game *g );
106char get_key( void );
107void clear_graphics( void );
108void refresh_graphics( void );
109void end_graphics( void );
110
111player * create_player( game *g );
112void free_player( player *p );
113void draw_player( game *g, player *p );
114void update_player( game *g, player *p );
115
116void init_weapons( game *g, weapons *wp );
117void draw_weapons( game *g, weapons *wp );
118void update_weapons( game *g, weapons *wp );
119void add_weapon( game *g, weapons *wp, int x, int y, int type );
120
121void init_starfield( game *g, starfield *s );
122void draw_starfield( game *g, starfield *s );
123void update_starfield( game *g, starfield *s );
124
125tunnel * create_tunnel( game *g, int w, int h );
126void free_tunnel( tunnel *t );
127void draw_tunnel( game *g, tunnel *t );
128void update_tunnel( game *g, tunnel *t );
129
130void init_explosions( game *g, explosions *ex );
131void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type );
132void draw_explosions( game *g, explosions *ex );
133void update_explosions( game *g, explosions *ex );
134
Note: See TracBrowser for help on using the repository browser.