I checked your quick snippet and made a few edits. This makes a few blocks in the center and then allows you to move around with proper collision.
sync on : sync rate 60
set display mode 800,600,16
hide mouse : backdrop on : color backdrop 0
gosub _variables
gosub _makeimages
gosub _readdata
disable escapekey
repeat
gosub _displaymap
gosub _makechar
sync
until spacekey() = 1 or keystate(1) = 1
enable escapekey
for i = 1 to 2 : delete image i : next i
undim map()
delete sprite 1
show mouse
end
_variables:
mapwidth = 9
mapheight = 9
tilesize = 32
dim map(mapwidth,mapheight)
charx = 96
chary = 96
sproffset = 16
`currentx ( the current x tile of the character )
`currenty ( the current y tile of the character )
return
_makeimages:
cls rgb(255,255,0)
get image 2,0,0,32,32
cls rgb(0,0,255)
get image 1,0,0,32,32
cls 0
return
_readdata:
restore map
for y = 0 to mapheight
for x = 0 to mapwidth
read map(x,y)
next x
next y
return
_displaymap:
for y = 0 to mapheight
for x = 0 to mapwidth
if map(x,y) > 0
paste image map(x,y),x*tilesize,y*tilesize
endif
next x
next y
return
_makechar:
`the tile numbers of each corner of the sprite
topleftx = (charx)/tilesize
toplefty = (chary)/tilesize
bottomleftx = (charx)/tilesize
bottomlefty = (chary + tilesize - 1)/tilesize
toprightx = (charx + tilesize - 1)/tilesize
toprighty = (chary)/tilesize
bottomrightx = (charx + tilesize - 1)/tilesize
bottomrighty = (chary + tilesize - 1)/tilesize
text 330,10,"topleft : " + str$(topleftx) + ", " + str$(toplefty)
text 330,30,"bottomleft : " + str$(bottomleftx) + ", " + str$(bottomlefty)
text 330,50,"topright : " + str$(toprightx) + ", " + str$(toprighty)
text 330,70,"bottomright: " + str$(bottomrightx) + ", " + str$(bottomrighty)
text 10,350,"map(tlx,tly) = " + str$(map(tlx,tly))
text 10,370,"map(trx,try) = " + str$(map(trx,try))
text 10,390,"map(blx,bly) = " + str$(map(blx,bly))
text 10,410,"map(brx,bry) = " + str$(map(brx,bry))
tlx = topleftx : trx = toprightx
blx = bottomleftx : brx = bottomrightx
tly = toplefty : try = toprighty
bly = bottomlefty : bry = bottomrighty
if tlx > 0 and tlx < 10 and tly > 0 and tly < 10
if upkey() and map(tlx,tly) = 0 and map(trx,try) = 0
t = chary - 1 : t = (t) / tilesize : tly = t : try = t
if map(tlx,tly) = 0 and map(trx,try) = 0 then dec chary
endif
if downkey() and map(blx,bly) = 0 and map(brx,bry) = 0
t = chary + 1 : t = (t + tilesize - 1) / tilesize : bly = t : bry = t
if map(blx,bly) = 0 and map(brx,bry) = 0 then inc chary
endif
if rightkey() and map(trx,try) = 0 and map(brx,bry) = 0
t = charx + 1 : t = (t + tilesize - 1) / tilesize : trx = t : brx = t
if map(trx,try) = 0 and map(brx,bry) = 0 then inc charx
endif
if leftkey() and map(tlx,tly) = 0 and map(blx,bly) = 0
t = charx - 1 : t = (t) / tilesize : tlx = t : blx = t
if map(tlx,tly) = 0 and map(blx,bly) = 0 then dec charx
endif
endif
sprite 1,charx,chary,2
return
`_________________________
REM DATA
`_________________________
map:
data 1,1,1,1,1,1,1,1,1,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,0,0,0,0,1,1,1,0,1
data 1,0,0,0,1,0,0,0,0,1
data 1,0,0,1,0,0,0,0,0,1
data 1,0,1,0,0,0,0,0,0,1
data 1,0,0,0,0,0,0,0,0,1
data 1,1,1,1,1,1,1,1,1,1
Hope this is helpful,
LB
So many games to code......so little time.