Keeping Track of Instances

BlitzMax Forums/BlitzMax Beginners Area/Keeping Track of Instances

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Tlist are really the best method for keep track of bullets

Graphics 1024,768,32

Global Bullet_List:TList=CreateList()

Type Bullet
	Field XCoor#
	Field YCoor#
	Field Speed#
	
	Method Move_bullet()
		Xcoor#:+Speed#
	End Method
	
	Method Draw_Bullet()
		DrawOval(Xcoor#,Ycoor#,10,10)
	End Method
	
	Method Check_Dead()
		If xcoor#>1024+10 Then
		ListRemove Bullet_list,Self
		EndIf
	End Method
	
End Type

While Not KeyHit(Key_Escape)
Update_Bullets()
If KeyHit(KEY_SPACE) Then Create_Bullets


Flip
FlushMem
Cls
Wend

Function Create_Bullets()
Bull:Bullet=New Bullet
Bull.Xcoor#=Rnd(100)+100
Bull.Ycoor#=Rnd(700)+50
Bull.Speed#=(Rnd(20)+1)/10
ListAddLast Bullet_List,bull
End Function

Function Update_Bullets()
For Bull:Bullet=EachIn Bullet_List
Bull.Move_Bullet
Bull.Draw_bullet
Bull.Check_Dead
Total:+1
Next
DrawText ("Total Bullets="+Total,50,50)
End Function