O'Reilly logo

XNA 4.0 Game Development by Example Beginner's Guide by Kurt Jaegers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - creating the Player class

  1. Add a new class file called Player.cs to the Gemstone Hunter project.
  2. Add the following using directives to the Player class:
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.Input;
    using Tile_Engine;
    
  3. Modify the declaration of the Player class to make it public, and derive from the GameObject class:
    public class Player : GameObject
    
  4. Add declarations to the Player class:
    private Vector2 fallSpeed = new Vector2(0, 20);
    private float moveScale = 180.0f;
    private bool dead = false;
    
  5. Add the Dead property to the Player class:
    public bool Dead
    {
    get { return dead; }
    }
    
  6. Create a constructor for the Player class:
    #region Constructor ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required