Hi, CakeWizard. Welcome to the world of DBPro programming. Open the DBPro help file a walk through the code in this snippet. Saving and loading the grid is as simple as saving and loading an array, provided the array is dimensioned with the same size.
#constant ScreenWidth 640
#constant ScreenHeight 480
#constant GridImage 1
#constant TileImage 2
#constant TileSize 32
set display mode ScreenWidth, ScreenHeight, screen depth()
GetGridImage(GridImage, 0xFF202020)
GetTileImage(TileImage, 0xFFFF00FF)
dim ScreenGrid(ScreenWidth/TileSize*ScreenHeight/TileSize-1) as integer
for i= 0 to array count(ScreenGrid())
ScreenGrid(i) = 0
next i
sync on
sync rate 60
backdrop on
color backdrop 0
ink -1, 0
do
Control()
DrawScreen()
set cursor 0, 0
print "Mouse Tile X: ";mousex()/TileSize
print "Mouse Tile Y: ";mousey()/TileSize
print "Mouse Button: ";mouseclick()
sync
loop
end
function GetGridImage(imgID as integer, color as dword)
local i as integer
local j as integer
if (image exist(imgID))
exitfunction
endif
cls
ink color, 0
box 1, 1, TileSize-1, TileSize-1
get image imgID, 0, 0, TileSize, TileSize, 1
cls
for i=0 to ScreenWidth/TileSize-1
for j=0 to ScreenHeight/TileSize-1
paste image imgID, i*TileSize, j*TileSize
next j
next i
delete image imgID
get image imgID, 0, 0, ScreenWidth, ScreenHeight, 1
endfunction
function GetTileImage(imgID as integer, color as dword)
if (image exist(imgID))
exitfunction
endif
cls
ink color, 0
box 1, 1, TileSize-1, TileSize-1
get image imgID, 0, 0, TileSize, TileSize, 1
endfunction
function DrawScreen()
local i as integer
local j as integer
paste image GridImage, 0, 0
for i=0 to ScreenWidth/TileSize-1
for j=0 to ScreenHeight/TileSize-1
if (ScreenGrid(j*ScreenWidth/TileSize+i))
paste image TileImage, i*TileSize, j*TileSize
endif
next j
next i
endfunction
function Control()
local mb as integer
local mx as integer
local my as integer
mb = mouseclick()
if (mb)
mx = mousex()/TileSize
my = mousey()/TileSize
if (mb=1)
ScreenGrid(my*ScreenWidth/TileSize+mx) = 1
else
ScreenGrid(my*ScreenWidth/TileSize+mx) = 0
endif
endif
endfunction