![PoGa 4DGL Reference Manual Download Page 9](http://html1.mh-extra.com/html/poga/4dgl/4dgl_reference-manual_1570571009.webp)
Portable Game Console
PoGa-4DGL Reference Manual
And now the main function, compile and download, saving it as 'Target.4dg'.
func main()
var i, newgame;
SEED(peekB(SYSTEM_TIMER_LO)) ;
newgame := 1 ;
while(1)
if (newgame == 1) // if this is a new game
xcross := 63 ; // set crosshairs to screen centre
ycross := 63 ;
xcrosso := 63 ;
ycrosso := 63 ;
xtgt := (ABS(RAND()) % (128 - 2*Indent)) + Indent ; // make rand pos for the tgt
ytgt := (ABS(RAND()) % (128 - 2*Indent)) + Indent ;
gfx_Cls(); // clear the screen
newgame := 0 ; // new game now set, clear newgame flag
endif
writescreen() ; // update display with crosshair and target
xcrosso := xcross ; // save current crosshair, needed so we can erase old position
ycrosso := ycross ;
while((i := joystick()) == 0) ; // read the joystick value
pause(50) ; // pause a little bit, so we get autorepeat
if ((i == UP) && (ycross != Indent))
// move crosshair if within bounds
ycross := ycross -1 ;
else if ((i == DOWN) && (ycross != 128-Indent-1))
ycross := 1 ;
else if ((i == RIGHT) && (xcross != 128-Indent-1))
xcross := 1;
else if ((i == LEFT) && (xcross != Indent))
xcross := xcross -1;
else if (i == BTNB) // else see if it was the fire button
beep(20,200) ;
if ((xcross == xtgt) && (ycross == ytgt)) // if cross is same as the target
kaboom() ; // do the kaboom sequence
newgame := 1 ; // set flag so we start a new game
endif
endif
wend // loop forever
endfunc
A snapshot of the 'Target.4dg'.
© 2011 4D Systems
www.4dsystems.com.au
Page 9 of 87