need help at Eachin :-(

BlitzMax Forums/BlitzMax Beginners Area/need help at Eachin :-(

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.

can I suggest holding the list inside the type?
And maybe moving the animate function inside it as well.

Type AniFig
	Global list:TList
	Field Frame:Int
	Field X:Float
	Field Y:Float
	Field Speed:Int
	Field GFX:TImage
	Field Timer1:Int
	Field Name:String
	Field RandomCase:Int
	Field Direction
	Field Steps
	Field PathX1
	Field PathY1
	Field PathX2
	Field PathY2
	
	Function Create:AniFig(X:Float , Y:Float , Speed:Int , GFX:TImage , Name:String , PathX1:Float , PathY1:Float , PathX2:Float , PathY2:Float)
		If Not list Then list:TList = New TList
		Local temp:AniFig = New AniFig
			temp.Frame = 0
			temp.X = X
			temp.Y = Y
			temp.Speed = Speed
			temp.GFX = GFX
			temp.Timer1 = MilliSecs()
			temp.Name = Name
			temp.RandomCase = Rand(0 , 10000)
			temp.Direction = 1
			temp.Steps = 0
			temp.PathX1=PathX1
			temp.PathY1=PathY1+temp.Y
			temp.PathX2=PathX2
			temp.PathY2=PathY2+temp.Y
		Return temp
	End Function
	

	Function Animate()
		For Fig:Anifig = EachIn list
			SetColor 0,0,0
			
			DrawText Fig.Name,Fig.X,Fig.Y - 33
			
			SetColor 255,0,0
			DrawLine Fig.PathX1,Fig.PathY1,Fig.PathX1,Fig.PathY2-30
			DrawLine Fig.PathX2,Fig.PathY1,Fig.PathX2,Fig.PathY2-30
			DrawLine Fig.PathX1,Fig.PathY1,Fig.PathX2,Fig.PathY2
			SetColor 255,255,255
			
			If fig.Direction = 1 Then SetScale(1,1)
			If fig.Direction = 0 Then SetScale(-1,1)
			
			'SetRotation(180)
			DrawImage(Fig.GFX,Fig.X,Fig.Y,Fig.Frame)
			SetRotation(0)
			SetScale(1,1)
			
			If Fig.Frame = 7 Then Fig.Frame = 0
			If MilliSecs() > Fig.Timer1 + Fig.Speed Then
			If Fig.X >= Fig.PathX2-12 Then
				Fig.Direction = 0
			End If
			If Fig.X <= Fig.PathX1+12 Then
				Fig.Direction = 1
			End If
			If Fig.Direction = 1 Then
				Fig.X = Fig.X + 5
			End If
			If Fig.Direction = 0 Then
				Fig.X = Fig.X - 5
			End If
			Fig.Steps = Fig.Steps +1
			Fig.Frame = Fig.Frame +1
			If Fig.Frame = 4 Then Fig.Frame = 5
				Fig.Timer1 = MilliSecs()
			End If
		Next
	End Function
End Type




You can then instantiate a AniFig type with
Global fig1:AnimFig = AniFig.Create(350, 290, 50, Anim1, "Heidi", 100, 32, 400 ,32) 

And it will have all the default fields set for it.

To animate:
Anifig.Animate()

And to loop through the type list (if you haven't spotted it in the animate function).

For Local fig:Anifig = Eachin AniFig.list


Note that the above code is untested, but the principle is there.