[comp.sources.x] v08i070: xinvaders -- space invaders for X, Patch2, Part01/02

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

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

This is patch file #2 to the xinvaders game.  All it does is allow you to
have two different game sizes.  I've done this by creating new bitmap files
and modifying the source so it can handle the new (larger) size.  I've also
added a new resource so the user can specify which size to use.

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

There are all new bitmaps (.bit) files.  Actually, there are only some new
files, some are just renamed from the old ones, but they're small, so I'm
just including them as part of a shar file.

The files that changed are:

diff -c xinvaders.1/Makefile xinvaders/Makefile
diff -c xinvaders.1/base.c xinvaders/base.c
diff -c xinvaders.1/main.c xinvaders/main.c
diff -c xinvaders.1/patchlevel.h xinvaders/patchlevel.h
diff -c xinvaders.1/shot.c xinvaders/shot.c
diff -c xinvaders.1/spacers.c xinvaders/spacers.c
diff -c xinvaders.1/vaders.c xinvaders/vaders.c
diff -c xinvaders.1/vaders.h xinvaders/vaders.h
diff -c xinvaders.1/xinvaders.ma xinvaders/xinvaders.ma

Next comes the context diff.  The next part is a shar archive of the
bitmaps.

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

diff -c xinvaders.1/Makefile xinvaders/Makefile
*** xinvaders.1/Makefile	Tue Aug  7 10:29:23 1990
--- xinvaders/Makefile	Tue Aug  7 17:19:29 1990
***************
*** 7,15 ****
  
  LIBS = -lXaw -lXt -lXmu -lX11
  
! BITS = 	base.bit	sperma.bit	vader1b.bit	vader3a.bit \
! 	explode.bit	spermb.bit	vader2a.bit	vader3b.bit \
! 	spacer.bit	vader1a.bit	vader2b.bit
  
  INCS = patchlevel.h vaders.h
  
--- 7,18 ----
  
  LIBS = -lXaw -lXt -lXmu -lX11
  
! BITS = 	base1.bit	sperma1.bit	vader1b1.bit	vader3a1.bit \
! 	explode1.bit	spermb1.bit	vader2a1.bit	vader3b1.bit \
! 	spacer1.bit	vader1a1.bit	vader2b1.bit \
! 	base2.bit	sperma2.bit	vader1b2.bit	vader3a2.bit \
! 	explode2.bit	spermb2.bit	vader2a2.bit	vader3b2.bit \
! 	spacer2.bit	vader1a2.bit	vader2b2.bit
  
  INCS = patchlevel.h vaders.h
  
***************
*** 25,30 ****
--- 28,35 ----
  
  SPLIT  = xinvaders.split.
  
+ TAR = xinvaders.tar
+ 
  xinvaders:	$(OBJS)
  	$(CC) -o xinvaders $(OBJS) $(LIBS)
  
***************
*** 35,37 ****
--- 40,48 ----
  
  ${DISTRIB}: $(ALL)
  	shar $(ALL) | split -500 - ${SPLIT}
+ 
+ tar::	$(TAR)
+ 
+ $(TAR): $(ALL)
+ 	tar cvf $(TAR) $(ALL)
+ 	compress $(TAR)

diff -c xinvaders.1/base.c xinvaders/base.c
*** xinvaders.1/base.c	Tue Aug  7 11:16:08 1990
--- xinvaders/base.c	Tue Aug  7 15:53:02 1990
***************
*** 49,55 ****
    char *data, filename[255];
    int i, status;
  
!   sprintf(filename, "%sbase.bit", bitdir);
  
    status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
--- 49,55 ----
    char *data, filename[255];
    int i, status;
  
!   sprintf(filename, "%sbase%d.bit", bitdir, scale);
  
    status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
***************
*** 71,77 ****
    base->shape_image->bitmap_bit_order = LSBFirst;
    base->shape_image->byte_order = LSBFirst;
  
!   sprintf(filename, "%sexplode.bit", bitdir);
  
    status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
--- 71,77 ----
    base->shape_image->bitmap_bit_order = LSBFirst;
    base->shape_image->byte_order = LSBFirst;
  
!   sprintf(filename, "%sexplode%d.bit", bitdir, scale);
  
    status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
***************
*** 231,243 ****
  
  void MoveLeft()
  {
!   if(!paused) base->v= -1;
  }
  
  
  void MoveRight()
  {
!   if(!paused) base->v = 1;
  }
  
  
