|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T a
Length: 7892 (0x1ed4)
Types: TextFile
Names: »ast_stuff.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/Sun/Asteroids/ast_stuff.c«
/* ast_stuff.c
*
* Various functions and procedures used by the asteroids game.
* Written by Rich Burridge - SUN Microsystems Australia (Melbourne).
*
* Version 3.0. - April 1987.
*
* No responsibility is taken for any errors inherent either to the code
* or the comments of this program, but if reported to me then an attempt
* will be made to fix them.
*/
#include <stdio.h>
#include <strings.h>
#include "bltstuff.h"
#include "asteroids.h"
#include <sys/types.h>
#include <sys/timeb.h>
#include <suntool/sunview.h>
#include <suntool/canvas.h>
extern Pixfont *pf ;
extern Pixwin *pw ;
/* For descriptions of these external variables, see ast_main.c */
extern char bonusstr[MAXLINE],new_key_vals[3][MAXLINE] ;
extern char old_key_vals[3][MAXLINE],path[MAXLINE],progname[MAXLINE] ;
extern char titlestring[MAXLINE],thisscore[MAXLINE] ;
extern struct hscore highscore[MAXHS] ;
extern struct timeb tstartflash,tlastflash ;
extern int basecount,bonusship,bonusshown,c,csi,csj,flashbonus,fuel ;
extern int fuellength,fuelmaxlength,fuelxoffset,givehelp,height ;
extern int key_stations[3],orgx,orgy,progstate,rr,score,scorei,scorethistank ;
extern int sfunc,width ;
addscore(s) /* Add up current total score. */
int s ;
{
int s10 ;
s10 = s*10 ;
score += s10 ;
scorethistank += s10 ;
if (score > bonusship)
{
SPRINTF(bonusstr," ** Bonus Spaceship ** ") ;
startflashbonus() ;
basecount += 1 ;
bonusship *= 2 ; /* double it. */
}
SPRINTF(titlestring," Score : %6d Ships : %6d ",score,basecount) ;
showtitle() ;
}
clear_screen()
{
BLT_SCRN(orgx,orgy,width,height,RCLR) ;
}
do_help_screen()
{
int x,y ;
int length = 0 ; /* Length of longest help line. */
int nolines = 0 ; /* Number of lines in help file. */
char line[MAXLINE] ; /* Current line read from help file. */
FILE *tf ; /* File descripter for help file. */
int texty = 20 ; /* Initial y coordinate for help message. */
char helpname[MAXLINE] ; /* Full help file pathname. */
SPRINTF(helpname,"%s%s",path,HELPNAME) ;
if ((tf = fopen(helpname,"r")) == NULL)
{
FPRINTF(stderr,"%s: can't open %s for help information.\n",
progname,helpname) ;
return ;
}
while (fgets(line,MAXLINE,tf) != NULL)
{
if (strlen(line) > length) length = strlen(line) ;
nolines++ ;
}
FCLOSE(tf) ;
x = (width - length*FONT_WIDTH - 20) / 2 ;
y = (height - nolines*15+texty) / 2 ;
draw_frame(x,y,length*FONT_WIDTH+20,nolines*15+texty) ;
tf = fopen(helpname,"r") ;
while (fgets(line,MAXLINE,tf) != NULL)
{
line[strlen(line)-1] = '\0' ;
SCHRFUNC(PIX_SRC) ;
WRITELN(x+10,y+texty,line) ;
texty += 15 ;
}
FCLOSE(tf) ;
}
doflashbonus()
{
struct timeb tnow ;
ftime(&tnow) ;
if (numticks(&tnow,&tlastflash) > FLICKERTIME)
{
bonusshown = !bonusshown ; /* on off on off every second. */
SCHRFUNC(RXOR) ;
WRITELN(orgx+6,orgy+FONT_HEIGHT-2,bonusstr) ;
tlastflash.time = tnow.time ;
tlastflash.millitm = tnow.millitm ;
}
/* See if time out, if so stop flash */
if (((tnow.time - tstartflash.time) > FLASHTIME) && !bonusshown)
{
flashbonus = 0 ;
addscore(0) ; /* to put score back on screen. */
}
}
draw_frame(x,y,fr_width,fr_height)
int x,y,fr_width,fr_height ;
{
BLT_SCRN(x,y,fr_width,fr_height,RSET) ;
BLT_SCRN(x+1,y+1,fr_width-2,fr_height-2,RCLR) ;
BLT_SCRN(x+3,y+3,fr_width-6,fr_height-6,RSET) ;
BLT_SCRN(x+5,y+5,fr_width-10,fr_height-10,RCLR) ;
}
function_keys(state) /* Set or reset the function keys. */
int state ;
{
int count = 176 ; /* 0xB0 -- the starting entry for strings. */
int fd,i ;
if ((fd = open("/dev/kbd",0,0)) < 0)
{
FPRINTF(stderr,"sidtool: can't open /dev/kbd\n") ;
exit(1) ;
}
for (i = 0; i < 3; i++) /* Set up function keys. */
{
if (state == KEY_SET)
{
get_key(fd,key_stations[i],old_key_vals[i],count) ;
set_key(fd,key_stations[i],new_key_vals[i],count++) ;
}
else set_key(fd,key_stations[i],old_key_vals[i],count++) ;
}
CLOSE(fd) ;
}
getnewscore(x,y) /* Get new user name for highscore. */
int x,y ;
{
if (c)
{
switch (c)
{
case BSPACE :
case DEL : if (scorei)
{
scorei-- ;
thisscore[scorei] = ' ' ;
thisscore[scorei+1] = '\0' ;
WRITELN(x,y,thisscore) ;
thisscore[scorei] = '\0' ;
}
break ;
case CR : thisscore[scorei] = '\0' ;
if (!scorei) WRITELN(100,220," ** No name given. **") ;
else
{
csj = MAXHS - 1 ;
while (--csj >= csi)
{
highscore[csj+1].score = highscore[csj].score ;
STRCPY(highscore[csj+1].who,highscore[csj].who) ;
}
highscore[csi].score = score ;
STRCPY(highscore[csi].who,thisscore) ;
puthighscore() ;
progstate = DOEND ;
}
break ;
default : if (c < ' ') break ;
thisscore[scorei++] = c ;
thisscore[scorei] = '\0' ;
WRITELN(x,y,thisscore) ;
}
c = 0 ;
}
}
get_options(argc,argv)
int argc ;
char *argv[] ;
{
char *arg ;
char *p ; /* Pointer to string following argument flag. */
/* Changed--PLAY
STRCPY(path,progname) ; /* Extract full path name for asteroid files. */
STRCPY(path,"/ufs/play/lib.sun");
if ((arg = rindex(path,'/')) == NULL) path[0] = '\0' ;
else *(++arg) = '\0' ;
STRCPY(titlestring," Asteroids V3.0. Rich Burridge.") ;
orgx = 0 ;
orgy = 0 ;
width = SWIDTH ;
height = SHEIGHT ;
givehelp = 1 ;
while (argc > 1 && (arg = argv[1])[0] == '-')
{
p = arg + 2 ;
switch (arg[1])
{
case 'h' : givehelp = 0 ; /* Don't display help message. */
break ;
case 'x' : width = atoi(p) ; /* Width of asteroids window. */
if (width < 500) width = 500 ;
break ;
case 'y' : height = atoi(p) ; /* Height of asteroids window. */
if (height < 500) height = 500 ;
break ;
}
argc-- ;
argv++ ;
}
}
rint(r)
int r ;
{
rr = ((rr*4705 + 1) & 32767) ;
if (!r) r = 1 ;
return(rr % r) ;
}
showfuel() /* Show how much fuel is left. */
{
int howmuch ;
howmuch = (int)(fuelmaxlength * ((double)fuel / (double)FULLTANK)) ;
if (howmuch != fuellength)
{
BLT_SCRN(fuelxoffset,height-FONT_HEIGHT,fuelmaxlength,FONT_HEIGHT-2,RCLR) ;
fuellength = howmuch ;
BLT_SCRN(fuelxoffset,height-FONT_HEIGHT,fuellength,FONT_HEIGHT-2,RXNOR) ;
}
}
showtitle() /* Display titlestring or bonus message. */
{
if (!flashbonus)
{
SCHRFUNC(RRPL) ;
WRITELN(orgx+6,orgy+FONT_HEIGHT-2,titlestring) ;
}
}
startflashbonus() /* start bonus flashing. */
{
flashbonus = 1 ;
bonusshown = 1 ;
SCHRFUNC(RRPL) ;
WRITELN(orgx+6,orgy+FONT_HEIGHT-2,bonusstr) ; /* Don't XOR the first one. */
ftime(&tstartflash) ; /* Get the time start. */
tlastflash.time = tstartflash.time ;
tlastflash.millitm = tstartflash.millitm ;
}