1 | |
---|
2 | #define STARS 50 |
---|
3 | #define WEAPONS 50 |
---|
4 | #define BONUS 30 |
---|
5 | #define ALIENS 30 |
---|
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_putchar(x) SLsmg_write_char(x) |
---|
13 | # define gfx_putstr(x) SLsmg_write_string(x) |
---|
14 | #else |
---|
15 | # include <curses.h> |
---|
16 | # define gfx_color(x) attrset(COLOR_PAIR(x)) |
---|
17 | # define gfx_goto(x,y) move(y,x) |
---|
18 | # define gfx_putchar(x) addch(x) |
---|
19 | # define gfx_putstr(x) addstr(x) |
---|
20 | #endif |
---|
21 | |
---|
22 | #define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) |
---|
23 | |
---|
24 | #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) |
---|
25 | |
---|
26 | typedef struct |
---|
27 | { |
---|
28 | int w, h, *left, *right; |
---|
29 | |
---|
30 | } tunnel; |
---|
31 | |
---|
32 | typedef struct |
---|
33 | { |
---|
34 | int x[STARS]; |
---|
35 | int y[STARS]; |
---|
36 | int z[STARS]; |
---|
37 | char ch[STARS]; |
---|
38 | int c[STARS]; |
---|
39 | |
---|
40 | } starfield; |
---|
41 | |
---|
42 | typedef struct |
---|
43 | { |
---|
44 | enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS]; |
---|
45 | int x[EXPLOSIONS]; |
---|
46 | int y[EXPLOSIONS]; |
---|
47 | int vx[EXPLOSIONS]; |
---|
48 | int vy[EXPLOSIONS]; |
---|
49 | int n[EXPLOSIONS]; |
---|
50 | |
---|
51 | } explosions; |
---|
52 | |
---|
53 | typedef struct |
---|
54 | { |
---|
55 | enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE } type[WEAPONS]; |
---|
56 | int x[WEAPONS]; |
---|
57 | int y[WEAPONS]; |
---|
58 | int x2[WEAPONS]; |
---|
59 | int y2[WEAPONS]; |
---|
60 | int x3[WEAPONS]; |
---|
61 | int y3[WEAPONS]; |
---|
62 | int vx[WEAPONS]; |
---|
63 | int vy[WEAPONS]; |
---|
64 | int n[WEAPONS]; |
---|
65 | |
---|
66 | } weapons; |
---|
67 | |
---|
68 | typedef struct |
---|
69 | { |
---|
70 | enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS]; |
---|
71 | int x[BONUS]; |
---|
72 | int y[BONUS]; |
---|
73 | int n[BONUS]; |
---|
74 | |
---|
75 | } bonus; |
---|
76 | |
---|
77 | typedef struct |
---|
78 | { |
---|
79 | int x, y; |
---|
80 | int dir; |
---|
81 | int weapon, nuke; |
---|
82 | |
---|
83 | } player; |
---|
84 | |
---|
85 | typedef struct |
---|
86 | { |
---|
87 | enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS]; |
---|
88 | int x[ALIENS]; |
---|
89 | int y[ALIENS]; |
---|
90 | int life[ALIENS]; |
---|
91 | int img[ALIENS]; |
---|
92 | |
---|
93 | } aliens; |
---|
94 | |
---|
95 | typedef struct |
---|
96 | { |
---|
97 | int w, h; |
---|
98 | |
---|
99 | starfield *sf; |
---|
100 | weapons *wp; |
---|
101 | explosions *ex; |
---|
102 | tunnel *t; |
---|
103 | player *p; |
---|
104 | aliens *al; |
---|
105 | bonus *bo; |
---|
106 | |
---|
107 | } game; |
---|
108 | |
---|
109 | #define BLACK 1 |
---|
110 | #define GREEN 2 |
---|
111 | #define YELLOW 3 |
---|
112 | #define WHITE 4 |
---|
113 | #define RED 5 |
---|
114 | #define GRAY 6 |
---|
115 | #define LIGHTGRAY 7 |
---|
116 | #define BLUE 8 |
---|
117 | #define CYAN 9 |
---|
118 | #define MAGENTA 10 |
---|
119 | |
---|
120 | void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ); |
---|
121 | void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ); |
---|
122 | void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ); |
---|
123 | |
---|
124 | void init_aliens( game *g, aliens *al ); |
---|
125 | void draw_aliens( game *g, aliens *al ); |
---|
126 | void update_aliens( game *g, aliens *al ); |
---|
127 | void add_alien( game *g, aliens *al, int x, int y, int type ); |
---|
128 | |
---|
129 | int init_graphics( void ); |
---|
130 | void init_game( game *g ); |
---|
131 | char get_key( void ); |
---|
132 | void clear_graphics( void ); |
---|
133 | void refresh_graphics( void ); |
---|
134 | void end_graphics( void ); |
---|
135 | |
---|
136 | player * create_player( game *g ); |
---|
137 | void free_player( player *p ); |
---|
138 | void draw_player( game *g, player *p ); |
---|
139 | void update_player( game *g, player *p ); |
---|
140 | |
---|
141 | void init_weapons( game *g, weapons *wp ); |
---|
142 | void draw_weapons( game *g, weapons *wp ); |
---|
143 | void update_weapons( game *g, weapons *wp ); |
---|
144 | void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ); |
---|
145 | |
---|
146 | void init_bonus( game *g, bonus *bo ); |
---|
147 | void draw_bonus( game *g, bonus *bo ); |
---|
148 | void update_bonus( game *g, bonus *bo ); |
---|
149 | void add_bonus( game *g, bonus *bo, int x, int y, int type ); |
---|
150 | |
---|
151 | void init_starfield( game *g, starfield *s ); |
---|
152 | void draw_starfield( game *g, starfield *s ); |
---|
153 | void update_starfield( game *g, starfield *s ); |
---|
154 | |
---|
155 | tunnel * create_tunnel( game *g, int w, int h ); |
---|
156 | void free_tunnel( tunnel *t ); |
---|
157 | void draw_tunnel( game *g, tunnel *t ); |
---|
158 | void update_tunnel( game *g, tunnel *t ); |
---|
159 | |
---|
160 | void init_explosions( game *g, explosions *ex ); |
---|
161 | void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ); |
---|
162 | void draw_explosions( game *g, explosions *ex ); |
---|
163 | void update_explosions( game *g, explosions *ex ); |
---|
164 | |
---|