Quick Grid Related Problem

BlitzMax Forums/BlitzMax Beginners Area/Quick Grid Related Problem

Hi all,

Just a quicky here, that I hope someone can advise me on. I have a grid that is 100x64 of 48x48 tiles. I just need to be able to set a variable to show me which X 'tile' I'm in, and which Y 'tile' I'm in. So it's the CaveX and CaveY variables, at the bottom of my code snippet.

This works fine when I don't scroll the screen, but goes skewhiff when I scroll around my map.

Here's the simple grid / movement routine.

	For x=0 To CaveWidth 'Draw a basic grid as a guide
		For y=0 To CaveHeight
			DrawRect (x*TileWidth)-OffsetX,(y*TileHeight)-OffsetY,TileWidth,TileHeight
		Next
	Next
	SetColor 0,0,0
	For x=0 To CaveWidth
		For y=0 To CaveHeight
			DrawRect ((x*TileWidth)+1)-OffsetX,((y*TileHeight)+1)-OffsetY,TileWidth-1,TileHeight-1
		Next
	Next
	
	If KeyDown(Key_Right) Then 'Move right across the map
		OffsetX:+4
	End If
	If KeyDown(Key_Left) Then 'Move left across the map
		OffsetX:-4
	End If
	If KeyDown(Key_Up) Then 'Move up the map
		OffsetY:-4
	End If
	If KeyDown(Key_Down) Then 'Move down the map
		OffsetY:+4
	End If

	SetColor 255,255,255
	
	CaveX=Floor(MouseX())/48
	CaveY=Floor((MouseY()+40)/40)-1


Cheers!
M