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,v 1.7 2002/12/22 18:44:12 sam Exp $ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | #define STARS 50 |
---|
24 | #define WEAPONS 100 |
---|
25 | #define BONUS 30 |
---|
26 | #define ALIENS 30 |
---|
27 | #define EXPLOSIONS 100 |
---|
28 | |
---|
29 | #ifdef USE_SLANG |
---|
30 | # include <slang.h> |
---|
31 | # define gfx_color(x) SLsmg_set_color(x) |
---|
32 | # define gfx_goto(x,y) SLsmg_gotorc(y,x) |
---|
33 | # define gfx_putchar(x) SLsmg_write_char(x) |
---|
34 | # define gfx_putstr(x) SLsmg_write_string(x) |
---|
35 | #else |
---|
36 | # include <curses.h> |
---|
37 | # define gfx_color(x) attrset(COLOR_PAIR(x)) |
---|
38 | # define gfx_goto(x,y) move(y,x) |
---|
39 | # define gfx_putchar(x) addch(x) |
---|
40 | # define gfx_putstr(x) addstr(x) |
---|
41 | #endif |
---|
42 | |
---|
43 | #define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) |
---|
44 | |
---|
45 | #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) |
---|
46 | |
---|
47 | typedef struct |
---|
48 | { |
---|
49 | int w, h, *left, *right; |
---|
50 | |
---|
51 | } tunnel; |
---|
52 | |
---|
53 | typedef struct |
---|
54 | { |
---|
55 | int x[STARS]; |
---|
56 | int y[STARS]; |
---|
57 | int z[STARS]; |
---|
58 | char ch[STARS]; |
---|
59 | int c[STARS]; |
---|
60 | |
---|
61 | } starfield; |
---|
62 | |
---|
63 | typedef struct |
---|
64 | { |
---|
65 | enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS]; |
---|
66 | int x[EXPLOSIONS]; |
---|
67 | int y[EXPLOSIONS]; |
---|
68 | int vx[EXPLOSIONS]; |
---|
69 | int vy[EXPLOSIONS]; |
---|
70 | int n[EXPLOSIONS]; |
---|
71 | |
---|
72 | } explosions; |
---|
73 | |
---|
74 | typedef struct |
---|
75 | { |
---|
76 | enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB } type[WEAPONS]; |
---|
77 | int x[WEAPONS]; |
---|
78 | int y[WEAPONS]; |
---|
79 | int x2[WEAPONS]; |
---|
80 | int y2[WEAPONS]; |
---|
81 | int x3[WEAPONS]; |
---|
82 | int y3[WEAPONS]; |
---|
83 | int vx[WEAPONS]; |
---|
84 | int vy[WEAPONS]; |
---|
85 | int n[WEAPONS]; |
---|
86 | |
---|
87 | } weapons; |
---|
88 | |
---|
89 | typedef struct |
---|
90 | { |
---|
91 | enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS]; |
---|
92 | int x[BONUS]; |
---|
93 | int y[BONUS]; |
---|
94 | int n[BONUS]; |
---|
95 | |
---|
96 | } bonus; |
---|
97 | |
---|
98 | typedef struct |
---|
99 | { |
---|
100 | int x, y; |
---|
101 | int dir; |
---|
102 | int weapon, nuke; |
---|
103 | |
---|
104 | } player; |
---|
105 | |
---|
106 | typedef struct |
---|
107 | { |
---|
108 | enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS]; |
---|
109 | int x[ALIENS]; |
---|
110 | int y[ALIENS]; |
---|
111 | int life[ALIENS]; |
---|
112 | int img[ALIENS]; |
---|
113 | |
---|
114 | } aliens; |
---|
115 | |
---|
116 | typedef struct |
---|
117 | { |
---|
118 | int w, h; |
---|
119 | |
---|
120 | starfield *sf; |
---|
121 | weapons *wp; |
---|
122 | explosions *ex; |
---|
123 | tunnel *t; |
---|
124 | player *p; |
---|
125 | aliens *al; |
---|
126 | bonus *bo; |
---|
127 | |
---|
128 | } game; |
---|
129 | |
---|
130 | #define BLACK 1 |
---|
131 | #define GREEN 2 |
---|
132 | #define YELLOW 3 |
---|
133 | #define WHITE 4 |
---|
134 | #define RED 5 |
---|
135 | #define GRAY 6 |
---|
136 | #define LIGHTGRAY 7 |
---|
137 | #define BLUE 8 |
---|
138 | #define CYAN 9 |
---|
139 | #define MAGENTA 10 |
---|
140 | |
---|
141 | void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ); |
---|
142 | void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ); |
---|
143 | void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ); |
---|
144 | |
---|
145 | void init_aliens( game *g, aliens *al ); |
---|
146 | void draw_aliens( game *g, aliens *al ); |
---|
147 | void update_aliens( game *g, aliens *al ); |
---|
148 | void add_alien( game *g, aliens *al, int x, int y, int type ); |
---|
149 | |
---|
150 | int init_graphics( void ); |
---|
151 | void init_game( game *g ); |
---|
152 | char get_key( void ); |
---|
153 | void clear_graphics( void ); |
---|
154 | void refresh_graphics( void ); |
---|
155 | void end_graphics( void ); |
---|
156 | |
---|
157 | player * create_player( game *g ); |
---|
158 | void free_player( player *p ); |
---|
159 | void draw_player( game *g, player *p ); |
---|
160 | void update_player( game *g, player *p ); |
---|
161 | |
---|
162 | void init_weapons( game *g, weapons *wp ); |
---|
163 | void draw_weapons( game *g, weapons *wp ); |
---|
164 | void update_weapons( game *g, weapons *wp ); |
---|
165 | void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ); |
---|
166 | |
---|
167 | void init_bonus( game *g, bonus *bo ); |
---|
168 | void draw_bonus( game *g, bonus *bo ); |
---|
169 | void update_bonus( game *g, bonus *bo ); |
---|
170 | void add_bonus( game *g, bonus *bo, int x, int y, int type ); |
---|
171 | |
---|
172 | void init_starfield( game *g, starfield *s ); |
---|
173 | void draw_starfield( game *g, starfield *s ); |
---|
174 | void update_starfield( game *g, starfield *s ); |
---|
175 | |
---|
176 | tunnel * create_tunnel( game *g, int w, int h ); |
---|
177 | void free_tunnel( tunnel *t ); |
---|
178 | void draw_tunnel( game *g, tunnel *t ); |
---|
179 | void update_tunnel( game *g, tunnel *t ); |
---|
180 | |
---|
181 | void init_explosions( game *g, explosions *ex ); |
---|
182 | void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ); |
---|
183 | void draw_explosions( game *g, explosions *ex ); |
---|
184 | void update_explosions( game *g, explosions *ex ); |
---|
185 | |
---|
186 | void ceo_alert( void ); |
---|
187 | |
---|