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 1456 2006-12-11 15:55:56Z sam $ |
---|
7 | * |
---|
8 | * This program is free software. It commes without any warranty, to |
---|
9 | * the extent permitted by applicable law. You can redistribute it |
---|
10 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
11 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * Compile-time limits |
---|
17 | */ |
---|
18 | #define STARS 50 |
---|
19 | #define WEAPONS 200 |
---|
20 | #define BONUS 30 |
---|
21 | #define ALIENS 30 |
---|
22 | #define EXPLOSIONS 200 |
---|
23 | |
---|
24 | /* |
---|
25 | * Game defines |
---|
26 | */ |
---|
27 | #define MAX_LIFE 1000 |
---|
28 | #define MAX_SPECIAL 200 |
---|
29 | |
---|
30 | #define COST_NUKE (100*MAX_SPECIAL/100) |
---|
31 | #define COST_BEAM (75*MAX_SPECIAL/100) |
---|
32 | #define COST_FRAGBOMB (50*MAX_SPECIAL/100) |
---|
33 | |
---|
34 | /* |
---|
35 | * Graphics primitives |
---|
36 | */ |
---|
37 | #include <caca.h> |
---|
38 | |
---|
39 | /* |
---|
40 | * Useful macros |
---|
41 | */ |
---|
42 | #define GET_MAX(a,b) ((a)>(b)?(a):(b)) |
---|
43 | #define GET_MIN(a,b) ((a)<(b)?(a):(b)) |
---|
44 | |
---|
45 | /* |
---|
46 | * Game structures |
---|
47 | */ |
---|
48 | typedef struct |
---|
49 | { |
---|
50 | int w, h, *left, *right; |
---|
51 | |
---|
52 | } tunnel; |
---|
53 | |
---|
54 | typedef struct |
---|
55 | { |
---|
56 | int x, y, z, c; |
---|
57 | char ch; |
---|
58 | |
---|
59 | } starfield; |
---|
60 | |
---|
61 | typedef struct |
---|
62 | { |
---|
63 | enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS]; |
---|
64 | int x[EXPLOSIONS]; |
---|
65 | int y[EXPLOSIONS]; |
---|
66 | int vx[EXPLOSIONS]; |
---|
67 | int vy[EXPLOSIONS]; |
---|
68 | int n[EXPLOSIONS]; |
---|
69 | |
---|
70 | } explosions; |
---|
71 | |
---|
72 | typedef struct |
---|
73 | { |
---|
74 | enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS]; |
---|
75 | int x[WEAPONS]; |
---|
76 | int y[WEAPONS]; |
---|
77 | int x2[WEAPONS]; |
---|
78 | int y2[WEAPONS]; |
---|
79 | int x3[WEAPONS]; |
---|
80 | int y3[WEAPONS]; |
---|
81 | int vx[WEAPONS]; |
---|
82 | int vy[WEAPONS]; |
---|
83 | int n[WEAPONS]; |
---|
84 | |
---|
85 | } weapons; |
---|
86 | |
---|
87 | typedef struct |
---|
88 | { |
---|
89 | enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS]; |
---|
90 | int x[BONUS]; |
---|
91 | int y[BONUS]; |
---|
92 | int n[BONUS]; |
---|
93 | |
---|
94 | } bonus; |
---|
95 | |
---|
96 | typedef struct |
---|
97 | { |
---|
98 | int x, y; |
---|
99 | int vx, vy; |
---|
100 | int weapon, special; |
---|
101 | int life, dead; |
---|
102 | |
---|
103 | } player; |
---|
104 | |
---|
105 | typedef struct |
---|
106 | { |
---|
107 | enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS]; |
---|
108 | int x[ALIENS]; |
---|
109 | int y[ALIENS]; |
---|
110 | int life[ALIENS]; |
---|
111 | int img[ALIENS]; |
---|
112 | |
---|
113 | } aliens; |
---|
114 | |
---|
115 | typedef struct |
---|
116 | { |
---|
117 | int w, h; |
---|
118 | int x, y; |
---|
119 | int frame; |
---|
120 | |
---|
121 | } box; |
---|
122 | |
---|
123 | typedef struct |
---|
124 | { |
---|
125 | int w, h; |
---|
126 | |
---|
127 | cucul_canvas_t *cv; |
---|
128 | caca_display_t *dp; |
---|
129 | |
---|
130 | starfield *sf; |
---|
131 | weapons *wp; |
---|
132 | explosions *ex; |
---|
133 | tunnel *t; |
---|
134 | player *p; |
---|
135 | aliens *al; |
---|
136 | bonus *bo; |
---|
137 | |
---|
138 | } game; |
---|
139 | |
---|
140 | void intro(game *g); |
---|
141 | |
---|
142 | /* |
---|
143 | * From aliens.c |
---|
144 | */ |
---|
145 | void init_aliens(game *, aliens *); |
---|
146 | void draw_aliens(game *, aliens *); |
---|
147 | void update_aliens(game *, aliens *); |
---|
148 | void add_alien(game *, aliens *, int, int, int); |
---|
149 | |
---|
150 | /* |
---|
151 | * From bonus.c |
---|
152 | */ |
---|
153 | void init_bonus(game *, bonus *); |
---|
154 | void draw_bonus(game *, bonus *); |
---|
155 | void update_bonus(game *, bonus *); |
---|
156 | void add_bonus(game *, bonus *, int, int, int); |
---|
157 | |
---|
158 | /* |
---|
159 | * From box.c |
---|
160 | */ |
---|
161 | box * create_box(game *, int, int, int, int); |
---|
162 | void draw_box(game *, box *); |
---|
163 | void free_box(box *); |
---|
164 | |
---|
165 | /* |
---|
166 | * From ceo.c |
---|
167 | */ |
---|
168 | void ceo_alert(game *); |
---|
169 | |
---|
170 | /* |
---|
171 | * From collide.c |
---|
172 | */ |
---|
173 | void collide_weapons_tunnel(game *, weapons *, tunnel *, explosions *); |
---|
174 | void collide_weapons_aliens(game *, weapons *, aliens *, explosions *); |
---|
175 | void collide_player_tunnel(game *, player *, tunnel *, explosions *); |
---|
176 | |
---|
177 | /* |
---|
178 | * From explosions.c |
---|
179 | */ |
---|
180 | void init_explosions(game *, explosions *); |
---|
181 | void add_explosion(game *, explosions *, int, int, int, int, int); |
---|
182 | void draw_explosions(game *, explosions *); |
---|
183 | void update_explosions(game *, explosions *); |
---|
184 | |
---|
185 | /* |
---|
186 | * From overlay.c |
---|
187 | */ |
---|
188 | void draw_status(game *); |
---|
189 | |
---|
190 | /* |
---|
191 | * From player.c |
---|
192 | */ |
---|
193 | player * create_player(game *); |
---|
194 | void free_player(player *); |
---|
195 | void draw_player(game *, player *); |
---|
196 | void update_player(game *, player *); |
---|
197 | |
---|
198 | /* |
---|
199 | * From starfield.c |
---|
200 | */ |
---|
201 | starfield * create_starfield(game *); |
---|
202 | void draw_starfield(game *, starfield *); |
---|
203 | void update_starfield(game *, starfield *); |
---|
204 | void free_starfield(game *, starfield *); |
---|
205 | |
---|
206 | /* |
---|
207 | * From tunnel.c |
---|
208 | */ |
---|
209 | tunnel * create_tunnel(game *, int, int); |
---|
210 | void free_tunnel(tunnel *); |
---|
211 | void draw_tunnel(game *, tunnel *); |
---|
212 | void update_tunnel(game *, tunnel *); |
---|
213 | |
---|
214 | /* |
---|
215 | * From weapons.c |
---|
216 | */ |
---|
217 | void init_weapons(game *, weapons *); |
---|
218 | void draw_weapons(game *, weapons *); |
---|
219 | void update_weapons(game *, weapons *); |
---|
220 | void add_weapon(game *, weapons *, int, int, int, int, int); |
---|
221 | |
---|