Time for action – creating the Enemy class
Add a new class called Enemy to the Asteroid Belt Assault project.
Add the standard
using
directives to the class:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
Add declarations to the Enemy class:
public Sprite EnemySprite; public Vector2 gunOffset = new Vector2(25, 25); private Queue<Vector2> waypoints = new Queue<Vector2>(); private Vector2 currentWaypoint = Vector2.Zero; private float speed = 120f; public bool Destroyed = false; private int enemyRadius = 15; private Vector2 previousLocation = Vector2.Zero;
Add a constructor to the Enemy class:
public Enemy( Texture2D texture, Vector2 location, Rectangle initialFrame, int frameCount) { EnemySprite = new Sprite( location, texture, initialFrame, Vector2.Zero); for (int x = 1; x < frameCount; x++) { EnemySprite.AddFrame( new Rectangle( initialFrame.X = (initialFrame...