Time for action – enemy update and draw
Add the
Update()
method to the Enemy class:public void Update(GameTime gameTime) { if (IsActive()) { Vector2 heading = currentWaypoint - EnemySprite.Location; if (heading != Vector2.Zero) { heading.Normalize(); } heading *= speed; EnemySprite.Velocity = heading; previousLocation = EnemySprite.Location; EnemySprite.Update(gameTime); EnemySprite.Rotation = (float)Math.Atan2( EnemySprite.Location.Y - previousLocation.Y, EnemySprite.Location.X - previousLocation.X); if (WaypointReached()) { if (waypoints.Count > 0) { currentWaypoint = waypoints.Dequeue(); } } } }
Add the
Draw()
method to the Enemy class:public void Draw(SpriteBatch spriteBatch) { if (IsActive()) { EnemySprite.Draw(spriteBatch); } }
What just happened?
Updating...