[unix-pc.sources] Bitmapped "Asteroids" Game

hjespers@attcan.UUCP (Hans Jespersen) (12/02/89)

'Rocks' is an Asteroids type game. I tried to preserve
as many of the elements of the original game as possible.
However, this being the first release, not all elements of the 
the arcade game have been implimented. Most notably, the 
little UFO-things (technical description eh?). Also, the
"rocks" are square (should have called the game "cubes" then
nobody would complain). Other than that I think it's a 
challanging game. See the README for directions on how to
play.

-- 
Hans Jespersen                UUCP: {uunet | att}!attcan!hjespers
AT&T Canada Inc.            
Toronto, Ontario              

-------------------------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 archive 1 (of 1)."
# Contents:  Makefile README game.c init.c move.c point.c rocks.c
#   rocks.h shot.c sprites.c stars.c window.c
# Wrapped by root@arakis on Thu Nov 30 23:36:18 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(661 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
rocks: rocks.o sprites.o window.o init.o game.o move.o shot.o stars.o point.o
X	cc -o rocks sprites.o rocks.o window.o init.o game.o move.o shot.o stars.o point.o -ltam -ltermlib
X
rocks.o: rocks.c rocks.h
X	cc -O -c rocks.c
X
sprites.o: sprites.c rocks.h
X	cc -O -c sprites.c 
X
window.o: window.c rocks.h
X	cc -O -c window.c
X
init.o: init.c rocks.h
X	cc -O -c init.c
X
game.o: game.c rocks.h
X	cc -O -c game.c
X
move.o: move.c rocks.h
X	cc -O -c move.c
X
shot.o: shot.c rocks.h
X	cc -O -c shot.c
X
stars.o: stars.c rocks.h
X	cc -O -c stars.c
X
point.o: point.c rocks.h
X	cc -O -c point.c
X
clean:
X	rm sprites.o rocks.o window.o move.o init.o game.o shot.o stars.o point.o rocks
END_OF_FILE
if test 661 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(1185 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen     ..!uunet!attcan!hjespers         *
X*                                                          *
X* NOTICE:    This program is in the public domain.         *
X*                                                          *
X\**********************************************************/
X
X'Rocks' is an Asteroids type game. I tried to preserve
as many of the elements of the original game as possible.
However, this being the first release, not all elements of the 
the arcade game have been implimented. Most notably, the 
little UFO-things (technical description eh?).
X
The controls for the game are as follows :
X
X	'a'	- shoot
X	'k'	- rotate counter-clockwise
X	'l'	- rotate clockwise
X	<space> - thrust
X	'q'	- quit
X
Anyone wishing to change these controls should look at rocks.h
X
Please let me know what you think of this program. I may add
some new features in the future and perhaps spruce up the 
graphics. 
X
XEnjoy.
X
X- hans             hjespers@attcan.uucp (uunet!attcan!hjespers) 
END_OF_FILE
if test 1185 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'game.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'game.c'\"
else
echo shar: Extracting \"'game.c'\" \(3910 characters\)
sed "s/^X//" >'game.c' <<'END_OF_FILE'
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X\**********************************************************/
X
X#include "rocks.h"
X
void collission_check();
int  explode;
X
playgame()
X{
X	char	key;
X	int	i;
X	
X	flushinp();
X	for(explode = FALSE; quitflag != TRUE ;) {
X		key = getch();
X		switch( key ) {
X			case BEEP:
X				togglebeep();
X				break;
X			case LEFTKEY:
X				rotate( LEFT );
X				break;
X			case RIGHTKEY:
X				rotate( RIGHT );
X				break;
X			case SHOOT:
X				shoot();
X				break;
X			case THRUST:
X				thrust();
X				break;
X	       		case QUIT:
X				cleanup();
X		}
X		moverocks();
X		moveshots();
X		moveship();
X		printscreen();
X		collission_check();   
X	}
X	if( explode ){
X		debrislist[0].x = myship.x;
X		debrislist[0].y = myship.y;
X		debrislist[0].xdelta = -1;
X		debrislist[0].ydelta = 0;
X		debrislist[1].x = myship.x;
X		debrislist[1].y = myship.y;
X		debrislist[1].xdelta = 0;
X		debrislist[1].ydelta = 1;
X		debrislist[2].x = myship.x;
X		debrislist[2].y = myship.y;
X		debrislist[2].xdelta = 1;
X		debrislist[2].ydelta = -1;
X	}
X	for(i=0; i < RANGE + 5 ; i++){ 
X		moverocks();
X		moveshots();
X		if( explode )
X			movedebris();
X		else
X			moveship();
X		printscreen();
X	}
X	clear();
X}
X
rotate( which_way ) 
int which_way;
X{
X	wrastop(wn,ship[direction],2,screen,WIDTH,0,0,myship.x,myship.y,SHIP_WIDTH,SHIP_HEIGHT,SRCSRC,DSTCAM,0);
X	direction += which_way;
X	if ( direction == 8 )
X		direction = 0;
X	else if ( direction == -1 )
X		direction = 7;
X	wrastop(wn,ship[direction],2,screen,WIDTH,0,0,myship.x,myship.y,SHIP_WIDTH,SHIP_HEIGHT,SRCSRC,DSTOR,0);
X}
X
togglebeep()
X{
X	beepflag = 1 - beepflag;
X}
X
void collission_check()
X{
X	int i;
X
X	for (i = 0; i < nrocks;i++){
X		if ( collide( myship, SHIP_WIDTH, SHIP_HEIGHT, rocklist[i], rockwidth[ rocklist[i].size ], rockheight[ rocklist[i].size ] ) ){
X			quitflag = TRUE;
X			explode = TRUE;
X			men -= 1;  
X			level -= 1;
X		}
X	}
X}
X
X/*
X * General collision detection routine based on overlapping rectangles.
X * Wraparound is considered only for second (ie. b ) rectangle.
X */
X
int collide( apos, awidth, aheight, bpos, bwidth, bheight )
position apos;
int awidth;
int aheight;
position bpos;
int bwidth;
int bheight;
X{
X
X	/* check for regular y-axis overlap */
X	
X	if( (bpos.y >= apos.y - bheight) && (bpos.y <= apos.y + aheight) )
X	{
X
X		/* check for regular x-axis overlap */
X
X		if( (bpos.x >= apos.x - bwidth) && (bpos.x <= apos.x + awidth) )
X			return( TRUE );
X
X		/* check for wraparound x-axis overlap */
X
X		if( (bpos.x - SCREEN_WIDTH >= apos.x - bwidth) && 
X		    (bpos.x -SCREEN_WIDTH <= apos.x + awidth) )
X			return( TRUE );
X
X		else
X			return( FALSE );
X	}
X
X	/* check for wraparound y-axis overlap */
X
X	else if( (bpos.y - SCREEN_HEIGHT >= apos.y - bheight) && 
X		 (bpos.y - SCREEN_HEIGHT <= apos.y + aheight) )
X	{
X
X		/* check for regular x-axis overlap */
X
X		if( (bpos.x >= apos.x - bwidth) && (bpos.x <= apos.x + awidth) )
X			return( TRUE );
X
X		/* check for wraparound x-axis overlap */
X
X		if( (bpos.x - SCREEN_WIDTH >= apos.x - bwidth) && 
X		    (bpos.x - SCREEN_WIDTH <= apos.x + awidth) )
X			return( TRUE );
X
X		else
X			return( FALSE );
X	}
X
X	/* no overlap */
X	
X	else
X		return( FALSE );
X}
X
printscore()
X{
X	char scorestr[7];
X	char outstr[20];
X	int digit;
X	int tmpscore;
X	int index;
X	
X	tmpscore = score;
X	strcpy( outstr , "score : ");
X	for( index = 0; index < 5; index++ )
X		scorestr[index] = ' ';
X	scorestr[6] = '\0';
X	for( index = 5; tmpscore > 0; index-- ) {
X		digit = tmpscore % 10;
X		tmpscore = (tmpscore - digit)/10;
X		scorestr[index] = digit + '0';
X	}
X	strcat( outstr, scorestr );
X	wprompt(wn,outstr);
X}
X
int randdir()
X{
X	int direction;
X
X	if ( rand() % 2 == 0 ) 
X		direction = -1;
X	else
X		direction = 1;
X	return( direction );
X}	
END_OF_FILE
if test 3910 -ne `wc -c <'game.c'`; then
    echo shar: \"'game.c'\" unpacked with wrong size!
fi
# end of 'game.c'
fi
if test -f 'init.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'init.c'\"
else
echo shar: Extracting \"'init.c'\" \(1691 characters\)
sed "s/^X//" >'init.c' <<'END_OF_FILE'
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X\**********************************************************/
X
X#include "rocks.h"
X
initscreen( level )
int level;
X{
X        int 		i,j,index;
X	char		menstr[15];
X	position	freezone; 
X
X	/* clean screen */    	
X
X       	wrastop(wn,screen,WIDTH,screen,WIDTH,0,0,0,0,SCREEN_WIDTH,SPACE_HEIGHT,SRCSRC,DSTCAM,0);
X	myship.x = SCREEN_WIDTH / 2;
X	myship.y = SCREEN_HEIGHT / 2;
X	freezone.x = myship.x - LARGE_ROCK_WIDTH;
X	freezone.y = myship.y - LARGE_ROCK_HEIGHT;
X	myship.xdelta = myship.ydelta = 0;
X        wrastop(0,ship[0],2,screen,WIDTH,0,0,myship.x,myship.y,16,16,SRCSRC,DSTOR,0);
X	nrocks = level;
X	srand( (long)time(0) );
X	for ( i = 0; i < nrocks; i++ ){
X		rocklist[i].size = LARGE;
X		rocklist[i].x = rand() % SCREEN_WIDTH;
X		rocklist[i].y = rand() % SPACE_HEIGHT;
X		while( collide( rocklist[i], LARGE_ROCK_WIDTH, LARGE_ROCK_HEIGHT, freezone, 2 * LARGE_ROCK_WIDTH, 2 * LARGE_ROCK_HEIGHT ) ){
X			rocklist[i].x = rand() % SCREEN_WIDTH;
X			rocklist[i].y = rand() % SPACE_HEIGHT;
X		}
X		rocklist[i].xdelta = randdir() * ((rand() % 2) + 1);
X		rocklist[i].ydelta = randdir() * ((rand() % 2) + 1);
X       		wrastop(0,rock[LARGE],8,screen,WIDTH,0,0,rocklist[i].x,rocklist[i].y,LARGE_ROCK_WIDTH,LARGE_ROCK_HEIGHT,SRCSRC,DSTOR,0);
X	}
X	printscreen();
X	strcpy( menstr, "men   :      " );
X	menstr[13] = men + '0';
X	menstr[14] = '\0';
X	wcmd( wn, menstr );
X	quitflag = FALSE;
X	direction = 0;
X	nshots = -1;
X}
END_OF_FILE
if test 1691 -ne `wc -c <'init.c'`; then
    echo shar: \"'init.c'\" unpacked with wrong size!
fi
# end of 'init.c'
fi
if test -f 'move.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'move.c'\"
else
echo shar: Extracting \"'move.c'\" \(5799 characters\)
sed "s/^X//" >'move.c' <<'END_OF_FILE'
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X\**********************************************************/
X
X#include "rocks.h"
X
movedebris()
X{
X	int i;
X
X	for( i = 0; i < 3; i++){
X	
X		/* 
X		 * move debris
X		 */
X	
X		debrislist[i].x += debrislist[i].xdelta;
X		debrislist[i].y += debrislist[i].ydelta;	
X	
X		/* 
X		 * check for wrap around 
X		 */
X	
X		if ( debrislist[i].x > SCREEN_WIDTH - SHIP_WIDTH )
X			debrislist[i].x = 0;
X		else if ( debrislist[i].x < 0 )
X			debrislist[i].x = SCREEN_WIDTH - SHIP_WIDTH;
X		if ( debrislist[i].y > SCREEN_HEIGHT - SHIP_HEIGHT )
X			debrislist[i].y = 0;
X		else if ( debrislist[i].y < 0 )
X			debrislist[i].y = SCREEN_HEIGHT - SHIP_HEIGHT;
X	
X		/*
X		 * place debris in new position 
X		 */
X	
X		wrastop(wn,debris[i],2,screen,WIDTH,0,0,debrislist[i].x,debrislist[i].y,SHIP_WIDTH,SHIP_HEIGHT,SRCSRC,DSTOR,0);
X	}
X}
X
moveship()
X{
X
X	/* 
X	 * move ship
X	 */
X
X	myship.x += myship.xdelta;
X	myship.y += myship.ydelta;	
X
X	/* 
X	 * check for wrap around 
X	 */
X
X	if ( myship.x > SCREEN_WIDTH - SHIP_WIDTH )
X		myship.x = 0;
X	else if ( myship.x < 0 )
X		myship.x = SCREEN_WIDTH - SHIP_WIDTH;
X	if ( myship.y > SCREEN_HEIGHT - SHIP_HEIGHT )
X		myship.y = 0;
X	else if ( myship.y < 0 )
X		myship.y = SCREEN_HEIGHT - SHIP_HEIGHT;
X
X	/*
X	 * place ship in new position 
X	 */
X
X	wrastop(wn,ship[direction],2,screen,WIDTH,0,0,myship.x,myship.y,SHIP_WIDTH,SHIP_HEIGHT,SRCSRC,DSTOR,0);
X}
X
moverocks()
X{
X	int i;
X
X	/*
X	 * erase screen bitmap
X	 */
X
X	wrastop(wn,0,0,screen,WIDTH,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT+LARGE_ROCK_HEIGHT,SRCPAT,DSTSRC,0);
X
X	/*
X	 * move each rock one at a time
X	 */
X
X	for ( i = 0; i < nrocks; i++ ){
X
X		/* move rock to new location */ 
X
X		rocklist[i].x += rocklist[i].xdelta; 
X		rocklist[i].y += rocklist[i].ydelta; 
X
X		/* check for wrap around */
X
X		if ( rocklist[i].x > SCREEN_WIDTH )
X			rocklist[i].x = 0;
X		else if ( rocklist[i].x < 0 )
X			rocklist[i].x = SCREEN_WIDTH;
X		if ( rocklist[i].y > SCREEN_HEIGHT )
X			rocklist[i].y = 0;
X		else if ( rocklist[i].y < 0 )
X			rocklist[i].y = SCREEN_HEIGHT; 
X
X		/* put rock in new location */
X
X		wrastop(wn,rock[rocklist[i].size],8,screen,WIDTH,0,0,rocklist[i].x,rocklist[i].y,rockwidth[ rocklist[i].size ],rockheight[ rocklist[i].size ],SRCSRC,DSTOR,0);
X	}
X}
X
moveshots()
X{
X	int i,j,splitflag = FALSE;
X	
X	/*
X	 * move shots one at a time
X 	 */
X
X	for ( i = 0; i <= nshots; i++ ){
X
X		/* move shot */
X
X		shotlist[i].x += shotlist[i].xdelta;
X		shotlist[i].y += shotlist[i].ydelta;
X
X		/* wrap around */
X
X		if ( shotlist[i].x >= SCREEN_WIDTH )
X			shotlist[i].x = 0;
X		else if ( shotlist[i].x < 0 )
X			shotlist[i].x = SCREEN_WIDTH - 1;
X		if ( shotlist[i].y >= SCREEN_HEIGHT )
X			shotlist[i].y = 0;
X		else if ( shotlist[i].y < 0 )
X			shotlist[i].y = SCREEN_HEIGHT - 1; 
X
X		/* print new shot */
X
X		point(shotlist[i].x, shotlist[i].y);
X
X		/* check for collisions between each rock and each shot */
X
X		for ( j = 0; (j <= nrocks) && (splitflag == FALSE); j++ ){
X			if( collide( shotlist[i], 1, 1, rocklist[j], rockwidth[rocklist[j].size], rockheight[rocklist[j].size ]) ){
X	
X				/* erase shot */
X
X				point(shotlist[i].x, shotlist[i].y);
X		
X				/* remove shot from shotlist */
X
X				removeshot( i );
X
X				/* update score */ 
X
X				score += (3 - rocklist[j].size ) * 100;
X				printscore();
X
X				/* split rock into smaller units */
X
X				split_rock( j );
X				splitflag = TRUE;
X			}
X		}
X		
X		/* reduce range of shot by one */
X
X		shotlist[i].size -= 1;
X
X		/* if shot has worn out erase it */
X
X		if ( shotlist[i].size == 0 ){
X			point(shotlist[i].x, shotlist[i].y);
X			removeshot( i );
X		}
X	}
X}
X
split_rock( index )
int index;
X{
X	int i;
X
X	wrastop(wn,rock[rocklist[index].size],8,screen,WIDTH,0,0,rocklist[index].x,rocklist[index].y,rockwidth[ rocklist[index].size ], rockheight[ rocklist[index].size ],SRCSRC,DSTCAM,0);
X	 if ( rocklist[index].size != SMALL ){
X		for ( i = 0; i < 2; i++ ){
X			rocklist[nrocks+i].x = rocklist[ index ].x;
X			rocklist[nrocks+i].y = rocklist[ index ].y;
X			rocklist[nrocks+i].xdelta = randdir() * ((rand()%4)+(3-rocklist[nrocks+i].size));
X			rocklist[nrocks+i].ydelta = randdir() * ((rand()%4)+(3-rocklist[nrocks+i].size));
X			rocklist[nrocks+i].size = rocklist[ index ].size - 1;
X		}
X		nrocks += 2;
X	}
X	removerock( index );	
X	if( nrocks == 0 )
X		quitflag = TRUE;
X}
X
removerock( index )
int index;
X{
X	int i;
X
X	for( i = index; i < nrocks; i++ )
X		rocklist[ i ] = rocklist[ i + 1 ];
X	nrocks -= 1;
X}
X
removeshot( index )
int index;
X{
X	int i;
X
X	for( i = index; i < nshots; i++ )
X		shotlist[ i ] = shotlist[ i + 1 ];
X	nshots -= 1;
X}
X
printscreen()
X{
X	wrastop(wn,screen,WIDTH,screen,WIDTH,0,SCREEN_HEIGHT,0,0,SCREEN_WIDTH,LARGE_ROCK_HEIGHT,SRCSRC,DSTOR,0);
X	wrastop(wn,screen,WIDTH,0,0,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,SRCSRC,DSTSRC,0);
X}
X
clearscreen()
X{
X	wrastop(wn,screen,WIDTH,screen,WIDTH,0,0,0,0,SCREEN_WIDTH,SPACE_HEIGHT,SRCSRC,DSTCAM,0);
X}
X
thrust()
X{
X	switch ( direction ) {
X	case	0:	myship.ydelta -= 1;
X			break;
X	case	1:	myship.xdelta += 1;
X			myship.ydelta -= 1;
X			break;
X	case	2:	myship.xdelta += 1;
X			break;
X	case	3:	myship.xdelta += 1;
X			myship.ydelta += 1;
X			break;
X	case	4:	myship.ydelta += 1;	
X			break;
X	case	5:	myship.xdelta -= 1;
X			myship.ydelta += 1;
X			break;
X	case 	6:	myship.xdelta -= 1;
X			break;
X	case 	7:	myship.xdelta -= 1;
X			myship.ydelta -= 1;
X			break;
X	}
X	if( myship.xdelta > MAXTHRUST )
X		myship.xdelta = MAXTHRUST;
X	else if( myship.xdelta < (-1 * MAXTHRUST ) )
X		myship.xdelta = -1 * MAXTHRUST;
X	if( myship.ydelta > MAXTHRUST )
X		myship.ydelta = MAXTHRUST;
X	else if( myship.ydelta < (-1 * MAXTHRUST ) )
X		myship.ydelta = -1 * MAXTHRUST;
X}
END_OF_FILE
if test 5799 -ne `wc -c <'move.c'`; then
    echo shar: \"'move.c'\" unpacked with wrong size!
fi
# end of 'move.c'
fi
if test -f 'point.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'point.c'\"
else
echo shar: Extracting \"'point.c'\" \(471 characters\)
sed "s/^X//" >'point.c' <<'END_OF_FILE'
X#include "rocks.h"
X
X#define xtopixmask(x)	(dpixmask[((x) % 16)])
X
static unsigned short	dpixmask[16] =
X{
X	0x0001, 0x0002,	0x0004,	0x0008,	
X	0x0010, 0x0020,	0x0040,	0x0080,	
X	0x0100, 0x0200,	0x0400,	0x0800,
X	0x1000, 0x2000,	0x4000, 0x8000
X};
X
X
void point(x,y)
int x,y;
X{
X	unsigned short	bitmask;
X	int 		address;
X
X
X	/* Determine Address & Bit Mask For This Point */
X
X	address = y * 45; 
X	address += (int)(x / 16);
X
X	bitmask = xtopixmask(x);
X
X	screen[address] ^= bitmask;
X}
END_OF_FILE
if test 471 -ne `wc -c <'point.c'`; then
    echo shar: \"'point.c'\" unpacked with wrong size!
fi
# end of 'point.c'
fi
if test -f 'rocks.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rocks.c'\"
else
echo shar: Extracting \"'rocks.c'\" \(1114 characters\)
sed "s/^X//" >'rocks.c' <<'END_OF_FILE'
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X\**********************************************************/
X
X#include "rocks.h"
X
main(argc,argv)
int argc;
char *argv[];
X{
X	rockwidth[0] = SMALL_ROCK_WIDTH;
X	rockwidth[1] = MEDIUM_ROCK_WIDTH;
X	rockwidth[2] = LARGE_ROCK_WIDTH;
X	rockheight[0] = SMALL_ROCK_HEIGHT;
X	rockheight[1] = MEDIUM_ROCK_HEIGHT;
X	rockheight[2] = LARGE_ROCK_HEIGHT;
X	if( argc != 1 ) {
X		fprintf(stderr,"\nusage: rocks\n");
X		fprintf(stderr,"       There aint no arguments dummy, just type 'rocks'\n");
X		exit(-1);
X	} 
X        defsprites();		/* Define the little critters */
X        wininit();		/* Set up the full screen window */
X	beepflag = FALSE;
X	score = 0;
X	level = 4;
X	for(men = 2; men >= 0;level++) {
X	        initscreen( level );		/* Display initial screen */
X		playgame();
X	}
X	mvaddstr(12,35,"Game Over");
X	sleep(5);
X	cleanup();
X}
END_OF_FILE
if test 1114 -ne `wc -c <'rocks.c'`; then
    echo shar: \"'rocks.c'\" unpacked with wrong size!
fi
# end of 'rocks.c'
fi
if test -f 'rocks.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rocks.h'\"
else
echo shar: Extracting \"'rocks.h'\" \(2313 characters\)
sed "s/^X//" >'rocks.h' <<'END_OF_FILE'
X
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X* R.R.1                                                    *
X* Terra Cotta, Ontario                                     *
X* L0P 1N0                                                  *
X*                                                          *
X\**********************************************************/
X
X#include <sys/window.h>
X#include <fcntl.h>
X#include <tam.h>
X#include <termio.h>
X#include <stdio.h>
X
X#define SCREEN_WIDTH    720
X#define SCREEN_HEIGHT   300
X#define WIDTH		SCREEN_WIDTH / 8
X
X#define LARGE_ROCK_WIDTH	64
X#define LARGE_ROCK_HEIGHT	48
X#define MEDIUM_ROCK_WIDTH	32
X#define MEDIUM_ROCK_HEIGHT	24	
X#define SMALL_ROCK_WIDTH	16	
X#define SMALL_ROCK_HEIGHT	12	
X
unsigned short rockwidth[3];
unsigned short rockheight[3];
X
X#define MAXROCKS	100
X
X#define SPACE_HEIGHT	SCREEN_HEIGHT + LARGE_ROCK_HEIGHT
X#define SIZE		SCREEN_WIDTH * SPACE_HEIGHT / 16
X
X#define SHIP_WIDTH	16
X#define SHIP_HEIGHT	16
X#define MAXTHRUST	6
X
X#define SHOT_WIDTH	16
X#define SHOT_HEIGHT	16
X#define RANGE		20
X#define MAXSHOTS	10
X
X#define SHOTINC		8
X
X#define TRUE		1
X#define FALSE		0
X
X#define RIGHT		1
X#define LEFT           -1
X
X#define LARGE		2
X#define MEDIUM		1
X#define SMALL		0
X
X#define SHOOT		'a'
X#define BEEP		'b'
X#define LEFTKEY		'k'
X#define RIGHTKEY	'l'
X#define QUIT		'q'
X#define THRUST		' '
X
extern unsigned short patwhite[];
extern unsigned short patgray[];
extern unsigned short patltgray[];
extern unsigned short patblack[];
X
unsigned short rock[ 3 ][ LARGE_ROCK_WIDTH * LARGE_ROCK_HEIGHT / 16 ];
unsigned short ship[ 8 ][ SHIP_WIDTH * SHIP_HEIGHT / 16 ];
unsigned short debris[ 3 ][ SHIP_WIDTH * SHIP_HEIGHT / 16 ];
unsigned short shot[ SHOT_WIDTH * SHOT_HEIGHT / 16 ];
unsigned short screen[ SIZE ];
X
typedef struct position{
X        int x;
X        int y;
X	int xdelta;
X	int ydelta;
X	int size;
X} position;
X
position rocklist[ MAXROCKS ];
position myship;
position debrislist[ 3 ];
position shotlist[ MAXSHOTS ];
X
int wn;
int nrocks;
int nshots;
int beepflag;
int quitflag;
int score;
int men;
int level;
int direction;
END_OF_FILE
if test 2313 -ne `wc -c <'rocks.h'`; then
    echo shar: \"'rocks.h'\" unpacked with wrong size!
fi
# end of 'rocks.h'
fi
if test -f 'shot.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'shot.c'\"
else
echo shar: Extracting \"'shot.c'\" \(2032 characters\)
sed "s/^X//" >'shot.c' <<'END_OF_FILE'
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X\**********************************************************/
X
X#include "rocks.h"
X
shoot()
X{
X	if( nshots < MAXSHOTS - 1 ) {
X		nshots++;
X		shotlist[nshots].size = RANGE;
X		switch ( direction ){
X			case 0:	shotlist[nshots].x = myship.x + .5 * SHIP_WIDTH;
X				shotlist[nshots].y = myship.y; 
X				shotlist[nshots].xdelta = 0; 
X				shotlist[nshots].ydelta = -1 * SHOTINC; 
X				break;
X			case 1:	shotlist[nshots].x = myship.x + SHIP_WIDTH;
X				shotlist[nshots].y = myship.y; 
X				shotlist[nshots].xdelta = SHOTINC; 
X				shotlist[nshots].ydelta = -1 * SHOTINC; 
X				break;
X			case 2:	shotlist[nshots].x = myship.x + SHIP_WIDTH;
X				shotlist[nshots].y = myship.y + .5 * SHIP_HEIGHT -2; 
X				shotlist[nshots].xdelta = 2 * SHOTINC; 
X				shotlist[nshots].ydelta = 0; 
X				break;
X			case 3:	shotlist[nshots].x = myship.x + SHIP_WIDTH;
X				shotlist[nshots].y = myship.y + SHIP_HEIGHT -3; 
X				shotlist[nshots].xdelta = SHOTINC; 
X				shotlist[nshots].ydelta = SHOTINC; 
X				break;
X			case 4:	shotlist[nshots].x = myship.x + .5 * SHIP_WIDTH;
X				shotlist[nshots].y = myship.y + SHIP_HEIGHT; 
X				shotlist[nshots].xdelta = 0; 
X				shotlist[nshots].ydelta = SHOTINC;
X				break;
X			case 5:	shotlist[nshots].x = myship.x;
X				shotlist[nshots].y = myship.y + SHIP_HEIGHT -3; 
X				shotlist[nshots].xdelta = -1 * SHOTINC; 
X				shotlist[nshots].ydelta = SHOTINC; 
X				break;
X			case 6:	shotlist[nshots].x = myship.x;
X				shotlist[nshots].y = myship.y + .5*SHIP_HEIGHT -2; 
X				shotlist[nshots].xdelta = -2 * SHOTINC; 
X				shotlist[nshots].ydelta = 0; 
X				break;
X			case 7:	shotlist[nshots].x = myship.x;
X				shotlist[nshots].y = myship.y; 
X				shotlist[nshots].xdelta = -1 * SHOTINC; 
X				shotlist[nshots].ydelta = -1 * SHOTINC; 
X				break;
X		}
X	}
X}
END_OF_FILE
if test 2032 -ne `wc -c <'shot.c'`; then
    echo shar: \"'shot.c'\" unpacked with wrong size!
fi
# end of 'shot.c'
fi
if test -f 'sprites.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sprites.c'\"
else
echo shar: Extracting \"'sprites.c'\" \(8526 characters\)
sed "s/^X//" >'sprites.c' <<'END_OF_FILE'
X/**********************************************************\
X* Bugs : a bit-mapped arcade game for the AT&T UNIX PC.    *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X\**********************************************************/
X
X#include "rocks.h"
X
defsprites()
X{
X	int i;
X
X	/* define large */
X
X        rock[LARGE][0] = rock[LARGE][1] = rock[LARGE][2] = rock[LARGE][3] = 0xffff;
X	for ( i = 4; i < 188; i += 4 ){
X		rock[LARGE][i] = 0x0001;
X		rock[LARGE][i+1] = 0x0000;
X		rock[LARGE][i+2] = 0x0000;
X		rock[LARGE][i+3] = 0x8000;
X	}
X        rock[LARGE][188] = rock[LARGE][189] = rock[LARGE][190] = rock[LARGE][191] = 0xffff;
X
X	/* define medium */
X
X        rock[MEDIUM][0] = rock[MEDIUM][1] = 0xffff;
X	rock[MEDIUM][2] = rock[MEDIUM][3] = 0x0000;
X	for ( i = 4; i < 92 ; i += 4 ){
X		rock[MEDIUM][i] = 0x0001;
X		rock[MEDIUM][i+1] = 0x8000;
X		rock[MEDIUM][i+2] = 0x0000;
X		rock[MEDIUM][i+3] = 0x0000;
X	}
X        rock[MEDIUM][92] = rock[MEDIUM][93] = 0xffff;
X
X	/* define small */
X
X        rock[SMALL][0] = 0xffff;
X	rock[SMALL][1] = rock[SMALL][2] = rock[SMALL][3] = 0x0000;
X	for ( i = 4; i < 44 ; i += 4 ){
X		rock[SMALL][i] = 0x8001;
X		rock[SMALL][i+1] = 0x0000;
X		rock[SMALL][i+2] = 0x0000;
X		rock[SMALL][i+3] = 0x0000;
X	}
X        rock[SMALL][44] = 0xffff;
X
X	debris[0][0] = 0x0100;		/*	---- ---# ---- ----	*/
X	debris[0][1] = 0x0100;		/*	---- ---# ---- ----	*/
X	debris[0][2] = 0x0080;		/*	---- ---- #--- ----	*/
X	debris[0][3] = 0x0080;		/*	---- ---- #--- ----	*/
X	debris[0][4] = 0x0040;		/*	---- ---- -#-- ---- 	*/
X	debris[0][5] = 0x0040;		/* 	---- ---- -#-- ----	*/
X	debris[0][6] = 0x0020;		/*	---- ---- --#- ----	*/
X	debris[0][7] = 0x0020;		/*	---- ---- --#- ----	*/
X	debris[0][8] = 0x0010;		/*	---- ---- ---# ----	*/
X	debris[0][9] = 0x0010;		/*	---- ---- ---# ----	*/
X	debris[0][10] = 0x0008;		/*	---- ---- ---- #---	*/
X	debris[0][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	debris[1][0] = 0x0100;		/*	---- ---# ---- ----	*/
X	debris[1][1] = 0x0100;		/*	---- ---# ---- ----	*/
X	debris[1][2] = 0x0200;		/*	---- --#- ---- ----	*/
X	debris[1][3] = 0x0200;		/*	---- --#- ---- ----	*/
X	debris[1][4] = 0x0400;		/*	---- -#-- ---- ---- 	*/
X	debris[1][5] = 0x0400;		/* 	---- -#-- ---- ----	*/
X	debris[1][6] = 0x0800;		/*	---- #--- ---- ----	*/
X	debris[1][7] = 0x0800;		/*	---- #--- ---- ----	*/
X	debris[1][8] = 0x1000;		/*	---# ---- ---- ----	*/
X	debris[1][9] = 0x1000;		/*	---# ---- ---- ----	*/
X	debris[1][10] = 0x2000;		/*	--#- ---- ---- ----	*/
X	debris[1][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	debris[2][0] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][1] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][2] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][3] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][4] = 0x0000;		/*	---- ---- ---- ---- 	*/
X	debris[2][5] = 0x0000;		/* 	---- ---- ---- ----	*/
X	debris[2][6] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][7] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][8] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][9] = 0x0000;		/*	---- ---- ---- ----	*/
X	debris[2][10] = 0x3ff8;		/*	--## #### #### #---	*/
X	debris[2][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	ship[0][0] = 0x0100;		/*	---- ---# ---- ----	*/
X	ship[0][1] = 0x0100;		/*	---- ---# ---- ----	*/
X	ship[0][2] = 0x0380;		/*	---- --## #--- ----	*/
X	ship[0][3] = 0x0380;		/*	---- --## #--- ----	*/
X	ship[0][4] = 0x07c0;		/*	---- -### ##-- ---- 	*/
X	ship[0][5] = 0x07c0;		/* 	---- -### ##-- ----	*/
X	ship[0][6] = 0x0fe0;		/*	---- #### ###- ----	*/
X	ship[0][7] = 0x0fe0;		/*	---- #### ###- ----	*/
X	ship[0][8] = 0x1ff0;		/*	---# #### #### ----	*/
X	ship[0][9] = 0x1ff0;		/*	---# #### #### ----	*/
X	ship[0][10] = 0x3ff8;		/*	--## #### #### #---	*/
X	ship[0][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	ship[1][0] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[1][1] = 0xc000;		/*	##-- ---- ---- ---- 	*/
X	ship[1][2] = 0x7000;		/*	-### ---- ---- ----	*/
X	ship[1][3] = 0x7c00;		/*	-### ##-- ---- ----	*/
X	ship[1][4] = 0x3f00;		/*	--## #### ---- ----	*/
X	ship[1][5] = 0x3fc0;		/*	--## #### ##-- ----	*/
X	ship[1][6] = 0x1ff0;		/*	---# #### #### ----	*/
X	ship[1][7] = 0x1fc0;		/*	---# #### ##-- ----	*/
X	ship[1][8] = 0x0f00;		/*	---- #### ---- ----	*/
X	ship[1][9] = 0x0c00;		/*	---- ##-- ---- ----	*/
X	ship[1][10] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[1][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	ship[2][0] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[2][1] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[2][2] = 0x0004;		/*	---- ---- ---- -#--	*/
X	ship[2][3] = 0x001c;		/*	---- ---- ---# ##--	*/
X	ship[2][4] = 0x00fc;		/*	---- ---- #### ##--	*/
X	ship[2][5] = 0x07fc;		/*	---- -### #### ##--	*/
X	ship[2][6] = 0x3ffc;		/*	--## #### #### ##--	*/
X	ship[2][7] = 0x07fc;		/*	---- -### #### ##--	*/
X	ship[2][8] = 0x00fc;		/*	---- ---- #### ##--	*/
X	ship[2][9] = 0x001c;		/*	---- ---- ---# ##--	*/
X	ship[2][10] = 0x0004;		/*	---- ---- ---- -#--	*/
X	ship[2][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	ship[3][0] = 0x0000;		/*	---- ---- ---- ---- 	*/
X	ship[3][1] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[3][2] = 0x0c00;		/*	---- ##-- ---- ----	*/
X	ship[3][3] = 0x0f00;		/*	---- #### ---- ---- 	*/
X	ship[3][4] = 0x1fc0;		/*	---# #### ##-- ----	*/
X	ship[3][5] = 0x1ff0;		/*	---# #### #### ----	*/
X	ship[3][6] = 0x3fc0;		/*	--## #### ##-- ----	*/
X	ship[3][7] = 0x3f00;		/*	--## #### ---- ----	*/
X	ship[3][8] = 0x7c00;		/*	-### ##-- ---- ----	*/
X	ship[3][9] = 0x7000;		/*	-### ---- ---- ----	*/
X	ship[3][10] = 0xc000;		/*	##-- ---- ---- ----	*/
X	ship[3][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	ship[4][0] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[4][1] = 0x3ff8;		/*	--## #### #### #---	*/
X	ship[4][2] = 0x1ff0;		/*	---# #### #### ----	*/
X	ship[4][3] = 0x1ff0;		/*	---# #### #### ----	*/
X	ship[4][4] = 0x0fe0;		/*	---- #### ###- ----	*/
X	ship[4][5] = 0x0fe0;		/*	---- #### ###- ----	*/
X	ship[4][6] = 0x07c0;		/*	---- -### ##-- ----	*/
X	ship[4][7] = 0x07c0;		/*	---- -### ##-- ----	*/
X	ship[4][8] = 0x0380;		/*	---- --## #--- ----	*/
X	ship[4][9] = 0x0380;		/*	---- --## #--- ----	*/
X	ship[4][10] = 0x0100;		/*	---- ---# ---- ----	*/
X	ship[4][11] = 0x0100;		/*	---- ---# ---- ----	*/
X
X	ship[5][0] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[5][1] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[5][2] = 0x0030;		/*	---- ---- --## ----	*/
X	ship[5][3] = 0x00f0;		/*	---- ---- #### ----	*/
X	ship[5][4] = 0x03f8;		/*	---- --## #### #---	*/
X	ship[5][5] = 0x0ff8;		/*	---- #### #### #---	*/
X	ship[5][6] = 0x03fc;		/*	---- --## #### ##--	*/
X	ship[5][7] = 0x00fc;		/*	---- ---- #### ##--	*/
X	ship[5][8] = 0x003e;		/*	---- ---- --## ###-	*/
X	ship[5][9] = 0x000e;		/*	---- ---- ---- ###-	*/
X	ship[5][10] = 0x0003;		/*	---- ---- ---- --##	*/
X	ship[5][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	ship[6][0] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[6][1] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[6][2] = 0x2000;		/*	--#- ---- ---- ----	*/
X	ship[6][3] = 0x3800;		/*	--## #--- ---- ----	*/
X	ship[6][4] = 0x3f00;		/*	--## #### ---- ----	*/
X	ship[6][5] = 0x3fe0;		/*	--## #### ###- ----	*/
X	ship[6][6] = 0x3ffc;		/*	--## #### #### ##--	*/
X	ship[6][7] = 0x3fe0;		/*	--## #### ###- ----	*/
X	ship[6][8] = 0x3f00;		/*	--## #### ---- ----	*/
X	ship[6][9] = 0x3800;		/*	--## #--- ---- ----	*/
X	ship[6][10] = 0x2000;		/*	--#- ---- ---- ----	*/
X	ship[6][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	ship[7][0] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[7][1] = 0x0003;		/*	---- ---- ---- --##	*/
X	ship[7][2] = 0x000e;		/*	---- ---- ---- ###-	*/
X	ship[7][3] = 0x003e;		/*	---- ---- --## ###-	*/
X	ship[7][4] = 0x00fc;		/*	---- ---- #### ##--	*/
X	ship[7][5] = 0x03fc;		/*	---- --## #### ##--	*/
X	ship[7][6] = 0x0ff8;		/*	---- #### #### #---	*/
X	ship[7][7] = 0x03f8;		/*	---- --## #### #---	*/
X	ship[7][8] = 0x00f0;		/*	---- ---- #### ----	*/
X	ship[7][9] = 0x0030;		/*	---- ---- --## ----	*/
X	ship[7][10] = 0x0000;		/*	---- ---- ---- ----	*/
X	ship[7][11] = 0x0000;		/*	---- ---- ---- ----	*/
X
X	shot[0] = 0x0001;		/*	---- ---- ---- ---#	*/
X	shot[1] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[2] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[3] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[4] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[5] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[6] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[7] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[8] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[9] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[10] = 0x0000;		/*	---- ---- ---- ----	*/
X	shot[11] = 0x0000;		/*	---- ---- ---- ----	*/
X}
END_OF_FILE
if test 8526 -ne `wc -c <'sprites.c'`; then
    echo shar: \"'sprites.c'\" unpacked with wrong size!
fi
# end of 'sprites.c'
fi
if test -f 'stars.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'stars.c'\"
else
echo shar: Extracting \"'stars.c'\" \(584 characters\)
sed "s/^X//" >'stars.c' <<'END_OF_FILE'
X#include "rocks.h"
X
X#define SSIZE 	SCREEN_WIDTH * SCREEN_HEIGHT / 16 
X#define NSTARS 	100
X
stars() 
X{
X	char c;
X	int i,x,z;
X
X	srand48( (long)time(0) );
X       	wrastop(wn,screen,WIDTH,screen,WIDTH,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,SRCSRC,DSTCAM,0);
X	for ( i = 0; i < NSTARS; i++ ){
X		x = lrand48() % (SSIZE - 1);
X		z = lrand48() % 16;
X		screen[ x ] |= (1 << z);
X	}
X	mvaddstr(10,30,"    Rocks, 1989");
X	mvaddstr(12,30," By Hans Jespersen");
X	mvaddstr(23,30,"Hit Any Key To Start");
X       	wrastop(wn,screen,WIDTH,0,0,0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,SRCSRC,DSTXOR,0);
X	getchar();
X}
END_OF_FILE
if test 584 -ne `wc -c <'stars.c'`; then
    echo shar: \"'stars.c'\" unpacked with wrong size!
fi
# end of 'stars.c'
fi
if test -f 'window.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'window.c'\"
else
echo shar: Extracting \"'window.c'\" \(1003 characters\)
sed "s/^X//" >'window.c' <<'END_OF_FILE'
X/**********************************************************\
X* Rocks : a bit-mapped arcade game for the AT&T UNIX PC.   *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X\**********************************************************/
X
X#include "rocks.h"
X
void wininit()
X{
X	int wid;
X
X	close( 0 );
X	close( 1 );
X	close( 2 );
X	wid = open( "/dev/window",O_RDWR );
X	dup( 0 );
X	dup( 0 );
X        winit();
X        if( !iswind() ) {
X                fprintf(stderr,"\nSorry, you must use bit-mapped display!\n");
X                wexit(-1);
X        }
X        wn = wcreate( 0, 0, 25, 80, NBORDER );
X	wuser( wn, "Rocks" );
X	wprintf( wn, "\033[=1C" );
X	noecho();
X	stars();
X        clear();
X	nodelay( 0,1 );
X	wprompt( wn, "score :      0" );
X}
X 
void cleanup()
X{
X        clear();
X	wprintf( wn, "\033[=0C" );
X        wdelete( wn );		/* Quick, the boss is comming */
X        exit( 0 );
X}
END_OF_FILE
if test 1003 -ne `wc -c <'window.c'`; then
    echo shar: \"'window.c'\" unpacked with wrong size!
fi
# end of 'window.c'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0