Source for "rocks" game (reposted)

Mark H. Weber mhw at lock60.UUCP
Mon Jan 8 16:42:21 AEST 1990


Here's the re-posted source for the "rocks" (asteroids) game. It's
a shell archive, use your editor to chop off everything up to the
!/bin/sh line, then feed it into sh. The version of "shar" that I 
used is not very sophisticated and will allow overwriting existing
files, so make sure you have the file in the proper directory before 
you do the extraction. For you who already have this, sorry for using
up the bandwidth, but a lot of people never got this. Have fun!

#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  Makefile
#	  README
#	  game.c
#	  init.c
#	  move.c
#	  point.c
#	  rocks.c
#	  rocks.h
#	  shot.c
#	  sprites.c
#	  stars.c
#	  window.c
#
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
XOBJS=rocks.o sprites.o window.o init.o game.o move.o shot.o stars.o point.o
XCFLAGS=-O
XLDFLAGS=-s
XLIBS=-ltam -ltermlib
X
Xrocks: $(OBJS)
X	$(CC) $(LDFLAGS) -o rocks $(OBJS) $(LIBS)
X
Xrocks.o: rocks.c rocks.h
X	$(CC) $(CFLAGS) -c rocks.c
X
Xsprites.o: sprites.c rocks.h
X	$(CC) $(CFLAGS) -c sprites.c 
X
Xwindow.o: window.c rocks.h
X	$(CC) $(CFLAGS) -c window.c
X
Xinit.o: init.c rocks.h
X	$(CC) $(CFLAGS) -c init.c
X
Xgame.o: game.c rocks.h
X	$(CC) $(CFLAGS) -c game.c
X
Xmove.o: move.c rocks.h
X	$(CC) $(CFLAGS) -c move.c
X
Xshot.o: shot.c rocks.h
X	$(CC) $(CFLAGS) -c shot.c
X
Xstars.o: stars.c rocks.h
X	$(CC) $(CFLAGS) -c stars.c
X
Xpoint.o: point.c rocks.h
X	$(CC) $(CFLAGS) -c point.c
X
Xclean:
X	rm $(OBJS)
X
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
sed 's/^X//' << 'SHAR_EOF' > README &&
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
Xas many of the elements of the original game as possible.
XHowever, this being the first release, not all elements of the 
Xthe arcade game have been implimented. Most notably, the 
Xlittle UFO-things (technical description eh?).
X
XThe 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
XAnyone wishing to change these controls should look at rocks.h
X
XPlease let me know what you think of this program. I may add
Xsome new features in the future and perhaps spruce up the 
Xgraphics. 
X
XEnjoy.
X
X- hans             hjespers at attcan.uucp (uunet!attcan!hjespers) 
SHAR_EOF
chmod 0644 README || echo "restore of README fails"
sed 's/^X//' << 'SHAR_EOF' > game.c &&
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
Xvoid collission_check();
Xint  explode;
X
Xplaygame()
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
Xrotate( which_way ) 
Xint 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
Xtogglebeep()
X{
X	beepflag = 1 - beepflag;
X}
X
Xvoid 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
Xint collide( apos, awidth, aheight, bpos, bwidth, bheight )
Xposition apos;
Xint awidth;
Xint aheight;
Xposition bpos;
Xint bwidth;
Xint 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
Xprintscore()
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
Xint randdir()
X{
X	int direction;
X
X	if ( rand() % 2 == 0 ) 
X		direction = -1;
X	else
X		direction = 1;
X	return( direction );
X}	
SHAR_EOF
chmod 0644 game.c || echo "restore of game.c fails"
sed 's/^X//' << 'SHAR_EOF' > init.c &&
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
Xinitscreen( level )
Xint 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}
SHAR_EOF
chmod 0644 init.c || echo "restore of init.c fails"
sed 's/^X//' << 'SHAR_EOF' > move.c &&
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
Xmovedebris()
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
Xmoveship()
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
Xmoverocks()
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
Xmoveshots()
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
Xsplit_rock( index )
Xint 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
Xremoverock( index )
Xint index;
X{
X	int i;
X
X	for( i = index; i < nrocks; i++ )
X		rocklist[ i ] = rocklist[ i + 1 ];
X	nrocks -= 1;
X}
X
Xremoveshot( index )
Xint index;
X{
X	int i;
X
X	for( i = index; i < nshots; i++ )
X		shotlist[ i ] = shotlist[ i + 1 ];
X	nshots -= 1;
X}
X
Xprintscreen()
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
Xclearscreen()
X{
X	wrastop(wn,screen,WIDTH,screen,WIDTH,0,0,0,0,SCREEN_WIDTH,SPACE_HEIGHT,SRCSRC,DSTCAM,0);
X}
X
Xthrust()
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}
SHAR_EOF
chmod 0644 move.c || echo "restore of move.c fails"
sed 's/^X//' << 'SHAR_EOF' > point.c &&
X#include "rocks.h"
X
X#define xtopixmask(x)	(dpixmask[((x) % 16)])
X
Xstatic 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
Xvoid point(x,y)
Xint 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}
SHAR_EOF
chmod 0644 point.c || echo "restore of point.c fails"
sed 's/^X//' << 'SHAR_EOF' > rocks.c &&
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
Xmain(argc,argv)
Xint argc;
Xchar *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}
SHAR_EOF
chmod 0644 rocks.c || echo "restore of rocks.c fails"
sed 's/^X//' << 'SHAR_EOF' > rocks.h &&
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
Xunsigned short rockwidth[3];
Xunsigned 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
Xextern unsigned short patwhite[];
Xextern unsigned short patgray[];
Xextern unsigned short patltgray[];
Xextern unsigned short patblack[];
X
Xunsigned short rock[ 3 ][ LARGE_ROCK_WIDTH * LARGE_ROCK_HEIGHT / 16 ];
Xunsigned short ship[ 8 ][ SHIP_WIDTH * SHIP_HEIGHT / 16 ];
Xunsigned short debris[ 3 ][ SHIP_WIDTH * SHIP_HEIGHT / 16 ];
Xunsigned short shot[ SHOT_WIDTH * SHOT_HEIGHT / 16 ];
Xunsigned short screen[ SIZE ];
X
Xtypedef struct position{
X        int x;
X        int y;
X	int xdelta;
X	int ydelta;
X	int size;
X} position;
X
Xposition rocklist[ MAXROCKS ];
Xposition myship;
Xposition debrislist[ 3 ];
Xposition shotlist[ MAXSHOTS ];
X
Xint wn;
Xint nrocks;
Xint nshots;
Xint beepflag;
Xint quitflag;
Xint score;
Xint men;
Xint level;
Xint direction;
SHAR_EOF
chmod 0644 rocks.h || echo "restore of rocks.h fails"
sed 's/^X//' << 'SHAR_EOF' > shot.c &&
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
Xshoot()
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}
SHAR_EOF
chmod 0644 shot.c || echo "restore of shot.c fails"
sed 's/^X//' << 'SHAR_EOF' > sprites.c &&
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
Xdefsprites()
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}
SHAR_EOF
chmod 0644 sprites.c || echo "restore of sprites.c fails"
sed 's/^X//' << 'SHAR_EOF' > stars.c &&
X#include "rocks.h"
X
X#define SSIZE 	SCREEN_WIDTH * SCREEN_HEIGHT / 16 
X#define NSTARS 	100
X
Xstars() 
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}
SHAR_EOF
chmod 0644 stars.c || echo "restore of stars.c fails"
sed 's/^X//' << 'SHAR_EOF' > window.c &&
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
Xvoid 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 
Xvoid cleanup()
X{
X        clear();
X	wprintf( wn, "\033[=0C" );
X        wdelete( wn );		/* Quick, the boss is comming */
X        exit( 0 );
X}
SHAR_EOF
chmod 0644 window.c || echo "restore of window.c fails"
exit 0



More information about the Unix-pc.sources mailing list