220 lines
6.2 KiB
Plaintext
220 lines
6.2 KiB
Plaintext
$FG,4$//These are the coordinates of the player.$FG$
|
|
I8 x=0,y=GR_HEIGHT/2;
|
|
|
|
|
|
$FG,4$//This is a FIFO (first-in first-out) data structure
|
|
//which keeps track of bullets. When a new bullet is
|
|
//fired, the $FG,2$shots_in$FG,4$ value is increased by one.
|
|
//When a bullet expires, the $FG,2$shots_out$FG,4$ value is increased
|
|
//by one. The in and out values loop-around, back to
|
|
//the start of the arrays.$FG$
|
|
#define MAX_SHOTS 32
|
|
I8 shots_in=0,shots_out=0,sx[MAX_SHOTS],sy[MAX_SHOTS];
|
|
|
|
|
|
|
|
$FG,4$//This is a fifo which keeps track of the bad guys.$FG$
|
|
#define MAX_GOONS 32
|
|
I8 goons_in=0,goons_out=0,gx[MAX_GOONS],gy[MAX_GOONS];
|
|
BoolU4 g_dead[MAX_GOONS];
|
|
|
|
|
|
$FG,4$//This is a graphic for the player's character.
|
|
//Graphics are created and edited by pressing
|
|
//$FG,2$CTRL-R$FG,4$. When created, they are assigned
|
|
//a number. Press $FG,2$CTRL-T$FG,4$, right now, to see
|
|
//the hidden definition for the picture. The
|
|
//text in quotes, you can set to whatever you want,
|
|
//but the ending number cannot be changed. It
|
|
//is set when the graphic is created and is used
|
|
//in future references to the picture.$FG$
|
|
|
|
|
|
$PI,"<PI 1>",1$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$PI,"<PI 3>",3$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$PI,"<PI 4>",4$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$FG,4$//This routine updates the window. It is called
|
|
//by the window manager system task. The $FG,2$tss$FG,4$ refers to
|
|
//the task which owns the window.$FG$
|
|
void DrawIt(TssStruct *tss)
|
|
{
|
|
I8 i,j;
|
|
|
|
$FG,4$//This creates an alias to the screen's
|
|
//bitmap. $FG,2$grbase2$FG,4$ is the bitmap which
|
|
//is redrawn every time the screen is updated.$FG$
|
|
GrBitMap *base=GrAlias(grbase2,tss);
|
|
|
|
ClearWinText(tss);
|
|
|
|
$FG,4$//Press $FG,2$CTRL-T $FG,4$now to see the hidden part
|
|
//where the picture number is encoded. $FG,2$IB$FG,4$ stands
|
|
//for "insert pointer to binary object".$FG$
|
|
base->bkcolor=BLACK;
|
|
GrElemsPlot(base,x,y,0,$IB,"<IB 1>",1$);
|
|
|
|
i=shots_out;
|
|
while (i!=shots_in) {
|
|
j=(i++)&(MAX_SHOTS-1);
|
|
GrLine(base,sx[j],sy[j],sx[j]-2,sy[j]);
|
|
}
|
|
i=goons_out;
|
|
while (i!=goons_in) {
|
|
j=(i++)&(MAX_SHOTS-1);
|
|
base->bkcolor=BLACK;
|
|
if (!g_dead[j]) {
|
|
if (gx[j]%10>5)
|
|
GrElemsPlot(base,gx[j],gy[j],0,$IB,"<IB 3>",3$);
|
|
else
|
|
GrElemsPlot(base,gx[j],gy[j],0,$IB,"<IB 4>",4$);
|
|
}
|
|
}
|
|
GrDel(base);
|
|
i=0;
|
|
PlotWinStr(tss,"If you aspire to making games,",BLUE<<4+YELLOW,0,i++);
|
|
PlotWinStr(tss,"you must learn to make-up rules.",BLUE<<4+YELLOW,0,i++);
|
|
}
|
|
|
|
$FG,4$//This routine is called when the task in charge of
|
|
//playing the background music is killed. It turns off
|
|
//the sound and ends the task with $FG,2$Exit$FG,2$. $FG$
|
|
void SongEndTsk()
|
|
{
|
|
Sound(0);
|
|
Exit;
|
|
}
|
|
|
|
void SongTsk()
|
|
{
|
|
$FG,4$//This establishes a function which will be called when
|
|
//this task is killed.$FG$
|
|
Fs->end_task_cb=&SongEndTsk;
|
|
ResetMusicSettings;
|
|
while (TRUE) {
|
|
Play("qDqDsDCDCetBCBqCqCqCqCqDqDsDCDCetBCBqCqCqCqCqCq"
|
|
"CsCCCCetCCBeBBeBBqBqBqCqCsCCCCetCCBeBBeBBqBqB");
|
|
}
|
|
}
|
|
|
|
void Goons()
|
|
{
|
|
U8 i,j,i1,j1,k=0,sc=0,ch=0,cmd,p1,p2;
|
|
void *old_update=Fs->update_win;
|
|
BoolU4 gun_on=FALSE;
|
|
BoolU4 old_wordstat=WordStat(OFF);
|
|
BoolU4 old_border=WinBorder(OFF);
|
|
|
|
$FG,4$//This creates a task to play music in the background.$FG$
|
|
TssStruct *song_tss=Spawn(&SongTsk,"Goons Song",Fs);
|
|
|
|
SetTypeMatic(0); $FG,4$//Make the keyboard faster$FG$
|
|
|
|
WinMax;
|
|
Fs->update_win=&DrawIt;
|
|
while (ch!=CH_ESC && ch!=CH_CTRLQ) {
|
|
if (cmd=ScanMsg(&p1,&p2,(1<<MSG_KEY_DOWN)|(1<<MSG_KEY_UP))) {
|
|
$FG,4$//With KEYBOARD messages, the two message parameters
|
|
//are the scan code and ascii value for the key.$FG$
|
|
sc=p2; ch=p1;
|
|
|
|
if (cmd==MSG_KEY_DOWN) {
|
|
$FG,4$//The least significant byte of the scan code
|
|
//identifies the key.$FG$
|
|
if (sc.u1[0]==SC_CURSOR_DOWN) {
|
|
y+=10;
|
|
if (y>GR_HEIGHT-30)
|
|
y=GR_HEIGHT-30;
|
|
} else if (sc.u1[0]==SC_CURSOR_UP) {
|
|
y-=10;
|
|
if (y<0)
|
|
y=0;
|
|
} else if (sc.u1[0]==SC_CURSOR_RIGHT ||
|
|
ch==CH_SPACE)
|
|
gun_on=TRUE;
|
|
} else if (cmd==MSG_KEY_UP) {
|
|
if (sc.u1[0]==SC_CURSOR_RIGHT ||
|
|
ch==CH_SPACE)
|
|
gun_on=FALSE;
|
|
}
|
|
}
|
|
|
|
i=shots_out;
|
|
while (i!=shots_in) {
|
|
j=(i++)&(MAX_SHOTS-1);
|
|
sx[j]+=5;
|
|
if (sx[j]>GR_WIDTH)
|
|
shots_out++;
|
|
else {
|
|
i1=goons_out;
|
|
while (i1!=goons_in) {
|
|
j1=(i1++)&(MAX_GOONS-1);
|
|
if (sy[j]>=gy[j1] && sy[j]<=gy[j1]+60 &&
|
|
sx[j]>=gx[j1] && sx[j]<=gx[j1]+40) {
|
|
g_dead[j1]=TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (gun_on) {
|
|
j=shots_in&(MAX_SHOTS-1);
|
|
sx[j]=x+30;
|
|
sy[j]=y+8;
|
|
shots_in++;
|
|
}
|
|
|
|
$FG,4$//This runs one out of four passes through this loop.$FG$
|
|
if (!(k % 4)) {
|
|
i=goons_out;
|
|
while (i!=goons_in) {
|
|
j=(i++)&(MAX_GOONS-1);
|
|
gx[j]-=1;
|
|
if (gx[j]<25)
|
|
goons_out++;
|
|
}
|
|
}
|
|
|
|
$FG,4$//This runs one out of 150 passes through this loop.$FG$
|
|
if (!(k%150)) {
|
|
j=goons_in&(MAX_GOONS-1);
|
|
gx[j]=GR_WIDTH-30;
|
|
gy[j]=RandU4%(GR_HEIGHT-50)+25;
|
|
g_dead[j]=FALSE;
|
|
goons_in++;
|
|
}
|
|
k++;
|
|
|
|
Sleep(10); $FG,4$//Swap this task-out for 10 miliseconds.$FG$
|
|
}
|
|
Kill(song_tss); $FG,4$//get rid of song task$FG$
|
|
Fs->update_win=old_update; $FG,4$//Restore original window update routine$FG$
|
|
WinBorder(old_border);
|
|
WordStat(old_wordstat);
|
|
}
|
|
|
|
Goons; $FG,4$// run program when #included$FG$
|
|
$FG$ |