That's how I would do it ... maybe it helps.
-- Byteemoz
-- Byteemoz
SuperStrict SeedRnd MilliSecs() ' create enemies Global Enemies:TList = CreateList() For Local a:Int = 1 To 5 Enemies.AddLast TObject.Create(Rand(50, 750), Rand(50, 550)) Next ' create player Global Player:TObject = TObject.Create(0, 0) Graphics 800, 600 Repeat Cls ' draw enemies SetColor 255, 0, 0 For Local Enemy:TObject = EachIn Enemies DrawOval Enemy.PosX - 3, Enemy.PosY - 3, 7, 7 Next ' draw player SetColor 0, 255, 0 DrawOval Player.PosX - 3, Player.PosY - 3, 7, 7 ' draw shots SetColor 0, 0, 255 For Local Enemy:TObject = EachIn Enemies If Enemy.ShootAt Then DrawLine Enemy.PosX, Enemy.PosY, Enemy.ShootAt.PosX, Enemy.ShootAt.PosY EndIf Next Flip ' move player Player.PosX = MouseX() Player.PosY = MouseY() ' update enemies SetColor 0, 0, 255 For Local Enemy:TObject = EachIn Enemies If Enemy.DistToTarget(Player) < 100 Then Enemy.ShootAt = Player Else Enemy.ShootAt = Null EndIf Next Until KeyHit(KEY_ESCAPE) Or AppTerminate() ' generic player/enemy object Type TObject Field PosX:Int, PosY:Int Field ShootAt:TObject ' only for the enemy Method DistToTarget:Int(Target:TObject) Return Sqr( (PosX - Target.PosX) ^ 2 + (PosY - Target.PosY) ^ 2) EndMethod Function Create:TObject(X:Int, Y:Int) Local e:TObject = New TObject e.PosX = X ; e.PosY = Y Return e EndFunction EndType