Quick Grid Related Problem

BlitzMax Forums/BlitzMax Beginners Area/Quick Grid Related Problem

Not a problem, your help is appreciated! :)

'Cave Editor v0.1
'(C) Matt Vinyl 
'Version Date: 01/06/2008


'--------General Declarations

Graphics 1024,768 'Screen width and height in pixels

SetBlend Alphablend

Const TileWidth=48 'Width of tile in pixels
Const TileHeight=48 'Height of tile in pixels
Const CaveWidth=100 'Width of cave in tiles
Const CaveHeight=64 'Height of cave in tiles

Type Tile 'Set up the tile type
	Field X 'X position of the tile
	Field Y 'Y position of the tile
	Field Tile 'The tile number
	Field State 'Tile state, has tile been parsed
End Type

Global Cave[CaveWidth,CaveHeight] 'Dimension the cave

Global OffsetX=0 'Movement offset flag (width)
Global OffsetY=0 'Movement offset flag (height)

Global CaveX=0 'X of currently selected grid tile
Global CaveY=0 'Y of currently selected grid tile

Global CurrentTile=1 'The currently selected tile to place in the map

Global TileCount=102

Global State=0 'A flag that denotes the current state of the programme
'0=Startup
'99=User as quit

HideMouse 'Hide the default mouse cursor


'--------Media Declarations

Global Tiles=LoadAnimImage ("gfx\tiles.png",48,48,0,TileCount) 'Load in the tile graphics


'--------Core Loop

Repeat

	Cls
	Fnc_Grid
	Fnc_Quit()
	Fnc_Debug()
	Flip

Until State=99 'Carry out loop until user quits


'--------Functions

Function Fnc_Quit() 'Quit the programme

	If KeyHit(Key_Escape) Then State=99

End Function

Function Fnc_Debug() 'Debug routines, to be removed before final version

	DrawText "MouseX:",0,0
	DrawText MouseX(),104,0
	DrawText "MouseY:",0,12
	DrawText MouseY(),104,12
	DrawText "CaveX:",0,24
	DrawText CaveX,104,24
	DrawText "CaveY:",0,36
	DrawText CaveY,104,36
	DrawText "Current Tile:",0,48
	DrawText CurrentTile,104,48

End Function

Function Fnc_Grid() 'Control moving around the grid
	
	SetColor 100,100,100
	
	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()+OffsetX)/48)
	'CaveY=Floor((MouseY()+OffsetY)/48)
	'CaveX=Floor(MouseX())/48 'Work out current grid square X
	'CaveY=Floor((MouseY()+40)/40)-1 'Work out current grid square Y
	DrawImage Tiles,CaveX*48,CaveY*48,CurrentTile 'Show current tile in position X Y

	If KeyHit(Key_Equals) Then 'Cycle through available tiles
		If CurrentTile<TileCount-1 Then 
			CurrentTile:+1
		Else
			CurrentTile=0
		End If
	End If
	If KeyHit(Key_Minus) Then
		If CurrentTile>0 Then 
			CurrentTile:-1
		Else
			CurrentTile=TileCount-1
		End If
	End If

End Function



Here's what I have so far. Note that I have commented out the two attempts I've tried so far.