/**********************************************************\ * Bugs : a bit-mapped arcade game for the AT&T UNIX PC. * * * * By : Hans Jespersen * * * \**********************************************************/ #include "bugs.h" playgame() { int key; int moveflag; int xp, yp, bp, rp; flushinp(); moveflag = 0; for(; quitflag != TRUE ;) { key = wgetc( wn ); switch( key ) { case Mouse: wreadmouse( wn, &xp, &yp, &bp, &rp ); switch( bp ){ case MBUTL: moveflag = LEFT; break; case MBUTL|MBUTR: break; case MBUTM: shoot(); break; case MBUTM|MBUTL: shoot(); break; case MBUTM|MBUTR: shoot(); break; case MBUTALL: shoot(); break; case MBUTR: moveflag = RIGHT; break; default: moveflag = STOP; } break; case KILL: killshelters(); break; case SHOOT: shoot(); break; case BEEP: togglebeep(); break; case LEFTKEY: moveflag = LEFT; break; case STOPKEY: moveflag = STOP; break; case RIGHTKEY: moveflag = RIGHT; break; case QUIT: cleanup(); } moveshot(); movebug( bugnum ); bugshoot( bugnum ); movebase( moveflag ); moveufo(); } if( nbugs >= 0 ) men--; else { if( level < MAXLEVEL ) level++; else { if( chance > 20 ) chance -= 20; level = 0; } } sleep( 5 ); clear(); } togglebeep() { beepflag = 1 - beepflag; } shoot() { if( !shotflag ) { myshot.x = mybase.x + SHOT_OFFSET; myshot.y = mybase.y; shotflag = TRUE; } } killbug( index ) int index; { int i; wrastop(wn,bang,4,0,0,0,0,buglist[index].x,buglist[index].y,BANG_WIDTH,BANG_HEIGHT,SRCAND,DSTSRC,patblack); if(( index == bugnum ) && ( index == nbugs )) { movebug( index ); wrastop(wn,bang,4,0,0,0,0,buglist[index].x,buglist[index].y,BANG_WIDTH,BANG_HEIGHT,SRCAND,DSTSRC,patblack); } else { for( i = index; i < nbugs; i++ ) buglist[i] = buglist[i + 1]; } if( index < bugnum ) bugnum--; nbugs--; if( nbugs < 0 ) quitflag = TRUE; score += BUGSCORE; printscore(); } killshot( index ) int index; { int i; wrastop(wn,shot,2,0,0,0,0,shotlist[index].x,shotlist[index].y,REAL_SHOT_WIDTH,SHOT_HEIGHT,SRCAND,DSTSRC,patblack); for( i = index; i < nshots; i++ ) shotlist[i] = shotlist[i + 1]; nshots--; } killshelters() { int i; for( i = 0; i < MAXSHELTERS; i++ ) { wrastop(wn,shelter,4,0,0,0,0,shelterlist[i].x,shelterlist[i].y,SHELTER_WIDTH,SHELTER_HEIGHT,SRCAND,DSTSRC,patblack); shelterlist[i].x = -100; shelterlist[i].y = -100; } } int collide( apos, awidth, aheight, bpos, bwidth, bheight ) struct position apos; int awidth; int aheight; struct position bpos; int bwidth; int bheight; { if( (bpos.y >= apos.y - bheight) && (bpos.y <= apos.y + aheight) ){ if( (bpos.x >= apos.x - bwidth) && (bpos.x <= apos.x + awidth) ) return( TRUE ); else return( FALSE ); } else return( FALSE ); } printscore() { char scorestr[7]; char outstr[20]; int digit; int tmpscore; int index; tmpscore = score; strcpy( outstr , "score : "); for( index = 0; index <= 5; index++ ) scorestr[index] = ' '; scorestr[6] = '\0'; if( tmpscore == 0 ) scorestr[5] = '0'; else{ for( index = 5; tmpscore > 0; index-- ) { digit = tmpscore % 10; tmpscore = (tmpscore - digit)/10; scorestr[index] = digit + '0'; } } strcat( outstr, scorestr ); wprompt(wn,outstr); }