Time for action – waypoint management
Add the
AddWaypoint()
method to the Enemy class:public void AddWaypoint(Vector2 waypoint) { waypoints.Enqueue(waypoint); }
Add the
WaypointReached()
method to the Enemy class:public bool WaypointReached() { if (Vector2.Distance(EnemySprite.Location, currentWaypoint) < (float)EnemySprite.Source.Width/2) { return true; } else { return false; } }
Add the
IsActive()
method to the Enemy class:public bool IsActive() { if (Destroyed) { return false; } if (waypoints.Count > 0) { return true; } if (WaypointReached()) { return false; } return true; }
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 than half of the sprite width. If...