Time for action – waypoint management
Add the
AddWaypoint()
method to theEnemy
class:Public Sub AddWaypoint(waypoint As Vector2) waypoints.Enqueue(waypoint) End Sub
Add the
WaypointReached()
method to theEnemy
class:Public Function WaypointReached() as Boolean If Vector2.Distance(EnemySprite.Location, currentWaypoint) < CSng(EnemySprite.Source.Width)/2 Then Return True Else Return False End If End Function
Add the
IsActive()
method to theEnemy
class:Public Function IsActive() As Boolean If Destroyed Then Return False End If if waypoints.Count > 0 Then Return True End If If WaypointReached() Return False End If Return True End Function
What just happened?
When a new waypoint is added to the enemy's route, it is enqueued to the waypoints queue. When WaypointReached()
is called, the function checks to see if the distance between the sprite's current location and the current waypoint is less...