2d array as a type object

BlitzMax Forums/BlitzMax Beginners Area/2d array as a type object

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.

SuperStrict

Graphics 1024,768,0,75',32

Type Tmap

	Field levelmap:Int[,]
	Field Width:Int, Height:Int

	Function Create:TMap(w:Int, h:Int)
		
		Local This:TMap = New TMap
		This.levelmap = New Int[100,100]
		This.Width = w
		This.Height = h
		
		Local x:Int, y:Int
		For x=0 Until w
			For y=0 Until h
				This.levelmap[x,y]=Rand(0,1)
			Next
		Next
		
		Return This

	EndFunction

	Method drawmap()
		Local x:Int, y:Int
		For x=0 Until width
			For y=0 Until height
				If levelmap[x,y]=1
					SetColor 255,0,0	
				Else
					SetColor 0,255,0
				EndIf
				DrawRect x*16,y*16,16,16
			Next
		Next	
	End Method

End Type



Local Map:TMap = TMap.Create(100,100)

Repeat 

	Cls
	Map.drawmap()
	Flip

Until KeyDown(key_escape)


Sorry, dont have time to explain the changes right now, but it'll give you something to study. (maybe somebody else can give you some pointers on what you did wrong in your original code)