[comp.sources.x] v09i014: xinvaders, Patch3, Part01/01

jgoldman@parc.xerox.com (Jonny Goldman) (08/31/90)

Submitted-by: Jonny Goldman <jgoldman@parc.xerox.com>
Posting-number: Volume 9, Issue 14
Archive-name: xinvaders/patch3
Patch-To: xinvaders: Volume 8, Issues 62-66,68,70

This is patch file #3 to the xinvaders game.  I've incorporated code to
search the applications-defaults directory for resources, and added bitmaps
for explosions when you hit the aliens (like the original game).

The patch expects you to have the previous patch in place.

There are two new bitmap (.bit) files, vexlod1.bit and vexlod2.bit

The files that changed are:

diff -c xinvaders.2/Imakefile xinvaders/Imakefile
diff -c xinvaders.2/main.c xinvaders/main.c
diff -c xinvaders.2/patchlevel.h xinvaders/patchlevel.h
diff -c xinvaders.2/shot.c xinvaders/shot.c
diff -c xinvaders.2/spacers.c xinvaders/spacers.c
diff -c xinvaders.2/vaders.c xinvaders/vaders.c
diff -c xinvaders.2/vaders.h xinvaders/vaders.h

I've put the context diff and the bitmaps in a sharfile.  It expects the
old source to be in the directory xinvaders.2, and the new source to be in
the directory xinvaders (which at the start has a complete copy of
xinvaders.2).

