Time for action – enemy update and draw
Add the
Update()
method to theEnemy
class:Public Sub Update(gameTime As GameTime) If IsActive() Then Dim heading As Vector2 = currentWaypoint - EnemySprite.Location If heading <> Vector2.Zero heading.Normalize() End If heading *= speed EnemySprite.Velocity = heading previousLocation = EnemySprite.Location EnemySprite.Update(gameTime) EnemySprite.Rotation = CSng(Math.Atan2( EnemySprite.Location.Y - previousLocation.Y, EnemySprite.Location.X - previousLocation.X)) If WaypointReached() Then If waypoints.Count > 0 Then currentWaypoint = waypoints.Dequeue() End If End If End If End Sub
Add the
Draw()
method to theEnemy
class:Public Sub Draw(spriteBatch As SpriteBatch) If IsActive() Then EnemySprite.Draw(spriteBatch) End If End Sub
What just happened?
Updating an Enemy
, begins by checking to see if the enemy is still active. If it is, a heading...