objects query

BlitzMax Forums/BlitzMax Beginners Area/objects query

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.

No, each instance has its own set of values (unless you made them values global)

Graphics 640,480,0

' CREATE 100 OBJECTS
For n=0 Until 100
	New Test
Next

' MAIN LOOP
Repeat
	Cls
	Test.RenderAll()
	Flip 1
Until KeyDown(KEY_ESCAPE)


Type Test

	Global List:TList = New TList
	Field Link:TLink = ListAddLast(List,Self)

	Field x#, y#
	Field vx#,vy#
	
	Method New()
		x =Rnd(0,GraphicsWidth()-5)
		y =Rnd(0,GraphicsHeight()-5)
		vx=Rnd(-3,3)
		vy=Rnd(-3,3)
	EndMethod
	
	Method Render()
		x:+vx
		If x+5>GraphicsWidth() Or x<0 Then vx=-vx
		y:+vy
		If y+5>GraphicsHeight() Or y<0 Then vy=-vy
		DrawRect(Int(x),Int(y),5,5)
	EndMethod
	
	Function RenderAll()
		Local This:Test
		For This=EachIn This.List
			This.Render
		Next
	EndFunction
	
EndType