v08i068: xinvaders -- space invaders for X, Patch1, Part01/01

Jonny Goldman jgoldman at parc.xerox.com
Sat Aug 11 04:27:22 AEST 1990


Submitted-by: Jonny Goldman <jgoldman at parc.xerox.com>
Posting-number: Volume 8, Issue 68
Archive-name: xinvaders/patch1
Patch-To: xinvaders: Volume 8, Issue 62-66

Here's the first round of patches to the game.  They aren't really
bug-fixes, but rather small enhancements.  There are basically three
patches:

1.  To allow users to compile with X11R3
2.  expanding the images of the invaders by 1 bit and eliminating the erase
    to improve performance (thus allowing it to run on slower machines, like
    Sun 3's).
3.  To allow the specification of a bitmap directory in the Xresources.
    For example:

	 Vaders*BitmapDirectory:            /usr/local/xgames/xinvaders/

    The trailing `/' is important, and `"' should not be used (unless you
    really mean it).

The files that have changed are:

diff -c xinvaders.old/Makefile xinvaders/Makefile
diff -c xinvaders.old/base.c xinvaders/base.c
diff -c xinvaders.old/main.c xinvaders/main.c
diff -c xinvaders.old/patchlevel.h xinvaders/patchlevel.h
diff -c xinvaders.old/shot.c xinvaders/shot.c
diff -c xinvaders.old/spacers.c xinvaders/spacers.c
diff -c xinvaders.old/vader1a.bit xinvaders/vader1a.bit
diff -c xinvaders.old/vader1b.bit xinvaders/vader1b.bit
diff -c xinvaders.old/vader2a.bit xinvaders/vader2a.bit
diff -c xinvaders.old/vader2b.bit xinvaders/vader2b.bit
diff -c xinvaders.old/vader3a.bit xinvaders/vader3a.bit
diff -c xinvaders.old/vader3b.bit xinvaders/vader3b.bit
diff -c xinvaders.old/vaders.c xinvaders/vaders.c
diff -c xinvaders.old/vaders.h xinvaders/vaders.h
diff -c xinvaders.old/widget.c xinvaders/widget.c
diff -c xinvaders.old/xinvaders.ma xinvaders/xinvaders.ma

It looks like the whole thing, but it's really only minor stuff.  Here's
the entire context diff:

-------------------------Cut Here and use patch----------------------------

diff -c xinvaders.old/Makefile xinvaders/Makefile
*** xinvaders.old/Makefile	Wed Aug  1 13:42:33 1990
--- xinvaders/Makefile	Tue Aug  7 10:29:23 1990
***************
*** 1,6 ****
! CFLAGS		= -g -I/import/X11R4/include -L/import/X11R4/lib
  
! CC		= cc
  
  LIBS = -lXaw -lXt -lXmu -lX11
  
--- 1,9 ----
! # this is for my particular setup
! CFLAGS		= -O -I/import/X11R4/include -L/import/X11R4/lib
! # if you're using X11/R3, add this define
! #CFLAGS		= -DX11R3
  
! CC		= cc 
  
  LIBS = -lXaw -lXt -lXmu -lX11
  
diff -c xinvaders.old/base.c xinvaders/base.c
*** xinvaders.old/base.c	Wed Aug  1 13:14:39 1990
--- xinvaders/base.c	Tue Aug  7 11:16:08 1990
***************
*** 46,55 ****
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   char *data;
    int i, status;
  
!   status = XmuReadBitmapDataFromFile ("base.bit",
  				      &width, &height, &data,
  				      &x_hot, &y_hot);
  
--- 46,57 ----
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   char *data, filename[255];
    int i, status;
  
!   sprintf(filename, "%sbase.bit", bitdir);
! 
!   status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
  				      &x_hot, &y_hot);
  
***************
*** 69,75 ****
    base->shape_image->bitmap_bit_order = LSBFirst;
    base->shape_image->byte_order = LSBFirst;
  
!   status = XmuReadBitmapDataFromFile ("explode.bit",
  				      &width, &height, &data,
  				      &x_hot, &y_hot);
  
--- 71,79 ----
    base->shape_image->bitmap_bit_order = LSBFirst;
    base->shape_image->byte_order = LSBFirst;
  
!   sprintf(filename, "%sexplode.bit", bitdir);
! 
!   status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
  				      &x_hot, &y_hot);
  
