Randomly Placing Objects?

BlitzMax Forums/BlitzMax Beginners Area/Randomly Placing Objects?

' The TRect object remembers the x, y and size of each Rectangle created.
Type TRect
	Global list:TList=CreateList()
	Field x:Int
	Field y:Int
	Field size:Int
	' Create a new rectangle at the position and size specified.
	Function Create(x:Int,y:Int,size:Int=50)
		Local temp:trect = New trect
		temp.x=x
		temp.y=y
		temp.size=size
		ListAddLast list,temp
	End Function
	' draw all the rectangles using their saved position.
	Function draw()
		For Local all:trect = EachIn list
			DrawRect all.x,all.y,all.size,all.size
		Next
	End Function	
End Type
Local gw:Int=800
Local gh:Int=600
Graphics gw,gh
SeedRnd MilliSecs()
' Create our rectangles with random X, Y positions.
For Local x:Int=0 To 4
	Local xpos:Int=Rand(0,gw)
	Local ypos:Int=Rand(0,gh)
	trect.Create(xpos,ypos)
Next
While Not KeyHit(KEY_ESCAPE)
	Cls
	' Draw all our rectangles,
	trect.draw()
	Flip
Wend