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 | |
---|
22 | typedef struct |
---|
23 | { |
---|
24 | int w, h; |
---|
25 | |
---|
26 | } game; |
---|
27 | |
---|
28 | typedef struct |
---|
29 | { |
---|
30 | int w, h, *left, *right; |
---|
31 | |
---|
32 | } tunnel; |
---|
33 | |
---|
34 | typedef 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 | |
---|
44 | typedef 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 | |
---|
55 | typedef struct |
---|
56 | { |
---|
57 | int x[SHOTS]; |
---|
58 | int y[SHOTS]; |
---|
59 | int v[SHOTS]; |
---|
60 | |
---|
61 | } weapons; |
---|
62 | |
---|
63 | typedef struct |
---|
64 | { |
---|
65 | int x, y; |
---|
66 | int dir; |
---|
67 | int weapon; |
---|
68 | |
---|
69 | } player; |
---|
70 | |
---|
71 | typedef 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 | |
---|
91 | void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ); |
---|
92 | void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ); |
---|
93 | void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ); |
---|
94 | |
---|
95 | void init_aliens( game *g, aliens *al ); |
---|
96 | void draw_aliens( game *g, aliens *al ); |
---|
97 | void update_aliens( game *g, aliens *al ); |
---|
98 | void add_alien( game *g, aliens *al, int x, int y ); |
---|
99 | |
---|
100 | int init_graphics( void ); |
---|
101 | void init_game( game *g ); |
---|
102 | char get_key( void ); |
---|
103 | void clear_graphics( void ); |
---|
104 | void refresh_graphics( void ); |
---|
105 | void end_graphics( void ); |
---|
106 | |
---|
107 | player * create_player( game *g ); |
---|
108 | void free_player( player *p ); |
---|
109 | void draw_player( game *g, player *p ); |
---|
110 | void update_player( game *g, player *p ); |
---|
111 | |
---|
112 | void init_weapons( game *g, weapons *wp ); |
---|
113 | void draw_weapons( game *g, weapons *wp ); |
---|
114 | void update_weapons( game *g, weapons *wp ); |
---|
115 | void add_weapon( game *g, weapons *wp, int x, int y ); |
---|
116 | |
---|
117 | void init_starfield( game *g, starfield *s ); |
---|
118 | void draw_starfield( game *g, starfield *s ); |
---|
119 | void update_starfield( game *g, starfield *s ); |
---|
120 | |
---|
121 | tunnel * create_tunnel( game *g, int w, int h ); |
---|
122 | void free_tunnel( tunnel *t ); |
---|
123 | void draw_tunnel( game *g, tunnel *t ); |
---|
124 | void update_tunnel( game *g, tunnel *t ); |
---|
125 | |
---|
126 | void init_explosions( game *g, explosions *ex ); |
---|
127 | void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ); |
---|
128 | void draw_explosions( game *g, explosions *ex ); |
---|
129 | void update_explosions( game *g, explosions *ex ); |
---|
130 | |
---|