1 /*
2 Copyright notice:
3 
4 This is mine.  I'm only letting you use it.  Period.  Feel free to rip off
5 any of the code you see fit, but have the courtesy to give me credit.
6 Otherwise great hairy beasties will rip your eyes out and eat your flesh
7 when you least expect it.
8 
9 Jonny Goldman <jonathan@think.com>
10 
11 Wed May  8 1991
12 */
13 
14 /* vaders.h - definitions of vaders data structures. */
15 
16 #ifndef _vaders_h
17 #define _vaders_h
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <math.h>
22 #include <X11/Xlib.h>
23 #include <X11/Xos.h>
24 
25 /* #include <X11/Xutil.h> */
26 #include <X11/cursorfont.h>
27 
28 #include <X11/IntrinsicP.h>
29 #include <X11/StringDefs.h>
30 
31 #include <X11/Xaw/Command.h>
32 
33 #include <libintl.h>
34 
35 #ifndef XtRFloat
36 #define XtRFloat "Float"
37 #endif
38 
39 #define rint(x) ((int) (x))
40 #define MIN(x, y)	((x) < (y) ? (x) : (y))
41 #define MAX(x, y)	((x) > (y) ? (x) : (y))
42 
43 #define VWIDTH 		240
44 #define IWIDTH		 75
45 #define VHEIGHT 	190
46 
47 #ifndef M_PI
48 #define	M_PI	3.14159265358979323846
49 #define	M_PI_2	1.57079632679489661923
50 #define	M_PI_4	0.78539816339744830962
51 #endif
52 
53 #ifdef MAIN
54 #define ext
55 #else
56 #define ext extern
57 #endif
58 
59 /*
60  * Definitions to make us act as a widget.
61  */
62 
63 /* New fields for the Vaders widget class record */
64 typedef struct {
65      int mumble;   /* No new procedures */
66 } VadersClassPart;
67 
68 /* Full class record declaration */
69 typedef struct _VadersClassRec {
70     CoreClassPart       core_class;
71     VadersClassPart    vaders_class;
72 } VadersClassRec;
73 
74 extern VadersClassRec vadersClassRec;
75 extern WidgetClass vadersWidgetClass;
76 
77 /* New fields for the Vaders widget record */
78 typedef struct _VadersPart {
79     int dummy;
80 } VadersPart;
81 
82 
83 
84 /* Full instance record declaration */
85 
86 typedef struct _VadersRec {
87     CorePart core;
88     VadersPart vaders;
89 } VadersRec, *VadersWidget;
90 
91 
92 
93 /*
94  * Application resources
95  */
96 typedef struct {
97     int width, height;		/* Size of window. */
98     int scale;
99     Boolean debug;
100 
101     /* Base info: */
102     int basewait;		/* Number of milliseconds to wait between */
103 				/* moving base. */
104     Pixel basepixel;
105     Pixel buildingpixel;
106 
107     /* Vader info  */
108     Pixel vader1pixel;
109     Pixel vader2pixel;
110     Pixel vader3pixel;
111     int vaderwait;		/* Number of milliseconds to wait between */
112 				/* moving vaders. */
113 
114     /* Spacer info */
115     Pixel spacerpixel;
116     int spacerwait;		/* Number of milliseconds to wait between */
117 				/* moving spacers. */
118 
119     /* Shot info */
120     Pixel shotpixel;
121     Pixel vshotpixel;
122     int shotwait;
123     int vshotwait;
124     int maxshots;		/* How many shots are allowed to exist at */
125 				/* once. */
126     int maxvshots;		/* How many shots are allowed to exist at */
127 				/* once. */
128 
129     /* Score info */
130     Pixel scorepixel;
131 
132     Pixel defaultfore, defaultback;
133 
134     char *vaderfont;
135 } AppData;
136 
137 ext AppData app_data;
138 
139 #ifndef MAIN
140 #define scale		app_data.scale
141 #define debug		app_data.debug
142 #define basewait	app_data.basewait
143 #define basepixel	app_data.basepixel
144 #define buildingpixel	app_data.buildingpixel
145 #define vader1pixel	app_data.vader1pixel
146 #define vader2pixel	app_data.vader2pixel
147 #define vader3pixel	app_data.vader3pixel
148 #define vaderwait	app_data.vaderwait
149 #define spacerpixel	app_data.spacerpixel
150 #define spacerwait	app_data.spacerwait
151 #define shotpixel	app_data.shotpixel
152 #define vshotpixel	app_data.vshotpixel
153 #define shotwait	app_data.shotwait
154 #define vshotwait	app_data.vshotwait
155 #define maxshots	app_data.maxshots
156 #define maxvshots	app_data.maxvshots
157 #define scorepixel	app_data.scorepixel
158 #define defaultfore	app_data.defaultfore
159 #define defaultback	app_data.defaultback
160 #define vaderfont	app_data.vaderfont
161 #endif
162 
163 /*
164  * Actual vaders definitions.
165  */
166 
167 ext Widget pausebutton, infobutton;
168 
169 ext int level;
170 
171 ext Display *dpy;
172 ext Window gamewindow, labelwindow;
173 ext VadersWidget gamewidget, labelwidget;
174 ext int gamewidth, gameheight;
175 ext Widget toplevel;
176 ext int score;
177 ext int basesleft;
178 
179 /* Base info: */
180 
181 ext XtIntervalId basetimerid;
182 
183 extern Boolean basedestroyed;	/* TRUE if the base is non-existant */
184 
185 /* Vader info: */
186 
187 ext XtIntervalId vadertimerid;
188 
189 /* Spacer info */
190 
191 ext XtIntervalId spacertimerid;
192 ext int spacerappear;		/* same, but for the interval between appearances */
193 
194 extern Boolean spacer_shown;    	/* Currnet_Spacer is something */
195 extern int spacer_counter;		/* number of cycles to create a spacer */
196 
197 /* Shot info. */
198 
199 ext XtIntervalId shottimerid;
200 ext XtIntervalId vshottimerid;
201 extern int numshots;		/* how many shots (from the base) there are right now. */
202 extern int numvshots;		/* how many shots (from vaders) there are right now. */
203 
204 /* Score info */
205 
206 ext int bases, nextbonus, lastscore;
207 extern int hiscore;
208 
209 ext GC
210   foregc, backgc, basegc, buildinggc, vadergc[3],
211   shotgc, vshotgc, spacergc, scoregc;
212 
213 ext XImage *me_image;
214 
215 /* From widget.c */
216 
217 void Quit();
218 void Pause();
219 extern int paused;
220 void SuspendTimers();
221 void EnableTimers();
222 void ShowInfo();
223 
224 /* From base.c */
225 
226 void MoveBase();
227 void MoveLeft();
228 void MoveRight();
229 void Stop();
230 void Fire();
231 Boolean ShotHitsBase();
232 Boolean ShotHitsBuilding();
233 void InitBase();
234 void InitBuildings();
235 void PaintBase();
236 void PaintBasesLeft();
237 void DrawBuildings();
238 void ResetGame();
239 void ShowBase(int i, GC gc);
240 
241 /* From vaders.c */
242 
243 Boolean ShotHitsVader();
244 void MoveVaders();
245 void InitVaders();
246 void AddVShot();
247 void MoveVShots();
248 void CreateVaders();
249 void PaintAllVaders();
250 
251 /* from score.c */
252 
253 void InitScore();
254 void PaintScore();
255 void SaveScore();
256 
257 /* from spacer.c */
258 
259 Boolean ShotHitsSpacer();
260 void MoveSpacer();
261 void MakeSpacer();
262 void InitSpacers();
263 void PaintSpacer();
264 
265 /* From shot.c */
266 
267 void AddLine();
268 void AddShot();
269 void AddVshot();
270 void InitShot();
271 void MoveShots();
272 void MoveVshots();
273 void PaintAllShots();
274 
275 #endif _vaders_h
276