Posted: 7th Nov 2015 19:23
Please comment if you have any thoughts on this code of mini map for rpg style game.

+ Code Snippet
sync on : sync rate 0
backdrop on
 
REM load an image
load image "C:\Users\lusi\Desktop\Treasure_Map.png", 4

create bitmap 1,screen width(),screen height()
global widthMax
global heightMax
global DIAMETER = 128
global RADIUS = 64
paste image 4,0,40

do
	
`Paste the map to bitmap 1, then make image memblock for
`minimap, and draw the minimap, then sprite the minimap back to camera 1.
set current bitmap 1
``

`Draw minimap circle(DIA = DIAMETER)
`How much is ok to update depends on the map
if timer() >= timestamp+400
	if mouseWithin(128,128,screen width(),screen height()) = 1
		get image 5,mousex()-RADIUS,mousey()-RADIUS,mousex()+RADIUS,mousey()+RADIUS
		drawCircle(DIAMETER)
	endif
	timestamp = timer()
endif

set current bitmap 0

text 0,0,"screen fps: "+str$(screen fps())
text 0,20,"mouseWithin:"+str$(mouseWithin(0,0,screen width(),screen height()))

if offsetDone = 0
	sprite 2,screen width()-RADIUS, RADIUS, 3
	offset sprite 2,RADIUS,RADIUS
	offsetDone = 1
endif

if spacekey() = 1 and spaceFlag = 0
	z = z +rnd(2)-rnd(2)
	rotate sprite 2,z
endif
if spacekey() = 0 then spaceFlag = 0
    sync
loop
 
`Just call argb() like you would rgb(), but send an extra variable for alpha.
function argb2(r, g, b, a)
    col = a<<24 || r<<16 || g<<8 || b
endfunction col

Rem LW - Function to draw circle depeding on cooldown
Function drawCircle(Dia As Integer)
	
REM create a memblock from the image
make memblock from image 1, 5
widthMax = memblock dword(1,0)
heightMax = memblock dword(1,4)

Lock Pixels

For x = 1 To DIA
	For y = 1 To DIA
		If SQRT((x-DIA/2)*(x-DIA/2) + (y-DIA/2)*(y-DIA/2)) < DIA/2
			if y <= DIA
				readLocation = point ((mousex()-100-DIA/2)+x,(mousey()-DIA/2)+y)
				location = ((y-1)*widthMax + x - 1)*4 + 12
				write memblock dword 1, location, readLocation
			endif
		else
			``Clear corners arround minimap
			location = ((y-1)*widthMax + x - 1)*4 + 12
			write memblock dword 1, location, argb2(255, 255, 255, 0)
		EndIf
	Next y
Next x

Unlock Pixels

make image from memblock 3, 1

EndFunction

function mouseWithin(StartX as integer,StartY as integer,EndX as integer,EndY as integer)
	if mousex() => StartX and mousex()<= EndX and mousey() => StartY and mousey() <= EndX
		moouseIs = 1
	endif
endfunction moouseIs

EDIT: Better version of the code, more fps.Actually i get max fps with it, as if there is just FPS command runing in main loop.