--- 231,243 ----
  
  void MoveLeft()
  {
!   if(!paused) base->v= -scale;
  }
  
  
  void MoveRight()
  {
!   if(!paused) base->v = scale;
  }
  
  
***************
*** 258,265 ****
  #define NUMBUILDINGS 4
  #define HUNKROWS 4
  #define NUMHUNKS 10
! #define HUNKWIDTH 2
! #define HUNKHEIGHT 4
  #define buildingwidth HUNKWIDTH*NUMHUNKS
  #define buildingheight HUNKHEIGHT*HUNKROWS
  
--- 258,265 ----
  #define NUMBUILDINGS 4
  #define HUNKROWS 4
  #define NUMHUNKS 10
! #define HUNKWIDTH (2*scale)
! #define HUNKHEIGHT (4*scale)
  #define buildingwidth HUNKWIDTH*NUMHUNKS
  #define buildingheight HUNKHEIGHT*HUNKROWS
  
***************
*** 279,285 ****
    int x, y, w, h;
  
    x = building->x+c*HUNKWIDTH;
!   y = gameheight-45+r*HUNKHEIGHT;
  
    XFillRectangle(dpy, gamewindow, gc, x, y, HUNKWIDTH, HUNKHEIGHT);
  }
--- 279,285 ----
    int x, y, w, h;
  
    x = building->x+c*HUNKWIDTH;
!   y = gameheight-scale*45+r*HUNKHEIGHT;
  
    XFillRectangle(dpy, gamewindow, gc, x, y, HUNKWIDTH, HUNKHEIGHT);
  }
