This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
// --------------------------------- //
// Project: ExampleTemplate
// --------------------------------- //
//_____________________________________________________________________________ DECLARATIONS
//............................................................................... CONs
Constants:
//............................................................................... VARs
Variables:
// mouse state variables
GLOBAL mx, my // mouse coordinates
GLOBAL mbl, mbm, mbr // mouse button left, middle, right
GLOBAL mxspeed, myspeed, mwheel // mouse x speed, y speed, mouse wheel
// main directory
GLOBAL MainDir$
//............................................................................... DIMs
DIMs:
//.............................................................................. TYPEs
TYPes:
//______________________________________________________________________________________ INI
// main initialization
GOSUB subINI
//________________________________________________________________________________ MAIN LOOP
MainLoop:
WHILE TRUE
// read mouse state
GOSUB subReadMouse
//...................................................................... MAIN CODE >>>
//...................................................................... <<< MAIN CODE
// draw mouse pointer
DRAWSPRITE 1, mx-15, my-15
// draw buffer on screen
SHOWSCREEN
WEND
//_________________________________________________________________________ SUBs / FUNCTIONs
// ------------------------------------------------------------- //
// -=# SUBINI #=-
// .............................................................
// main initialization
// ------------------------------------------------------------- //
SUB subINI:
//.................................................. LOAD GFX
GFX:
// get main/set GFX directory
MainDir$ = GETCURRENTDIR$()
SETCURRENTDIR(MainDir$ + "Media/GFX")
// load standard font-gfx : index 0
LOADFONT "smalfont.png", 0 // standard font
// set font index
SETFONT 0 // standard font
// mouse pointer
LOADSPRITE "MPointer.png", 1
//.................................................. LOAD SFX
SFX:
SETCURRENTDIR(MainDir$ + "Media/SFX")
//................................................ LOAD MUSIC
Music:
SETCURRENTDIR(MainDir$ + "Media/Music")
// reset to main directory
SETCURRENTDIR(MainDir$)
ENDSUB // SUBINI
// ------------------------------------------------------------- //
// -=# SUBREADMOUSE #=-
// .............................................................
// reads various mouse states
// ------------------------------------------------------------- //
SUB subReadMouse:
// write mouse state into variables
MOUSESTATE mx, my, mbl, mbr // x coord, y coord, left button, right button
mxspeed = MOUSEAXIS(0) // x axis (x speed)
myspeed = MOUSEAXIS(1) // y axis (y speed)
mwheel = MOUSEAXIS(2) // wheel (1 = up / -1 = down)
mbm = MOUSEAXIS(5) // middle button
ENDSUB // SUBREADMOUSE
// ------------------------------------------------------------- //
// -=# FNMOVEX #=-
// ------------------------------------------------------------- //
FUNCTION fnMoveX: lAngle, lx, lSpeed
DEC lAngle, 180
lx = lx + COS(lAngle) * lSpeed
RETURN lx
ENDFUNCTION // FNMOVEX
// ------------------------------------------------------------- //
// -=# FNMOVEY #=-
// ------------------------------------------------------------- //
FUNCTION fnMoveY: lAngle, ly, lSpeed
DEC lAngle, 180
ly = ly + SIN(lAngle) * lSpeed
RETURN ly
ENDFUNCTION // FNMOVEY
// ------------------------------------------------------------- //
// -=# FNGETANGLE #=-
// ................................................................
// computes angle between two points
// ------------------------------------------------------------- //
FUNCTION fnGetAngle: lx1, ly1, lx2, ly2
LOCAL lAngle
// ??? angle-computing-code
lAngle = MOD((ATAN(ly1-ly2,lx1-lx2)+360),360)
RETURN lAngle
ENDFUNCTION // FNGETANGLE
// ------------------------------------------------------------- //
// -=# FNGETDISTANCE #=-
// ------------------------------------------------------------- //
FUNCTION fnGetDistance: lx1, ly1, lx2, ly2
LOCAL lx, ly, lReturn
lx = lx1 - lx2
ly = ly1 - ly2
// ??? distance computing code
lReturn = SQR( ABS(lx * lx) + ABS(ly * ly) )
RETURN lReturn
ENDFUNCTION // FNGETDISTANCE
// declare gImgTest as GENSPRITE
gImgTest = GENSPRITE()
// draw mouse-cursor GFX
DRAWRECT 0, 0, 16, 16, RGB(255,255,255)
// grab mouse-cursor GFX and store it in gImgTest
GRABSPRITE gImgTest, 0, 0, 16, 16
// mouse state variables
GLOBAL mx, my, mb1, mb2
WHILE TRUE
// read mouse state
MOUSESTATE mx, my, mb1, mb2
// draw mouse cursor at mouse x/y coordinates
DRAWSPRITE gImgTest, mx, my
// when left mouse button is pressed, grab screen GFX
IF mb1; GRABSPRITE 0, 0, 0, 640, 480; ENDIF
SHOWSCREEN
WEND