Time for action – building the Enemy class

  1. Add a new class called Enemy to the Robot Rampage project.
  2. Add the following using directives to the top of the class file:
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
  3. Add declarations to the Enemy class:
    #region Declarations
    public Sprite EnemyBase;
    public Sprite EnemyClaws;
    public float EnemySpeed = 60f;
    public Vector2 currentTargetSquare;
    public bool Destroyed = false;
    private int collisionRadius = 14;
    #endregion
  4. Add a constructor to the Enemy class:
    #region Constructor public Enemy( Vector2 worldLocation, Texture2D texture, Rectangle initialFrame) { EnemyBase = new Sprite( worldLocation, texture, initialFrame, Vector2.Zero); EnemyBase.CollisionRadius = collisionRadius; Rectangle ...

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.