Types and OOP?

BlitzMax Forums/BlitzMax Programming/Types and OOP?

I have a TStar type. I create objects using s:star = new star.

When I check if a star is near the other I do this.
	Method CheckDistance:Double(from:star)
 		 Local XDistance:Double = from.XLoc-XLoc
		 Local YDistance:Double = from.YLoc-YLoc
		 Return Sqr(XDistance * XDistance + YDistance*YDistance)
	End Method
	
	Function UpdateCluster()
		For Local Body:Star = EachIn StarList
			Body.DrawCluster
			body.MoveStars
			For Local Body2:Star = EachIn StarList
				If (body = body2) Continue
				If (Body.CheckDistance(Body2)<1.0)
					DrawText "yay",0,0
			End If
			Next
			'Body.CheckDistance
		Next
	End Function


What i want to know is, why does it work? The full source code is below. Antony helped me with it but I'm at a loss as to why a partiicular bit works.


SuperStrict

Graphics 800,600,16,60

Global StarList:TList = CreateList()

Type Star
	
	Field XLoc:Double
	Field YLoc:Double
	Field Speed:Double
	Field Inertia:Double
	Field Gravity:Double
	Field CRed:Int
	Field CGreen:Int
	Field CBlue:Int
	Field Name:String
	Field Class:Int
	Field Angle:Int
	Field Direction:Int
	
	Global MaxStars:Int
	Global SType:Int
	
	Function CreateCluster:Int( MaxStars:Int , SType:Int )
		For Local xiter:Int = 0 To MaxStars - 1
			Local Body:Star = New Star
			Body.Class = Rand( 0 , SType)
			If body.Class = 0
				Body.Name = "Small Planet"
				Body.Gravity = 0.01
				Body.Inertia = 0.05
				Body.Speed = Rnd( 0.05 , 0.1 )
				Body.XLoc = Rand( 0 , 800 )
				Body.YLoc = Rand( 0 , 600 )
				Body.CRed = 10
				Body.CGreen = 210
				Body.CBlue = 25
				Body.Angle = 0
				Body.Direction = Rand( -180 , 179 )
			End If
			ListAddFirst StarList , (Body)
		Next
		Return MaxStars
	End Function
	
	Method DrawCluster()
		SetColor( CRed , CGreen , CBlue )
		Plot XLoc,YLoc
	End Method
	
	Method MoveStars()
		Xloc = Xloc + Cos(Angle) * Speed
		YLoc = Yloc + Sin(Angle) * Speed
		angle = Direction
	End Method
	
	Method DoPhysics()
		
	End Method
	
	Method CheckDistance:Double(from:star)
 		 Local XDistance:Double = from.XLoc-XLoc
		 Local YDistance:Double = from.YLoc-YLoc
		 Return Sqr(XDistance * XDistance + YDistance*YDistance)
	End Method
	
	Function UpdateCluster()
		For Local Body:Star = EachIn StarList
			Body.DrawCluster
			body.MoveStars
			For Local Body2:Star = EachIn StarList
				If (body = body2) Continue
				If (Body.CheckDistance(Body2)<1.0)
					DrawText "yay",0,0
			End If
			Next
			'Body.CheckDistance
		Next
	End Function
		
End Type


Star.CreateCluster(5,0)

While Not KeyHit(KEY_ESCAPE)
	Cls
		Star.UpdateCluster
		'Star.CheckDistance		

		
	Flip
WEnd



If you notice, this bit below..

	Function UpdateCluster()
		For Local Body:Star = EachIn StarList
			Body.DrawCluster
			body.MoveStars
			For Local Body2:Star = EachIn StarList
				If (body = body2) Continue
				If (Body.CheckDistance(Body2)<1.0)
					DrawText "yay",0,0
			End If
			Next
			'Body.CheckDistance
		Next
	End Function


... has a Body and Body2. What i am not grasping is why Body2 exists if it hasn't been created using "new". eg. Body2:Star = new star.

I don't understand how it came to exist and it uses the same list. :/

Also, if you notice Antony's coding, he uses the word "From" as a parameter and the word "continue".

I dunno, I'm lost. Any help would be appreciated.

Also, please be gentle when explaining it to me. :)