-------------------------Cut Here ----------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  xinvaders.3.diffs xinvaders/vexplod1.bit
#   xinvaders/vexplod2.bit
# Wrapped by jgoldman@philo on Thu Aug 30 10:31:06 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xinvaders.3.diffs' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xinvaders.3.diffs'\"
else
echo shar: Extracting \"'xinvaders.3.diffs'\" \(9325 characters\)
sed "s/^X//" >'xinvaders.3.diffs' <<'END_OF_FILE'
Xdiff -c xinvaders.2/Imakefile xinvaders/Imakefile
X*** xinvaders.2/Imakefile	Wed Aug  1 13:40:41 1990
X--- xinvaders/Imakefile	Thu Aug 30 09:35:58 1990
X***************
X*** 1,4 ****
X! LOCAL_LIBRARIES = $(XAWLIB) $(XTOOLLIB) $(XMULIB) $(XLIB)
X  
X  OBJS = spacers.o base.o widget.o main.o vaders.o shot.o score.o
X  
X--- 1,4 ----
X! LOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB)
X  
X  OBJS = spacers.o base.o widget.o main.o vaders.o shot.o score.o
X  
XOnly in xinvaders.2: bits
Xdiff -c xinvaders.2/main.c xinvaders/main.c
X*** xinvaders.2/main.c	Thu Aug 30 10:17:21 1990
X--- xinvaders/main.c	Thu Aug 30 09:36:39 1990
X***************
X*** 24,33 ****
X  #include <X11/VPaned.h>
X  #endif
X  static int width, height;		/* Size of window. */
X- static Pixel defaultfore;	/* Default foreground */
X- Pixel defaultback;	/* Default background */
X- static Pixel scorepixel;	/* Color for score. */
X  
X  static XrmOptionDescRec table[] = {
X      {"-debug",	"*debug",	XrmoptionNoArg,	NULL},
X  };
X--- 24,34 ----
X  #include <X11/VPaned.h>
X  #endif
X  static int width, height;		/* Size of window. */
X  
X+ #ifdef XFILESEARCHPATH
X+ static void AddPathToSearchPath();
X+ #endif
X+ 
X  static XrmOptionDescRec table[] = {
X      {"-debug",	"*debug",	XrmoptionNoArg,	NULL},
X  };
X***************
X*** 124,129 ****
X--- 125,133 ----
X      Widget pane;
X      extern WidgetClass labelwidgetclass;
X      srandom(time(0));
X+ #ifdef XFILESEARCHPATH
X+     AddPathToSearchPath(XFILESEARCHPATH);
X+ #endif
X      toplevel = XtInitialize(argv[0], "Vaders", table, XtNumber(table),
X  			    &argc, argv);
X      dpy = XtDisplay(toplevel);
X***************
X*** 171,173 ****
X--- 175,223 ----
X      fprintf(stderr, "%s\n", msg);
X      exit(1);
X  }
X+ 
X+ 
X+ #ifdef XFILESEARCHPATH
X+ static void
X+ AddPathToSearchPath(path)
X+ char *path;
X+ {
X+      char *old, *new;
X+      extern char *getenv();
X+      
X+      old = getenv("XFILESEARCHPATH");
X+      if (old) {
X+ #if defined(mips) || defined(hpux) || defined(sun)
X+ 	  /* +1 for =, +2 for :, +3 for null */
X+ 	  new = XtMalloc((Cardinal) (strlen("XFILESEARCHPATH") +
X+ 				     strlen(old) +
X+ 				     strlen(path) + 3));
X+ 	  (void) strcpy(new, "XFILESEARCHPATH");
X+ 	  (void) strcat(new, "=");
X+ 	  (void) strcat(new, old);
X+ 	  (void) strcat(new, ":");
X+ 	  (void) strcat(new, path);
X+ 	  putenv(new);
X+ #else
X+ 	  /* +1 for colon, +2 for null */
X+ 	  new = XtMalloc((Cardinal) (strlen(old) + strlen(path) + 2));
X+ 	  (void) strcpy(new, old);
X+ 	  (void) strcat(new, ":");
X+ 	  (void) strcat(new, path);
X+ 	  setenv("XFILESEARCHPATH", new, 1);
X+ #endif
X+      }
X+      else {
X+ #if defined(mips) || defined(hpux) || defined(sun)
X+ 	  new = XtMalloc((Cardinal) (strlen("XFILESEARCHPATH") +
X+ 				     strlen(path) + 2));
X+ 	  (void) strcpy(new, "XFILESEARCHPATH");
X+ 	  (void) strcat(new, "=");
X+ 	  (void) strcat(new, path);
X+ 	  putenv(new);
X+ #else
X+ 	  setenv("XFILESEARCHPATH", path, 1);
X+ #endif
X+      }
X+ }
X+ #endif
Xdiff -c xinvaders.2/patchlevel.h xinvaders/patchlevel.h
X*** xinvaders.2/patchlevel.h	Tue Aug  7 17:13:10 1990
X--- xinvaders/patchlevel.h	Thu Aug 30 10:07:58 1990
X***************
X*** 8,19 ****
X  
X  Jonny Goldman <jgoldman@parc.xerox.com>
X  
X! Tue Jul 17 1990
X  */
X  
X  /* patchlevel.h -- patchlevel for xinvaders */
X  
X! #define PATCHLEVEL 2
X  
X  /* 
X    version 1.1:
X--- 8,19 ----
X  
X  Jonny Goldman <jgoldman@parc.xerox.com>
X  
X! Thu Aug 30 1990
X  */
X  
X  /* patchlevel.h -- patchlevel for xinvaders */
X  
X! #define PATCHLEVEL 3
X  
X  /* 
X    version 1.1:
X***************
X*** 25,29 ****
X--- 25,35 ----
X    version 1.2:
X    added multi-resolution code.  created new bitmaps for large-scale.
X    added new resource for scale: Vaders*Scale, 1=normal, 2=large.
X+ 
X+   version 1.3:
X+   added explosions for aliens.
X+   cleaned up some dirty code so the program will compile without 
X+    complaints from gcc and added applications-default directory search
X+    - from jik@athena.mit.edu
X  
X  */
Xdiff -c xinvaders.2/shot.c xinvaders/shot.c
X*** xinvaders.2/shot.c	Tue Aug  7 15:32:08 1990
X--- xinvaders/shot.c	Thu Aug 30 09:36:50 1990
X***************
X*** 83,89 ****
X  Opaque closure;
X  XtIntervalId id;
X  {
X!   int i, x, y, newx, newy;
X    Shot shot;
X    if (closure != (Opaque) MoveShots) return;
X    if (!paused) {
X--- 83,89 ----
X  Opaque closure;
X  XtIntervalId id;
X  {
X!   int i, x, y, newy;
X    Shot shot;
X    if (closure != (Opaque) MoveShots) return;
X    if (!paused) {
X***************
X*** 135,141 ****
X  Opaque closure;
X  XtIntervalId id;
X  {
X!   int i, x, y, newx, newy;
X    Shot vshot;
X  
X    if (closure != (Opaque) MoveVshots) return;
X--- 135,141 ----
X  Opaque closure;
X  XtIntervalId id;
X  {
X!   int i, x, y, newy;
X    Shot vshot;
X  
X    if (closure != (Opaque) MoveVshots) return;
Xdiff -c xinvaders.2/spacers.c xinvaders/spacers.c
X*** xinvaders.2/spacers.c	Tue Aug  7 15:29:02 1990
X--- xinvaders/spacers.c	Thu Aug 30 09:37:00 1990
X***************
X*** 65,72 ****
X  
X  static void DestroySpacer()
X  {
X-   XImage ximage;
X-   int num, value, ex, ey;
X    score += spacer->score;
X    PaintScore();
X  
X--- 65,70 ----
X***************
X*** 108,115 ****
X       Opaque closure;
X       XtIntervalId id;
X  {
X-   register int i;
X-   int minx, miny, maxx, maxy, spy;
X    if (closure != (Opaque) MoveSpacer) return;
X    spacertimerid = XtAddTimeOut(spacerwait, MoveSpacer, (Opaque) MoveSpacer);
X    if (!paused) {
X--- 106,111 ----
X***************
X*** 139,145 ****
X  {
X    unsigned int width, height;
X    int x_hot, y_hot;
X!   unsigned char *data, filename[255];
X    int status;
X  
X    sprintf(filename, "%sspacer%d.bit", bitdir, scale);
X--- 135,141 ----
X  {
X    unsigned int width, height;
X    int x_hot, y_hot;
X!   char *data, filename[255];
X    int status;
X  
X    sprintf(filename, "%sspacer%d.bit", bitdir, scale);
Xdiff -c xinvaders.2/vaders.c xinvaders/vaders.c
X*** xinvaders.2/vaders.c	Tue Aug  7 15:28:22 1990
X--- xinvaders/vaders.c	Thu Aug 30 10:20:55 1990
X***************
X*** 38,43 ****
X--- 38,44 ----
X    XImage *shape_image[2];
X    int value;
X    Boolean alive;
X+   Boolean exploded;
X  } VaderRec, *Vader;
X  
X  VaderRec vaders[NUMROWS][NUMVADERS];
X***************
X*** 54,59 ****
X--- 55,62 ----
X  
X  extern Base base;
X  
X+ XImage *Explode_image;
X+ 
X  /* indicates pad around vader bitmap for better collision detection */
X  #define VADERPAD 	scale
X  
X***************
X*** 77,86 ****
X  	    0, 0, rx, ry, w, h);
X  }
X  
X  static void DestroyVader(vader)
X  Vader vader;
X  {
X-   int num, value;
X    int oldx = vader->x;
X    int oldy = vader->y;
X    PaintVader(vader, backgc);
X--- 80,104 ----
X  	    0, 0, rx, ry, w, h);
X  }
X  
X+ static void PaintExplodedVader(vader, gc)
X+      Vader vader;
X+      GC gc;
X+ {
X+   int rx, ry, w, h;
X+   
X+   w = Explode_image->width;
X+   h = Explode_image->height;
X+ 
X+   rx = vader->x;
X+   ry = vader->y;
X+   
X+   XPutImage(dpy, gamewindow, gc, Explode_image,
X+ 	    0, 0, rx, ry, w, h);
X+ }
X+ 
X  static void DestroyVader(vader)
X  Vader vader;
X  {
X    int oldx = vader->x;
X    int oldy = vader->y;
X    PaintVader(vader, backgc);
X***************
X*** 97,102 ****
X--- 115,122 ----
X      vaderwait /= 2; break;
X    }
X    vader->alive = FALSE;
X+   vader->exploded = TRUE;
X+   PaintExplodedVader(vader, vader->gc);
X  }
X  
X  
X***************
X*** 158,164 ****
X  {
X    register Vader vader;
X    register int i, j;
X-   int oldx, newx;
X    Boolean reversep;
X  
X    reversep = FALSE;
X--- 178,183 ----
X***************
X*** 180,186 ****
X      for(j = 0; j < NUMROWS; j++)
X        for (i=0 ; i< NUMVADERS ; i++) {
X  	vader = &vaders[j][i];
X! 	if (vader->alive) {
X  	  if (vader->vx > 0)
X  	    ShotHitsBuilding(vader->x+vader->width, vader->y+vader->height);
X  	  else
X--- 199,209 ----
X      for(j = 0; j < NUMROWS; j++)
X        for (i=0 ; i< NUMVADERS ; i++) {
X  	vader = &vaders[j][i];
X! 	if (vader->exploded) {
X! 	  PaintExplodedVader(vader, backgc);
X! 	  vader->exploded = FALSE;
X! 	}
X! 	else if (vader->alive) {
X  	  if (vader->vx > 0)
X  	    ShotHitsBuilding(vader->x+vader->width, vader->y+vader->height);
X  	  else
X***************
X*** 243,248 ****
X--- 266,289 ----
X        Vader_Image[i][j]->byte_order = LSBFirst;
X      }
X  
X+   sprintf(filename, "%svexplod%d.bit", bitdir, scale); 
X+   status = XmuReadBitmapDataFromFile (filename,
X+ 				      &width, &height, &data,
X+ 				      &x_hot, &y_hot);
X+ 
X+   if (status != BitmapSuccess) return status;
X+ 
X+   Explode_image = XCreateImage(dpy,
X+ 			       DefaultVisual(dpy, DefaultScreen(dpy)),
X+ 			       1,
X+ 			       XYBitmap,
X+ 			       0,
X+ 			       data,
X+ 			       width, height,
X+ 			       8, 0);
X+   Explode_image->bitmap_bit_order = LSBFirst;
X+   Explode_image->byte_order = LSBFirst;
X+ 
X    return BitmapSuccess;
X  }
X  
X***************
X*** 263,268 ****
X--- 304,310 ----
X        vader->y = VADERHEIGHT*(offset+j);
X        vader->vx = scale;
X        vader->alive = TRUE;
X+       vader->exploded = FALSE;
X      }
X  }
X  
Xdiff -c xinvaders.2/vaders.h xinvaders/vaders.h
X*** xinvaders.2/vaders.h	Tue Aug  7 14:58:51 1990
X--- xinvaders/vaders.h	Thu Aug 30 09:44:31 1990
X***************
X*** 203,208 ****
X  extern void MoveShots();
X  extern void MoveVshots();
X  
X! ext Pixel defaultback, defaultfore;
X  
X  #endif _vaders_h
X--- 203,208 ----
X  extern void MoveShots();
X  extern void MoveVshots();
X  
X! ext Pixel defaultfore, defaultback;
X  
X  #endif _vaders_h
XOnly in xinvaders: vexplod1.bit
XOnly in xinvaders: vexplod2.bit
END_OF_FILE
if test 9325 -ne `wc -c <'xinvaders.3.diffs'`; then
    echo shar: \"'xinvaders.3.diffs'\" unpacked with wrong size!
fi
# end of 'xinvaders.3.diffs'
fi
if test -f 'xinvaders/vexplod1.bit' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xinvaders/vexplod1.bit'\"
else
echo shar: Extracting \"'xinvaders/vexplod1.bit'\" \(190 characters\)
sed "s/^X//" >'xinvaders/vexplod1.bit' <<'END_OF_FILE'
X#define vexplode1_width 14
X#define vexplode1_height 8
Xstatic char vexplode1_bits[] = {
X   0x48, 0x04, 0x50, 0x02, 0x00, 0x00, 0x06, 0x18, 0x10, 0x02, 0x88, 0x04,
X   0x80, 0x00, 0x00, 0x00};
END_OF_FILE
if test 190 -ne `wc -c <'xinvaders/vexplod1.bit'`; then
    echo shar: \"'xinvaders/vexplod1.bit'\" unpacked with wrong size!
fi
# end of 'xinvaders/vexplod1.bit'
fi
if test -f 'xinvaders/vexplod2.bit' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xinvaders/vexplod2.bit'\"
else
echo shar: Extracting \"'xinvaders/vexplod2.bit'\" \(491 characters\)
sed "s/^X//" >'xinvaders/vexplod2.bit' <<'END_OF_FILE'
X#define vexplode2_width 28
X#define vexplode2_height 16
Xstatic char vexplode2_bits[] = {
X   0x00, 0x20, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, 0x00, 0xa8, 0x10, 0x00,
X   0xc0, 0xa8, 0x0c, 0x00, 0x00, 0x03, 0x02, 0x00, 0x60, 0x00, 0x60, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x80, 0x00, 0x10, 0x00, 0x60, 0x04, 0x64, 0x00, 0x00, 0x53, 0x09, 0x00,
X   0xc0, 0x50, 0x11, 0x00, 0x00, 0x48, 0x02, 0x00, 0x00, 0x40, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00};
END_OF_FILE
if test 491 -ne `wc -c <'xinvaders/vexplod2.bit'`; then
    echo shar: \"'xinvaders/vexplod2.bit'\" unpacked with wrong size!
fi
# end of 'xinvaders/vexplod2.bit'
fi
echo shar: End of shell archive.
exit 0


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