Issue with lists

BlitzMax Forums/BlitzMax Beginners Area/Issue with lists

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.

Strict 

Global EntityList:TList = CreateList()

Type tEntity
	Field X:Float, Y:Float
	Field VX:Float, VY:Float
	Field Width:Int
	Field Height:Int
	Field Pushable:Int
	Field Name:String

	Method New()
		EntityList.AddLast(Self)
		X = Rnd(0,640)
		Y = Rnd(0,480)
		Width = 32
		Height = 16
		Pushable = True
	End Method

	Method Compare(_O:Object)
		Return Y - tEntity(_O).Y
	End Method
	
	Method Delete ()
		EntityList.Remove(Self)
	End Method
	
	Method Render ()
		SetColor 0,0,0
		DrawRect X-1, Y-Height-1, Width+2, Height+Height+2
		SetColor 200,200,200
		DrawRect X, Y, Width, Height
		SetColor 125,125,125
		DrawRect X, Y-Height, Width, Height
		SetColor 0, 0, 0
		DrawText(self.name, X, Y)
		SetColor 255, 255, 255
		DrawText(self.name, X+1, Y+1)
	End Method
	
	Method Update ()
		MoveIfNotCollided(VX, VY)
	End Method
	
	Method MoveIfNotCollided(_VX:Float, _VY:Float)
		Local e:tEntity
		
		X :+ _VX	
		Y :+ _VY	
		e = CollideWithEntity()

		If (e <> Null)
			If e.Pushable
				X :- (_VX * .5)
				Y :- (_VY * .5)
				e.X :+ (_VX * .5)
				e.Y :+ (_VY * .5)	
			Else
				X :- _VX
				Y :- _VY	
			End If
		End If

	End Method
	

	Method CollideWithEntity:tEntity ()
		Local e:tEntity
		For e = EachIn EntityList
			If e <> Self
				If e.X > X + Width Continue 
				If e.X + e.Width < X Continue
				If e.Y > Y + (Height*2) Continue
				If e.Y + (e.Height*2) < Y Continue
				Return e
			End If
		Next
	End Method

End Type


Graphics 640,480,0,0
SetClsColor 0,150,0

Local p1:tEntity = New tEntity
p1.name = "player1"
p1.pushable = False
Local p2:tEntity = New tEntity
p2.name="player2"
Local p3:tEntity = New tEntity
p3.name="player3"

Local Controls:Int [] = [KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT]

While Not KeyHit(KEY_ESCAPE)
	Cls
	
	p1.VX = 0; p1.VY = 0
	If (KeyDown(Controls[0])) p1.VY :+ -2 'UP
	If (KeyDown(Controls[1])) p1.VY :+ 2 'DOWN
	If (KeyDown(Controls[2])) p1.VX :+ -2 'LEFT
	If (KeyDown(Controls[3])) p1.VX :+ 2 'RIGHT
	
	For Local e:tEntity = EachIn EntityList
		e.Update()
		e.Render()
	Next

	Flip
	FlushMem
Wend


*EDIT*
I really should refresh before posting if I've spent a while on these things :)