diff -c xinvaders.old/main.c xinvaders/main.c
*** xinvaders.old/main.c	Sun Aug  5 01:58:09 1990
--- xinvaders/main.c	Tue Aug  7 11:07:26 1990
***************
*** 15,23 ****
  
  #define MAIN
  #include "vaders.h"
  #include <X11/Xaw/Label.h>
  #include <X11/Xaw/Paned.h>
! 
  static int width, height;		/* Size of window. */
  
  static XrmOptionDescRec table[] = {
--- 15,28 ----
  
  #define MAIN
  #include "vaders.h"
+ #ifndef X11R3
  #include <X11/Xaw/Label.h>
  #include <X11/Xaw/Paned.h>
! #else
! #include <X11/IntrinsicP.h>
! #include <X11/Label.h>
! #include <X11/VPaned.h>
! #endif
  static int width, height;		/* Size of window. */
  
  static XrmOptionDescRec table[] = {
***************
*** 31,36 ****
--- 36,43 ----
  	 (Cardinal)&height, XtRImmediate, (caddr_t) VHEIGHT},
      {"debug", "Debug", XtRBoolean, sizeof(Boolean),
  	 (Cardinal)&debug, XtRString, "off"},
+     {"bitdir", "BitmapDirectory", XtRString, sizeof(String),
+ 	 (Cardinal)&bitdir, XtRString, (String)"./"},
      {"basewait", "BaseWait", XtRInt, sizeof(int),
  	 (Cardinal)&basewait, XtRImmediate, (caddr_t) 10},
      {"vaderwait", "VaderWait", XtRInt, sizeof(int),
***************
*** 135,149 ****
      height = VHEIGHT;
      args[0].value = (XtArgVal) width;
      args[1].value = (XtArgVal) height;
      pane = XtCreateWidget("pane", panedWidgetClass, toplevel,
  			  args, XtNumber(args));
      XtManageChild(pane);
-     scoreargs[0].value = (XtArgVal) scorepixel;
-     scorewidget = XtCreateWidget("score", labelWidgetClass, pane,
- 				 scoreargs, XtNumber(scoreargs));
-     /*
-     XtManageChild(scorewidget);
-     */
      gamewidget = (VadersWidget)
  	XtCreateWidget("field", vadersWidgetClass, pane, NULL, 0);
      XtManageChild(gamewidget);
--- 142,155 ----
      height = VHEIGHT;
      args[0].value = (XtArgVal) width;
      args[1].value = (XtArgVal) height;
+ #ifndef X11R3
      pane = XtCreateWidget("pane", panedWidgetClass, toplevel,
  			  args, XtNumber(args));
+ #else
+     pane = XtCreateWidget("pane", vPanedWidgetClass, toplevel,
+ 			   args, XtNumber(args));
+ #endif
      XtManageChild(pane);
      gamewidget = (VadersWidget)
  	XtCreateWidget("field", vadersWidgetClass, pane, NULL, 0);
      XtManageChild(gamewidget);

diff -c xinvaders.old/patchlevel.h xinvaders/patchlevel.h
*** xinvaders.old/patchlevel.h	Wed Aug  1 13:28:33 1990
--- xinvaders/patchlevel.h	Tue Aug  7 11:24:58 1990
***************
*** 13,16 ****
  
  /* patchlevel.h -- patchlevel for xinvaders */
  
! #define PATCHLEVEL 0
--- 13,23 ----
  
  /* patchlevel.h -- patchlevel for xinvaders */
  
! #define PATCHLEVEL 1
! 
! /* 
!   added patches for X11R3 - from duncan at mips.com
!   quicker vader updating - from koreth at ebay.sun.com
!   and bitdir - the BitmapDirectory resource, courtesy of me.
!   Tue Aug  7 1990
! */

diff -c xinvaders.old/shot.c xinvaders/shot.c
*** xinvaders.old/shot.c	Tue Jul 17 14:17:09 1990
--- xinvaders/shot.c	Tue Aug  7 10:52:27 1990
***************
*** 202,212 ****
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   char *data, filename[30];
    int i, status;
  
    for (i = 0; i < 2; i++) {
!     sprintf(filename, "sperm%s.bit", (i ? "b" : "a"));
      status = XmuReadBitmapDataFromFile (filename,
  					&width, &height, &data,
  					&x_hot, &y_hot);
--- 202,212 ----
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   char *data, filename[255];
    int i, status;
  
    for (i = 0; i < 2; i++) {
!     sprintf(filename, "%ssperm%s.bit", bitdir, (i ? "b" : "a"));
      status = XmuReadBitmapDataFromFile (filename,
  					&width, &height, &data,
  					&x_hot, &y_hot);

diff -c xinvaders.old/spacers.c xinvaders/spacers.c
*** xinvaders.old/spacers.c	Tue Jul 17 14:17:20 1990
--- xinvaders/spacers.c	Tue Aug  7 10:53:01 1990
***************
*** 139,148 ****
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   unsigned char *data;
    int status;
  
!   status = XmuReadBitmapDataFromFile ("spacer.bit",
  				      &width, &height, &data,
  				      &x_hot, &y_hot);
    if (status != BitmapSuccess) return status;
--- 139,150 ----
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   unsigned char *data, filename[255];
    int status;
  
!   sprintf(filename, "%sspacer.bit", bitdir);
! 
!   status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
  				      &x_hot, &y_hot);
    if (status != BitmapSuccess) return status;

diff -c xinvaders.old/vader1a.bit xinvaders/vader1a.bit
*** xinvaders.old/vader1a.bit	Fri Jul 13 10:04:15 1990
--- xinvaders/vader1a.bit	Tue Aug  7 10:02:35 1990
***************
*** 1,4 ****
! #define vader1a_width 8
  #define vader1a_height 8
  static char vader1a_bits[] = {
!    0x18, 0x3c, 0x7e, 0xdb, 0xff, 0x5a, 0x81, 0x42};
--- 1,5 ----
! #define vader1a_width 10
  #define vader1a_height 8
  static char vader1a_bits[] = {
!    0x30, 0x00, 0x78, 0x00, 0xfc, 0x00, 0xb6, 0x01, 0xfe, 0x01, 0xb4, 0x00,
!    0x02, 0x01, 0x84, 0x00};
diff -c xinvaders.old/vader1b.bit xinvaders/vader1b.bit
*** xinvaders.old/vader1b.bit	Fri Jul 13 10:08:36 1990
--- xinvaders/vader1b.bit	Tue Aug  7 10:02:35 1990
***************
*** 1,4 ****
! #define vader1b_width 8
  #define vader1b_height 8
  static char vader1b_bits[] = {
!    0x18, 0x3c, 0x7e, 0xdb, 0xff, 0x5a, 0x24, 0x42};
--- 1,5 ----
! #define vader1b_width 10
  #define vader1b_height 8
  static char vader1b_bits[] = {
!    0x30, 0x00, 0x78, 0x00, 0xfc, 0x00, 0xb6, 0x01, 0xfe, 0x01, 0xb4, 0x00,
!    0x48, 0x00, 0x84, 0x00};
diff -c xinvaders.old/vader2a.bit xinvaders/vader2a.bit
*** xinvaders.old/vader2a.bit	Fri Jul 13 10:08:53 1990
--- xinvaders/vader2a.bit	Tue Aug  7 10:02:35 1990
***************
*** 1,5 ****
! #define vader2a_width 10
  #define vader2a_height 8
  static char vader2a_bits[] = {
!    0x84, 0x00, 0x48, 0x00, 0xfc, 0x00, 0xb6, 0x01, 0xff, 0x03, 0xfd, 0x02,
!    0x85, 0x02, 0x48, 0x00};
--- 1,5 ----
! #define vader2a_width 12
  #define vader2a_height 8
  static char vader2a_bits[] = {
!    0x08, 0x01, 0x90, 0x00, 0xf8, 0x01, 0x6c, 0x03, 0xfe, 0x07, 0xfa, 0x05,
!    0x0a, 0x05, 0x90, 0x00};
diff -c xinvaders.old/vader2b.bit xinvaders/vader2b.bit
*** xinvaders.old/vader2b.bit	Fri Jul 13 10:09:04 1990
--- xinvaders/vader2b.bit	Tue Aug  7 10:02:36 1990
***************
*** 1,5 ****
! #define vader2b_width 10
  #define vader2b_height 8
  static char vader2b_bits[] = {
!    0x84, 0x00, 0x49, 0x02, 0xfd, 0x02, 0xb7, 0x03, 0xfe, 0x01, 0xfc, 0x00,
!    0x84, 0x00, 0x02, 0x01};
--- 1,5 ----
! #define vader2b_width 12
  #define vader2b_height 8
  static char vader2b_bits[] = {
!    0x08, 0x01, 0x92, 0x04, 0xfa, 0x05, 0x6e, 0x07, 0xfc, 0x03, 0xf8, 0x01,
!    0x08, 0x01, 0x04, 0x02};
diff -c xinvaders.old/vader3a.bit xinvaders/vader3a.bit
*** xinvaders.old/vader3a.bit	Fri Jul 13 10:09:54 1990
--- xinvaders/vader3a.bit	Tue Aug  7 10:02:36 1990
***************
*** 1,5 ****
! #define vader3a_width 12
  #define vader3a_height 8
  static char vader3a_bits[] = {
!    0xf0, 0x00, 0xfe, 0x07, 0xff, 0x0f, 0x67, 0x0e, 0xff, 0x0f, 0x9c, 0x03,
!    0x66, 0x06, 0x0c, 0x03};
--- 1,5 ----
! #define vader3a_width 14
  #define vader3a_height 8
  static char vader3a_bits[] = {
!    0xe0, 0x01, 0xfc, 0x0f, 0xfe, 0x1f, 0xce, 0x1c, 0xfe, 0x1f, 0x38, 0x07,
!    0xcc, 0x0c, 0x18, 0x06};
diff -c xinvaders.old/vader3b.bit xinvaders/vader3b.bit
*** xinvaders.old/vader3b.bit	Fri Jul 13 10:09:36 1990
--- xinvaders/vader3b.bit	Tue Aug  7 10:02:36 1990
***************
*** 1,5 ****
! #define vader3b_width 12
  #define vader3b_height 8
  static char vader3b_bits[] = {
!    0xf0, 0x00, 0xfe, 0x07, 0xff, 0x0f, 0x67, 0x0e, 0xff, 0x0f, 0x9c, 0x03,
!    0x66, 0x06, 0x03, 0x0c};
--- 1,5 ----
! #define vader3b_width 14
  #define vader3b_height 8
  static char vader3b_bits[] = {
!    0xe0, 0x01, 0xfc, 0x0f, 0xfe, 0x1f, 0xce, 0x1c, 0xfe, 0x1f, 0x38, 0x07,
!    0xcc, 0x0c, 0x06, 0x18};
diff -c xinvaders.old/vaders.c xinvaders/vaders.c
*** xinvaders.old/vaders.c	Tue Jul 17 14:16:44 1990
--- xinvaders/vaders.c	Tue Aug  7 10:53:25 1990
***************
*** 54,68 ****
  
  extern Base base;
  
  #define PointInVader(vader, x, y)	\
!   (x >= (vader)->x && y >= (vader)->y &&		\
!    x <= (vader)->x + (vader)->width  && y <= (vader)->y + (vader)->height)
  
- #define VaderNearBox(vader, minx, miny, maxx, maxy)	\
-   ((vader)->x <= minx && maxx <= (vader)->x + (vader)->width && \
-    (vader)->y <= miny && maxy <= (vader)->y + (vader)->height)
- 
- 
  static void PaintVader(vader, gc)
       Vader vader;
       GC gc;
--- 54,66 ----
  
  extern Base base;
  
+ /* indicates pad around vader bitmap for better collision detection */
+ #define VADERPAD 	1
+ 
  #define PointInVader(vader, x, y)	\
!   (x >= (vader)->x+VADERPAD && y >= (vader)->y &&		\
!    x <= (vader)->x + (vader)->width-VADERPAD  && y <= (vader)->y + (vader)->height)
  
  static void PaintVader(vader, gc)
       Vader vader;
       GC gc;
***************
*** 187,193 ****
  	    ShotHitsBuilding(vader->x+vader->width, vader->y+vader->height);
  	  else
  	    ShotHitsBuilding(vader->x, vader->y+vader->height);
- 	  PaintVader(vader, backgc);
  	  vader->x += vader->vx;
  	  if ((vader->x < (VADERWIDTH-vader->width)/2 && vader->vx < 0) || 
  	      (vader->x > gamewidth-VADERWIDTH && vader->vx > 0))
--- 185,190 ----
***************
*** 222,233 ****
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   char *data, filename[30];
    int i, j, status;
  
    for (i = 0; i < NUMTYPES; i++)
      for (j = 0; j < 2; j++) {
!       sprintf(filename, "vader%d%s.bit", (i+1), (j ? "b" : "a")); 
        status = XmuReadBitmapDataFromFile (filename,
  					  &width, &height, &data,
  					  &x_hot, &y_hot);
--- 219,230 ----
  {
    unsigned int width, height;
    int x_hot, y_hot;
!   char *data, filename[255];
    int i, j, status;
  
    for (i = 0; i < NUMTYPES; i++)
      for (j = 0; j < 2; j++) {
!       sprintf(filename, "%svader%d%s.bit", bitdir, (i+1), (j ? "b" : "a")); 
        status = XmuReadBitmapDataFromFile (filename,
  					  &width, &height, &data,
  					  &x_hot, &y_hot);

diff -c xinvaders.old/vaders.h xinvaders/vaders.h
*** xinvaders.old/vaders.h	Wed Aug  1 11:27:28 1990
--- xinvaders/vaders.h	Tue Aug  7 10:47:43 1990
***************
*** 86,91 ****
--- 86,93 ----
   * Actual vaders definitions.
   */
  
+ ext char *bitdir;
+ 
  ext Boolean debug;
  ext int level;
  
***************
*** 93,99 ****
  ext Window gamewindow;
  ext VadersWidget gamewidget;
  ext int gamewidth, gameheight;
! ext Widget toplevel, scorewidget;
  ext int score;
  ext int basesleft;
  
--- 95,101 ----
  ext Window gamewindow;
  ext VadersWidget gamewidget;
  ext int gamewidth, gameheight;
! ext Widget toplevel;
  ext int score;
  ext int basesleft;
  
diff -c xinvaders.old/widget.c xinvaders/widget.c
*** xinvaders.old/widget.c	Wed Aug  1 11:27:35 1990
--- xinvaders/widget.c	Tue Aug  7 10:12:41 1990
***************
*** 14,20 ****
--- 14,24 ----
  /* widget.c -- handle things that make the playing field behave as a widget. */
  
  #include "vaders.h"
+ #ifndef X11R3
  #include <X11/Xaw/Paned.h>
+ #else
+ #include <X11/VPaned.h>
+ #endif
  
  typedef struct _BaseRec {
    int x;			/* Location. */

diff -c xinvaders.old/xinvaders.ma xinvaders/xinvaders.ma
*** xinvaders.old/xinvaders.ma	Wed Aug  1 12:33:15 1990
--- xinvaders/xinvaders.ma	Tue Aug  7 11:18:20 1990
***************
*** 1,5 ****
  .\" Man page for xinvaders, by Jonny Goldman.
! .TH XInvaders 1 "Jul 17 1990"
  .SH NAME
  \fIXInvaders\fR \- Shoot-em-up them nasty little bugs.
  .SH SYNOPSIS
--- 1,5 ----
  .\" Man page for xinvaders, by Jonny Goldman.
! .TH XInvaders 1.1 "Aug 7 1990"
  .SH NAME
  \fIXInvaders\fR \- Shoot-em-up them nasty little bugs.
  .SH SYNOPSIS
***************
*** 10,15 ****
--- 10,18 ----
  is an implementation of the old Atari Space Invaders game, on top of the
  X11 window system.
  
+ .SH PATCH LEVEL
+ xinvaders is now at Patch Level 1
+ 
  .SH PLAYING XINVADERS
  The game will start with all the invaders drawn.  Press 'p' to play, and
  you're off.
***************
*** 114,119 ****
--- 117,123 ----
  Here's an example of some of the resources you can set (this would be in
  your .Xdefaults file):
  
+  Vaders*BitmapDirectory:        ./
   Vaders*defaultfore:            black
   Vaders*defaultback:            white
   Vaders*Vader1Color:            blue
***************
*** 144,152 ****
  .SH BUGS
  
  The buildings aren't as good as the arcade, but hey, whatdayawant for free?
! You also must be in the same directory as the executable for the images to
! load properly.  It also doesn't handle auto-repeat very well, so you should
! probably turn it off.
  
  .SH COPYRIGHT
  
--- 148,155 ----
  .SH BUGS
  
  The buildings aren't as good as the arcade, but hey, whatdayawant for free?
! It also doesn't handle auto-repeat very well, so you should probably turn
! it off.
  
  .SH COPYRIGHT

dan
----------------------------------------------------
O'Reilly && Associates   argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.



More information about the Comp.sources.x mailing list