***************
*** 301,308 ****
    for(i=0; i< NUMBUILDINGS; i++) {
      building = &buildings[i];
      if(x>=building->x && x<building->x+buildingwidth &&
!        y>=gameheight-45 && y<gameheight-45+buildingheight) {
!       r = (y-(gameheight-45))/HUNKHEIGHT;
        c = (x-building->x)/HUNKWIDTH;
        if (r<0 || r>=HUNKROWS)
  	printf("Error in row");
--- 301,308 ----
    for(i=0; i< NUMBUILDINGS; i++) {
      building = &buildings[i];
      if(x>=building->x && x<building->x+buildingwidth &&
!        y>=gameheight-scale*45 && y<gameheight-scale*45+buildingheight) {
!       r = (y-(gameheight-scale*45))/HUNKHEIGHT;
        c = (x-building->x)/HUNKWIDTH;
        if (r<0 || r>=HUNKROWS)
  	printf("Error in row");
***************
*** 324,331 ****
  
    for(i=0; i< NUMBUILDINGS; i++) {
      buildings[i].x = i*((gamewidth ?
! 			 (VWIDTH -(3*(base->width+3))-70) :
! 			 (gamewidth-(3*(base->width+3))-70)))/4+35;
      for (j=0; j<HUNKROWS; j++)
        for (k = 0; k < NUMHUNKS; k++) 
  	buildings[i].hunks[j][k] = TRUE;
--- 324,331 ----
  
    for(i=0; i< NUMBUILDINGS; i++) {
      buildings[i].x = i*((gamewidth ?
! 			 (scale*VWIDTH -(3*(base->width+3))-scale*70) :
! 			 (gamewidth-(3*(base->width+3))-scale*70)))/4+scale*35;
      for (j=0; j<HUNKROWS; j++)
        for (k = 0; k < NUMHUNKS; k++) 
  	buildings[i].hunks[j][k] = TRUE;

diff -c xinvaders.1/main.c xinvaders/main.c
*** xinvaders.1/main.c	Tue Aug  7 11:07:26 1990
--- xinvaders/main.c	Tue Aug  7 15:55:44 1990
***************
*** 38,43 ****
--- 38,45 ----
  	 (Cardinal)&debug, XtRString, "off"},
      {"bitdir", "BitmapDirectory", XtRString, sizeof(String),
  	 (Cardinal)&bitdir, XtRString, (String)"./"},
+     {"scale", "Scale", XtRInt, sizeof(int),
+ 	 (Cardinal)&scale, XtRImmediate, (caddr_t) 1},
      {"basewait", "BaseWait", XtRInt, sizeof(int),
  	 (Cardinal)&basewait, XtRImmediate, (caddr_t) 10},
      {"vaderwait", "VaderWait", XtRInt, sizeof(int),
***************
*** 138,145 ****
  	vshotpixel = defaultfore;
  	scorepixel = defaultfore;
      }
!     width = VWIDTH;
!     height = VHEIGHT;
      args[0].value = (XtArgVal) width;
      args[1].value = (XtArgVal) height;
  #ifndef X11R3
--- 140,149 ----
  	vshotpixel = defaultfore;
  	scorepixel = defaultfore;
      }
!     if (scale<1) scale = 1;
!     if (scale>2) scale = 2;
!     width = scale*VWIDTH;
!     height = scale*VHEIGHT;
      args[0].value = (XtArgVal) width;
      args[1].value = (XtArgVal) height;
  #ifndef X11R3

diff -c xinvaders.1/patchlevel.h xinvaders/patchlevel.h
*** xinvaders.1/patchlevel.h	Tue Aug  7 11:24:58 1990
--- xinvaders/patchlevel.h	Tue Aug  7 17:13:10 1990
***************
*** 13,23 ****
  
  /* patchlevel.h -- patchlevel for xinvaders */
  
! #define PATCHLEVEL 1
  
  /* 
    added patches for X11R3 - from duncan@mips.com
    quicker vader updating - from koreth@ebay.sun.com
    and bitdir - the BitmapDirectory resource, courtesy of me.
    Tue Aug  7 1990
  */
--- 13,29 ----
  
  /* patchlevel.h -- patchlevel for xinvaders */
  
! #define PATCHLEVEL 2
  
  /* 
+   version 1.1:
    added patches for X11R3 - from duncan@mips.com
    quicker vader updating - from koreth@ebay.sun.com
    and bitdir - the BitmapDirectory resource, courtesy of me.
    Tue Aug  7 1990
+ 
+   version 1.2:
+   added multi-resolution code.  created new bitmaps for large-scale.
+   added new resource for scale: Vaders*Scale, 1=normal, 2=large.
+ 
  */

diff -c xinvaders.1/shot.c xinvaders/shot.c
*** xinvaders.1/shot.c	Tue Aug  7 10:52:27 1990
--- xinvaders/shot.c	Tue Aug  7 15:32:08 1990
***************
*** 19,25 ****
  
  #define MAXSHOTS	1
  #define MAXVSHOTS	6
! #define SHOTSIZE	8
  
  typedef struct _ShotRec {
      int x, y;		/* Location of this shot. */
--- 19,25 ----
  
  #define MAXSHOTS	1
  #define MAXVSHOTS	6
! #define SHOTSIZE	(8*scale)
  
  typedef struct _ShotRec {
      int x, y;		/* Location of this shot. */
***************
*** 146,152 ****
        vshottimerid = NULL;
      for (i=0 ; i<numvshots ; i++) {
        vshot = vshots + i;
!       newy = vshot->y + 2;
        x = vshot->x;
        y = vshot->y;
        if (y>gameheight ||
--- 146,152 ----
        vshottimerid = NULL;
      for (i=0 ; i<numvshots ; i++) {
        vshot = vshots + i;
!       newy = vshot->y + 2*scale;
        x = vshot->x;
        y = vshot->y;
        if (y>gameheight ||
***************
*** 206,212 ****
    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);
--- 206,212 ----
    int i, status;
  
    for (i = 0; i < 2; i++) {
!     sprintf(filename, "%ssperm%s%d.bit", bitdir, (i ? "b" : "a"), scale);
      status = XmuReadBitmapDataFromFile (filename,
  					&width, &height, &data,
  					&x_hot, &y_hot);

diff -c xinvaders.1/spacers.c xinvaders/spacers.c
*** xinvaders.1/spacers.c	Tue Aug  7 10:53:01 1990
--- xinvaders/spacers.c	Tue Aug  7 15:29:02 1990
***************
*** 18,24 ****
  Boolean spacer_shown;
  
  #define SPACERY 0
! #define SPACERV 2
  
  typedef struct _SpacerRec {
    int x;			/* Location. */
--- 18,24 ----
  Boolean spacer_shown;
  
  #define SPACERY 0
! #define SPACERV 2*scale
  
  typedef struct _SpacerRec {
    int x;			/* Location. */
***************
*** 142,148 ****
    unsigned char *data, filename[255];
    int status;
  
!   sprintf(filename, "%sspacer.bit", bitdir);
  
    status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,
--- 142,148 ----
    unsigned char *data, filename[255];
    int status;
  
!   sprintf(filename, "%sspacer%d.bit", bitdir, scale);
  
    status = XmuReadBitmapDataFromFile (filename,
  				      &width, &height, &data,

diff -c xinvaders.1/vaders.c xinvaders/vaders.c
*** xinvaders.1/vaders.c	Tue Aug  7 10:53:25 1990
--- xinvaders/vaders.c	Tue Aug  7 15:28:22 1990
***************
*** 19,27 ****
  #define NUMROWS		5	/* number of rows of vaders */
  #define NUMVADERS	11	/* Maximum of vaders of each type. */
  #define BASEY 10
! #define VADERWIDTH	14
! #define VADERHEIGHT	12
! #define VADERYINC	8
  
  static XImage *Vader_Image[NUMTYPES][2];	/* XImages for the vaders. */
  
--- 19,27 ----
  #define NUMROWS		5	/* number of rows of vaders */
  #define NUMVADERS	11	/* Maximum of vaders of each type. */
  #define BASEY 10
! #define VADERWIDTH	(14*scale)
! #define VADERHEIGHT	(12*scale)
! #define VADERYINC	(8*scale)
  
  static XImage *Vader_Image[NUMTYPES][2];	/* XImages for the vaders. */
  
***************
*** 55,61 ****
  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 &&		\
--- 55,61 ----
  extern Base base;
  
  /* indicates pad around vader bitmap for better collision detection */
! #define VADERPAD 	scale
  
  #define PointInVader(vader, x, y)	\
    (x >= (vader)->x+VADERPAD && y >= (vader)->y &&		\
***************
*** 224,230 ****
  
    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);
--- 224,230 ----
  
    for (i = 0; i < NUMTYPES; i++)
      for (j = 0; j < 2; j++) {
!       sprintf(filename, "%svader%d%s%d.bit", bitdir, (i+1), (j ? "b" : "a"), scale); 
        status = XmuReadBitmapDataFromFile (filename,
  					  &width, &height, &data,
  					  &x_hot, &y_hot);
***************
*** 261,267 ****
        vader = &vaders[j][i];
        vader->x = 3 + VADERWIDTH*i+(VADERWIDTH-vader->width)/2;
        vader->y = VADERHEIGHT*(offset+j);
!       vader->vx = 1;
        vader->alive = TRUE;
      }
  }
--- 261,267 ----
        vader = &vaders[j][i];
        vader->x = 3 + VADERWIDTH*i+(VADERWIDTH-vader->width)/2;
        vader->y = VADERHEIGHT*(offset+j);
!       vader->vx = scale;
        vader->alive = TRUE;
      }
  }
diff -c xinvaders.1/vaders.h xinvaders/vaders.h
*** xinvaders.1/vaders.h	Tue Aug  7 10:47:43 1990
--- xinvaders/vaders.h	Tue Aug  7 14:58:51 1990
***************
*** 87,92 ****
--- 87,93 ----
   */
  
  ext char *bitdir;
+ ext int scale;
  
  ext Boolean debug;
  ext int level;

diff -c xinvaders.1/xinvaders.ma xinvaders/xinvaders.ma
*** xinvaders.1/xinvaders.ma	Tue Aug  7 11:18:20 1990
--- xinvaders/xinvaders.ma	Tue Aug  7 17:16:31 1990
***************
*** 11,17 ****
  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
--- 11,17 ----
  X11 window system.
  
  .SH PATCH LEVEL
! xinvaders is now at Patch Level 2
  
  .SH PLAYING XINVADERS
  The game will start with all the invaders drawn.  Press 'p' to play, and
***************
*** 78,83 ****
--- 78,93 ----
  works on monochrome screens, but the colors don't mean anything (surprise!).
  .PP
  .TP 8
+ .B BitmapDirectory
+ The directory pathname for the bitmap files. Must have a trailing directory
+ delimiter (usually a /).
+ .PP
+ .TP 8
+ .B Scale
+ A switch that allows for multiple resolutions.
+ 1 for normal resolution, 2 for 2x zoom.
+ .PP
+ .TP 8
  .B BaseColor
  The color for the Base (you).  Default is white.
  .PP
***************
*** 118,123 ****
--- 128,134 ----
  your .Xdefaults file):
  
   Vaders*BitmapDirectory:        ./
+  Vaders*Scale:                  1
   Vaders*defaultfore:            black
   Vaders*defaultback:            white
   Vaders*Vader1Color:            blue

-------------------------Cut Here----------------------------

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