TileMap Array and only drawing whats on screen?

BlitzMax Forums/BlitzMax Beginners Area/TileMap Array and only drawing whats on screen?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I came up with my own noob way of doing it thanks to understanding what tonyg was doing.

Code here if anyone wants it.

SuperStrict

Graphics 800, 600

Global MapWidth:Int = 1600 / 25
Global MapHeight:Int = 1600 / 25

Global MapStartX:Int = 50
Global MapSTartY:Int = 50

Global MapXOffset:Int, MapYOffset:Int

Global array:Int[MapWidth, MapHeight] 

Print MapWidth

For Local x:Int = 0 Until MapWidth
	For Local y:Int = 0 Until MapHeight
		array[x, y] = Rand(0, 5) 
	Next
Next

Global startmapx:Int = 0, startmapy:Int = 0

While Not KeyHit(KEY_ESCAPE) 
	Cls
		
		DrawMap() 
		MoveMap() 
		
	Flip
Wend

Function MoveMap() 
	If KeyHit(KEY_LEFT) 
		If startmapx <= 0
			startmapx = 0
			MapStartX = 50
		Else
			MapXOffset:-1
			startmapx:-1
			MapStartX:+25
		EndIf
	ElseIf KeyHit(KEY_RIGHT) 
		If startmapx < MapWidth - 28
			MapXOffset:+1
			startmapx:+1
			MapStartX:-25
		Else
			startmapx = MapWidth - 28
		End If
	End If
	
	If KeyHit(KEY_UP) 
		If startmapy <= 0
			startmapy = 0
			MapSTartY = 50
		Else
			MapYOffset:-1
			startmapy:-1
			MapSTartY:+25
		EndIf
	ElseIf KeyHit(KEY_DOWN) 
		If startmapy < MapHeight - 20
			MapYOffset:+1
			startmapy:+1
			MapSTartY:-25
		Else
			startmapy = MapHeight - 20
		EndIf
	End If
	
End Function


Function DrawMap() 
	Local endmapx:Int, endmapy:Int
		
	If MapXOffset + 25 > MapWidth
		endmapx=mapwidth
	Else
		endmapx = MapXOffset + 28
	EndIf
	If MapYOffset + 20 > MapHeight
		endmapy=mapheight
	Else
		endmapy = MapYOffset + 20
	EndIf
	
	
	For Local x:Int = startmapx Until endmapx
		For Local y:Int = startmapy Until endmapy
			Select array[x, y] 
				Case 0
					SetColor 255, 255, 255
					DrawRect MapStartX + x * 25, MapSTartY + y * 25, 25, 25
				Case 1
					SetColor 0, 255, 255
					DrawRect MapStartX + x * 25, MapSTartY + y * 25, 25, 25
				Case 2
					SetColor 255, 0, 255
					DrawRect MapStartX + x * 25, MapSTartY + y * 25, 25, 25
				Case 3
					SetColor 255, 255, 0
					DrawRect MapStartX + x * 25, MapSTartY + y * 25, 25, 25
				Case 4
					SetColor 0, 0, 255
					DrawRect MapStartX + x * 25, MapSTartY + y * 25, 25, 25
			End Select
		Next
	Next
End Function