Portable Game Console
PoGa-4DGL Reference Manual
3.2 Writing your first PoGa game
Start a new Program
Click on the ‘New’ Icon again, the file type should be ‘4DGL program’, since that’s what you created last
time, then click OK. The platform should be PoGa-Goldelox, since that’s what we selected last time.
We are going to write a simple target shooting game, so lets start by including the color definitions and
adding some constants.
#inherit "4DGL_16bitColours.fnc"
#constant LineLen 5 // length of each crosshair line
#constant BoomPause 100 // pause between each expanding circle for the kaboom function
#constant TgtSize 4 // distance from centre-point to start of crosshair lines
#constant Indent 20 // Indent must be >= L TgtSize so cursor stays within
display area
And some global variables.
var xtgt, ytgt ; // position of the red circle (target)
var xcross, ycross ; // crosshair position
var xcrosso, ycrosso ; // old crosshair position
We’ll need some effects to be displayed when the target is hit.
// a sequence to show that we 'hit' the target
func kaboom()
var i ;
for (i := 1;i < Indent;i++)
gfx_CircleFilled(xtgt, ytgt,i, RAND());
beep(i*210,BoomPause/2) ; // beep as we go
pause(BoomPause) ;
next
endfunc
A routine to move the crosshairs around the screen.
func writescreen()
// erase old crosshairs
gfx_Line(xcrosso-TgtSize-LineLen,ycrosso,xcrosso-TgtSize,ycrosso,BLACK) ;
gfx_Line(TgtSize,ycrosso,LineLen,ycrosso,BLACK) ;
gfx_Line(xcrosso,ycrosso-TgtSize-LineLen,xcrosso,ycrosso-TgtSize,BLACK) ;
gfx_Line(xcrosso,TgtSize,xcrosso,LineLen,BLACK) ;
gfx_CircleFilled(xtgt, ytgt,TgtSize-1, RED); // incase crosshairs were covering it
// Write new crosshairs
gfx_Line(xcross-TgtSize-LineLen,ycross,xcross-TgtSize,ycross,WHITE) ;
gfx_Line(TgtSize,ycross,LineLen,ycross,WHITE) ;
gfx_Line(xcross,ycross-TgtSize-LineLen,xcross,ycross-TgtSize,WHITE) ;
gfx_Line(xcross,TgtSize,xcross,LineLen,WHITE) ;
endfunc
Note that we erase the old crosshairs by redrawing them in BLACK before drawing the new crosshairs in
white.
© 2011 4D Systems
www.4dsystems.com.au
Page 8 of 87