updated on Fri Jan 20 04:00:45 UTC 2012
[aur-mirror.git] / xasteroids / 01_legacy.patch
blobb291b621a6f6f0c92249723c35b5b84c4ee76b1f
1 --- xasteroids-5.0.orig/xast.c
2 +++ xasteroids-5.0/xast.c
3 @@ -3,6 +3,13 @@
4 goetz@cs.buffalo.EDU
5 Version 5, 9 Feb 93
7 + Changes after version 5.0:
8 +
9 + Improved cursor-hiding.
10 + Arrow keys.
11 + ANSI-C cleanups.
12 + Use usleep() instead of a delay loop, when available.
14 Changes from version 4.3:
16 High score script.
17 @@ -27,16 +34,29 @@
18 Pat Ryan <pat@jaameri.gsfc.nasa.gov>
19 Craig Smith <csmith@cscs.UUCP>
20 Doug Merritt <doug@netcom.com>
21 + Stephen McCamant <alias@mcs.com>
22 Makefile by James Berg <berg@plains>
23 Hi score script by Chris Moore <moore@src.bae.co.uk>
24 Man page by David Partain <dpl@ida.liu.se>
26 #include <stdio.h> /* For NULL */
27 +#include <stdlib.h> /* For malloc(), rand() etc */
28 +#include <time.h> /* For time() */
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
31 -#include <X11/cursorfont.h> /* For erasing cursor - not important */
32 +#include <X11/keysym.h>
33 #include <math.h>
35 +#ifdef HAS_USLEEP
36 +#include <unistd.h>
37 +#endif
39 +#ifndef __STDC__
40 +define void
41 +#endif
43 +#define rand(rndint) rand() /* ??? */
45 /* Indexes for 1st dimension of obj */
46 /* The order they are in is important */
47 #define AST 0
48 @@ -68,10 +88,10 @@
49 #define M_BULLET 0.1
51 /* Keys */
52 -#define FIRE 'p'
53 -#define PAUSE 27 /* escape */
54 -#define SHIELD '`'
55 -#define THRUST 'o'
56 +#define FIRE XK_p
57 +#define PAUSE XK_Escape /* escape */
58 +#define SHIELD XK_grave /* ` */
59 +#define THRUST XK_o
61 #define BMAX 300 /* Max particles in a "boom" + 1 */
62 #define letheight 20 /* height of font */
63 @@ -121,6 +141,7 @@
64 shapesize[LASTSHAPE+1] = {44, 21, 10, 2, 1, SHIPSIZE+1, 35, 20},
65 shield_on;
67 +void
68 initasts()
69 { int i;
70 extern Objtype obj[SHIP+1];
71 @@ -143,6 +164,7 @@
72 obj[i].mass = M_BULLET;
73 } }
75 +void
76 makeasts()
77 { int i;
78 extern Objtype obj[SHIP+1];
79 @@ -163,7 +185,7 @@
80 if (a > 63)
81 obj[i].y = (double) a;
82 else obj[i].y = (double) height - a;
83 - a = rand(rndint); a = 4 - a>>5;
84 + a = rand(rndint); a = 4 - (a>>5);
85 obj[i].rot = (double) a;
86 a = rand(rndint);
87 obj[i].rotvel = ((double) a)/2048;
88 @@ -177,6 +199,7 @@
89 numasts = i;
92 +void
93 makeenemy() /* Start an enemy ship */
94 { extern Objtype obj[SHIP+1];
95 extern int height, level, rndint;
96 @@ -258,6 +281,7 @@
97 return 0;
100 +void
101 blastpair(i, j) /* Generate random velocity vector v. */
102 int i, j ; /* Add v to i, -v to j. */
103 { extern int rndint;
104 @@ -266,7 +290,7 @@
105 double vx, vy;
106 c = rand(rndint);
107 /* c = 4 - c>>5; if you need angles from -3 to 4 */
108 - c>>2; /* possibly save some time on sin/cos */
109 + c >>= 2; /* possibly save some time on sin/cos */
110 vx = cos((double) c); vy = sin((double) c);
111 obj[i].xvel = obj[i].xvel + vx;
112 obj[i].yvel = obj[i].yvel + vy;
113 @@ -282,6 +306,7 @@
114 #define rotinert(i) (double) (obj[i].mass*shapesize[obj[i].shape]*shapesize[obj[i].shape])
116 /* cause two objects to collide elastically */
117 +void
118 bounce(i, j)
119 int i,j;
121 @@ -345,6 +370,7 @@
122 obj[j].rotvel = temp;
125 +void
126 botline(disp, window, gc) /* Print status line text */
127 Display *disp;
128 Drawable window;
129 @@ -357,6 +383,7 @@
130 text, strlen(text));
133 +void
134 printss(disp, window, gc) /* Print ships and score */
135 Display *disp;
136 Drawable window;
137 @@ -389,6 +416,7 @@
138 XClearArea(disp, window, 340+(energy>>1), height+8, 8, 10, False);
141 +void
142 upscore(killer, up) /* Only award score for things the player shot */
143 int killer, up;
144 { extern int score;
145 @@ -397,6 +425,7 @@
148 /* boom, movebooms, drawbooms all by Peter Phillips */
149 +void
150 boom(ob, particles, duration)
151 int ob;
152 int particles;
153 @@ -429,6 +458,7 @@
156 /* move the various booms that are active */
157 +void
158 movebooms()
160 int i;
161 @@ -461,6 +491,7 @@
164 /* Draw the various booms */
165 +void
166 drawbooms(disp, window, gc)
167 Display *disp;
168 Drawable window;
169 @@ -481,6 +512,7 @@
173 +void
174 deletebooms() /* delete all booms */
175 { Boom b;
177 @@ -490,11 +522,12 @@
178 b = b->next;
181 +void
182 killast(killer, i)
183 int killer, i; /* i = Asteroid # to kill */
184 { extern Objtype obj[SHIP+1];
185 extern int numasts;
186 - int k, na, oldna;
187 + int k, na = 0, oldna;
189 if (obj[i].shape == ASTSHAPE1)
190 { na = nextast(); /* Could put 6 lines in a sub */
191 @@ -543,6 +576,8 @@
192 { boom(i, 9, 7);
193 obj[i].alive = 0; upscore(killer, 500);}
196 +void
197 moveobjs(crash)
198 int *crash;
199 { extern Objtype obj[SHIP+1];
200 @@ -585,6 +620,7 @@
204 +void
205 fire()
206 { extern Objtype obj[SHIP+1];
207 extern int width, nextbul;
208 @@ -603,6 +639,7 @@
209 nextbul++; if (nextbul == LASTBUL+1) nextbul = FBUL;
212 +void
213 hyper()
214 { extern Objtype obj[SHIP+1];
215 extern int width, height, rndint;
216 @@ -617,6 +654,7 @@
217 obj[SHIP].y = (double) i;
220 +void
221 vdraw(disp, window, gc, shape, x, y, rot)
222 Display *disp;
223 Drawable window;
224 @@ -639,6 +677,7 @@
225 XDrawLines (disp, window, gc, figure, numpairs[shape], CoordModePrevious);
228 +int
229 main(argc, argv)
230 int argc;
231 char **argv;
232 @@ -663,8 +702,8 @@
233 extern int level, numasts, rndint, ships, score, oldscore;
234 extern Objtype obj[SHIP+1];
235 unsigned char c; /* for rand */
236 - double *temp, dx, dy, dist;
237 - int crashed, flashon, len, pause = 0, delay = 64,
238 + double dx, dy, dist;
239 + int crashed, flashon, pause = 0, delay = 64,
240 enemycount, counter, counterstart = 1,
241 i, /* index for drawing objs, counting bullets */
242 r; /* radius of shield circle */
243 @@ -704,11 +743,30 @@
244 KeyPressMask | KeyReleaseMask | StructureNotifyMask);
245 XMapRaised (disp, window);
247 - /* Erase cursor. Just delete next 5 lines if any error. */
248 + /* Make cursor invisible. Just delete chunk if any error. */
249 cmap = XDefaultColormap(disp, screen);
250 XAllocNamedColor(disp, cmap, "Black", &exact, &black);
251 +#if 0 /* Easy way, but can leave a black spot */
252 +#include <X11/cursorfont.h>
253 cursor = XCreateFontCursor(disp, XC_dot);
254 XRecolorCursor(disp, cursor, &black, &black);
255 +#else /* Hard, good way */
256 + { unsigned wd, ht;
257 + Pixmap pm, maskpm;
258 + GC cleargc;
259 + XQueryBestCursor(disp, window, 1, 1, &wd, &ht);
260 + pm = XCreatePixmap(disp, window, wd, ht, 1);
261 + maskpm = XCreatePixmap(disp, window, wd, ht, 1);
262 + cleargc = XCreateGC(disp, pm, 0, 0);
263 + XFillRectangle(disp, pm, cleargc, 0, 0, wd, ht);
264 + XFillRectangle(disp, maskpm, cleargc, 0, 0, wd, ht);
265 + cursor = XCreatePixmapCursor(disp, pm, maskpm,
266 + &black, &black, 1, 1);
267 + XFreePixmap(disp, pm);
268 + XFreePixmap(disp, maskpm);
269 + XFreeGC(disp, cleargc);
271 +#endif
272 XDefineCursor(disp, window, cursor);
274 XFillRectangle (disp, pixmap, pmgc, 0, 0, width, height);
275 @@ -746,7 +804,7 @@
276 { XNextEvent(disp, &event);
277 switch (event.type)
278 { case MappingNotify:
279 - XRefreshKeyboardMapping (&event);
280 + XRefreshKeyboardMapping ((XMappingEvent *)&event);
281 break;
282 case ConfigureNotify:
283 width = event.xconfigure.width;
284 @@ -757,28 +815,29 @@
285 botline(disp, window, gc);
286 break;
287 case KeyPress:
288 - len = XLookupString (&event, text, 10, &key, 0);
289 - if (len == 1 && !shield_on) switch (text[0])
290 - { case 'e':
291 + key = XLookupKeysym ((XKeyEvent *)&event, 0);
292 + if (!shield_on) switch (key)
293 + { case XK_Left: case XK_e:
294 obj[SHIP].rotvel = obj[SHIP].rotvel - .1; break;
295 - case 'r':
296 + case XK_Right: case XK_r:
297 obj[SHIP].rotvel = obj[SHIP].rotvel + .1; break;
298 - case 'w':
299 + case XK_w:
300 obj[SHIP].rot -= pi/4; break;
301 - case 't':
302 + case XK_t:
303 obj[SHIP].rot += pi/4; break;
304 - case 'd':
305 + case XK_d:
306 obj[SHIP].rotvel = obj[SHIP].rotvel - .02; break;
307 - case 'f':
308 + case XK_f:
309 obj[SHIP].rotvel = obj[SHIP].rotvel + .02; break;
310 - case THRUST:
311 + case XK_Up: case THRUST:
312 obj[SHIP].xvel += cos(obj[SHIP].rot);
313 obj[SHIP].yvel += sin(obj[SHIP].rot);
314 obj[SHIP].shape = SHIPTHRSHAPE;
315 break;
316 + case XK_Control_L: case XK_Control_R:
317 case FIRE:
318 if (obj[SHIP].alive) fire(); break;
319 - case ' ':
320 + case XK_space:
321 if (obj[SHIP].alive)
322 { hyper(); flashon = 1;
323 /* NOT XSetForeground (disp, gc, bg);
324 @@ -787,35 +846,37 @@
325 XFillRectangle (disp, pixmap, pmgc, 0, 0, width, height);
327 break;
328 - case SHIELD:
329 + case XK_Down: case SHIELD:
330 if (energy)
331 { shield_on = 1;
332 obj[SHIP].shape = SHIPSHAPE;}
333 break;
334 - case '.': /* decrease delay */
335 + case XK_period: /* decrease delay */
336 if (delay > 1) delay >>=1; break;
337 - case ',': /* increase delay */
338 + case XK_comma: /* increase delay */
339 delay <<=1; break;
340 - case 'm': /* decrease drawscale - may go negative */
341 + case XK_m: /* decrease drawscale - may go negative */
342 drawscale -= .1; break;
343 - case 'n': /* increase drawscale */
344 + case XK_n: /* increase drawscale */
345 drawscale += .1; break;
346 - case '2': /* increase speedscale */
347 + case XK_2: /* increase speedscale */
348 speedscale += .1; break;
349 - case '1': /* decrease speedscale */
350 + case XK_1: /* decrease speedscale */
351 speedscale -= .1; break;
352 - case 'b': /* increase moves/update */
353 + case XK_b: /* increase moves/update */
354 counterstart++; break;
355 - case 'v': /* decrease moves/update */
356 + case XK_v: /* decrease moves/update */
357 if (counterstart > 1) counterstart--;
358 break;
359 case PAUSE: /* pause */
360 pause = 1 - pause; break;
361 - case '+': /* cheat */
362 + case XK_plus: /* cheat */
363 ships++; botline(disp, window, gc); break;
364 - case 'Q': /* quit */
365 - goto End;
366 - case 's': /* start new ship */
367 + case XK_q: /* quit */
368 + if (event.xkey.state & ShiftMask)
369 + goto End;
370 + break;
371 + case XK_s: /* start new ship */
372 if (!obj[SHIP].alive)
373 if (ships < 1) goto Newgame;
374 else goto Newship;
375 @@ -823,16 +884,16 @@
377 break;
378 case KeyRelease:
379 - len = XLookupString(&event, text, 10, &key, 0);
380 - if (len == 1) switch (text[0])
381 - { case 'e':
382 + key = XLookupKeysym((XKeyEvent *)&event, 0);
383 + switch (key)
384 + { case XK_Left: case XK_e:
385 obj[SHIP].rotvel = 0; break;
386 - case 'r':
387 + case XK_Right: case XK_r:
388 obj[SHIP].rotvel = 0; break;
389 - case THRUST:
390 + case XK_Up: case THRUST:
391 obj[SHIP].shape = SHIPSHAPE;
392 break;
393 - case SHIELD:
394 + case XK_Down: case SHIELD:
395 shield_on = 0; break;
397 /* break; */
398 @@ -850,7 +911,7 @@
399 botline(disp, window, gc);
401 /* Write copyright notice */
402 - if (!ships && blist == NULL)
403 + if (!ships)
404 { sprintf(text, "Xasteroids");
405 XDrawImageString (disp, pixmap, gc,
406 width/2-50, height/2-2*letheight,
407 @@ -917,7 +978,11 @@
409 else obj[ENEMYBUL].alive = 0;
411 +#ifdef HAS_USLEEP
412 + usleep(delay);
413 +#else
414 for (i = 0; i < delay; i++);
415 +#endif
419 --- xasteroids-5.0.orig/xast.docs
420 +++ xasteroids-5.0/xast.docs
421 @@ -4,16 +4,16 @@
423 Keypress Command
424 -------- -------
425 - e Rotate counterclockwise ("left")
426 - r Rotate clockwise ("right")
427 + e / <- Rotate counterclockwise ("left")
428 + r / -> Rotate clockwise ("right")
429 w Rotate 45 degrees counterclockwise
430 t Rotate 45 degrees clockwise
431 d Increase counterclockwise rotational velocity
432 f Increase clockwise rotational velocity
433 - o Thrust
434 - p Fire
435 + o / Up Arrow Thrust
436 + p / Control Fire
437 space Hyperspace
438 - ` Shields
439 + ` / Down Arrow Shields
440 s Start new ship in center of playing field
441 (Also used to start a new game)
442 esc Pause
443 @@ -42,6 +42,3 @@
445 Resize the window with your window manager
446 at any time for a different playing field.
448 -Use the command-line option -s on the xasteroids script
449 -to see the high score list.
450 --- xasteroids-5.0.orig/xast.man
451 +++ xasteroids-5.0/xast.man
452 @@ -1,9 +1,9 @@
453 -.TH xasteroids n
454 +.TH xasteroids 6
455 .SH NAME
456 xasteroids - X windows based asteroids style arcade game
457 .SH SYNOPSIS
458 -.ta 8n
459 -\fBxasteroids\fP
460 +.ta 6
461 +\fBxasteroids\fP [-s]
463 .SH DESCRIPTION
464 Make big rocks into little ones.
465 @@ -11,60 +11,70 @@
466 .SH COMMANDS
467 .I xasteroids
469 - e Rotate counterclockwise ("left")
470 - r Rotate clockwise ("right")
471 - w Rotate 45 degrees counterclockwise
472 - t Rotate 45 degrees clockwise
473 - d Increase counterclockwise rotational velocity
474 - f Increase clockwise rotational velocity
475 - o Thrust
476 - p Fire
477 - ` Shields
478 - space Hyperspace
479 - s Start new ship in center of playing field
480 - (Also used to start a new game)
481 - esc Pause
482 - Q Quit
483 +.ft CW
484 + e Left Arrow Rotate counterclockwise ("left")
485 + r Right Arrow Rotate clockwise ("right")
486 + w Rotate 45 degrees counterclockwise
487 + t Rotate 45 degrees clockwise
488 + d Increase CCWise rotational velocity
489 + f Increase clockwise rotational velocity
490 + o Up Arrow Thrust
491 + p Control Fire
492 + ` Down Arrow Shields
493 + space Hyperspace
494 + s Start new ship in center of playing field
495 + (Also used to start a new game)
496 + esc Pause
497 + Q Quit
498 +.ft R
500 Speed commands: Key associated with faster speed is to the right of its
501 - corresponding key associated with slower speed.
502 +corresponding key associated with slower speed.
504 - . Decrease delay: Speed game up
505 - , Increase delay: Slow the game down
506 - m Decrease size ("Minimize")
507 - n Increase size
508 - b Increase # of moves/frame
509 - v Decrease # of moves/frame
510 - 2 Increase scale of movement
511 - 1 Decrease scale of movement
512 +.ft CW
513 + . Decrease delay: Speed game up
514 + , Increase delay: Slow the game down
515 + m Decrease size ("Minimize")
516 + n Increase size
517 + b Increase # of moves/frame
518 + v Decrease # of moves/frame
519 + 2 Increase scale of movement
520 + 1 Decrease scale of movement
522 Object Score
524 - Big asteroid 25, or 2000*level if it is the last asteroid remaining
525 - Medium asteroid 50, or 500*level if it is the last asteroid remaining
526 + Big asteroid 25, or
527 + 2000*level if last asteroid remaining
528 + Medium asteroid 50, or
529 + 500*level if last asteroid remaining
530 Little asteroid 100
531 Enemy spaceship 500
532 Enemy bullet 500
533 +.ft R
535 Commands can only be entered when the mouse pointer is in the
536 asteroids window.
538 Resize the window with your window manager
539 at any time for a different playing field.
541 -.SH OPTIONS
542 -.I xasteroids [-s]
543 --s Display high scores without running game.
545 .SH AUTHOR
546 Phil Goetz
548 goetz@cs.Buffalo.EDU
549 .SH CONTRIBUTORS
550 -Peter Phillips pphillip@cs.ubc.ca
551 -Pat Ryan pat@jaameri.gsfc.nasa.gov
552 -Craig Smith csmith@cscs.UUCP
553 -Doug Merritt doug@netcom.com
554 -James Berg berg@plains (makefile)
555 -Chris Moore moore@src.bae.co.uk (hi score script)
556 -David Partain dlp@ida.liu.se (original man page)
557 +Peter Phillips <pphillip@cs.ubc.ca>
558 +.br
559 +Pat Ryan <pat@jaameri.gsfc.nasa.gov>
560 +.br
561 +Craig Smith <csmith@cscs.UUCP>
562 +.br
563 +Doug Merritt <doug@netcom.com>
564 +.br
565 +Stephen McCamant <alias@mcs.com>
566 +.br
567 +James Berg <berg@plains> (makefile)
568 +.br
569 +Chris Moore <moore@src.bae.co.uk> (hi score script)
570 +.br
571 +David Partain <dlp@ida.liu.se> (original man page)