Hm, the relativetileX thing confused me, i'm not sure what it was for... I put in simpler code there, that seems to work fine. But it's possible I don't get what it was meant to do...
The collision you coded wasn't working because it was checking the grid value of the mouse position, not the player. I coded a simple little block check function which I like to use. Using a function is good practice, because then the same function can be used by the player, enemies etc. to check if a path is blocked. Hope it all makes sense... the only changes I made should be at the mouse part and the added function after the player input bit.
Oh and, I added some extra debug text...
The RelativeTileX and RelativeTileY variables aren't used anymore I think, but PlayerX and PlayerY (the players location on the grid, rather than the position of the sprite) have been added.
flush video memory
sync rate 60
dimensionx=20
dimensiony=15
mapsizex=100
mapsizey=15
tilesize=32
xx=32
yy=427
`Tiles
cls -1
get image 1,0,0,31,31
cls rgb(255,0,0)
get image 2,0,0,31,31
cls rgb(0,255,0)
get image 3,0,0,20,20
cls rgb(235,158,44)
`Image for Debugging display panel
get image 4,0,0,83,70
cls
dim grid(mapsizex,mapsizey)
dim display(dimensionx,dimensiony)
`load array "tilemap",grid(x,y)
`Read in tilemap
for y=1 to mapsizey
for x=1 to mapsizex
read grid(x,y)
grid(x,y)=grid(x,y)
next x
next y
color backdrop 0
do
`Player
sprite 1,xx,yy,3
`paste tilemap to screen
for x=1 to dimensionx
for y=1 to dimensiony
display(x,y)=grid(x+cx,y+cy)
paste image display(x,y),(x-1)*32,(y-1)*32
next y
next x
`Mouse position when selecting Tile
TileX=((mousex())/TileSize)+cx+1
TileY=((mousey())/TileSize)+cy+1
`Change Tile number
if mouseclick()=1 and TileX<=MapSizex and TileY<=MapSizey
grid(TileX,TileY)=1
`wait 100
endif
if mouseclick()=2 and TileX<=MapSizex and TileY<=MapSizey
Grid(TileX,TileY)=2
`wait 100
endif
`**********************************************************************************************************************************************
`Debugging information
`**********************************************************************************************************************************************
`Tile Number
for x=1 to dimensionx
for y=1 to dimensiony
ink rgb(0,255,0),0
set text size 14
text (x-1)*32+15,(y-1)*32+5,str$(display(x,y))
next y
next x
`Current TileX and TileY position
paste image 4,553,10,100
set text font "arial"
set text size 12
ink rgb(0,0,255),0
`text 580,10,str$(cx+relativeTileX)
`text 580,20,str$(cy+relativeTileY)
text 555,10,"TileX : "+str$(TileX)
text 555,20,"TileY : "+str$(TileY)
`Player position
text 555,40,"Player X-Pos : "+str$(xx+cx)
text 555,50,"Player Y-Pos : "+str$(yy+cy)
text 555,70,"Player XGRID : "+str$(PlayerX)
text 555,80,"Player YGRID : "+str$(PlayerY)
text 555,90,"GRID VALUE : "+Str$(grid(playerx,playery))
`**********************************************************************************************************************************************
`Player controls
` this gets the players X and Y values on the grid, rather than the screen positions
PlayerX=((xx+tilesize)/TileSize)+cx
PlayerY=((yy+tilesize)/TileSize)+cy
if rightkey()=1 and x+cx<mapsizex+1 and blocked(PlayerX+1,PlayerY)=0 then cx=cx+1
if leftkey()=1 and x+cx>21 and blocked(PlayerX-1,PlayerY)=0 then cx=cx-1
`if escapekey()=1
`save array "tilemap",grid(x,y)
`exit
`endif
loop
end
FUNCTION blocked(x,y)
` this function is used to check if a particular grid is clear or blocked
blockvalue=0
if grid(x,y)=2 then blockvalue=1
ENDFUNCTION blockvalue
`remstart
data 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2
data 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 2,1,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
The way it seems you're doing things though, is that the level itself is moving, rather than the player moving. Which works well enough, but it's not the way i'd do things. In most platform games, the camera will only scroll along the level when the player approaches the edge of the screen. I could try and incorporate that if you like?