Time for action – creating the Enemy class

  1. Add a new class called Enemy to the Asteroid Belt Assault project.
  2. Add the standard using directives to the class:
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
  3. 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; 
  4. Add a constructor to the Enemy class:
    public Enemy( Texture2D texture, Vector2 location, Rectangle initialFrame, int frameCount) { EnemySprite = new Sprite( location, texture, ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.