Time for action – creating the PlayerManager class
Add a new class called PlayerManager to the Asteroid Belt Assault project.
Add the following
using
directives to the top of the class file:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Graphics;
Add declarations to the PlayerManager class:
public Sprite playerSprite; private float playerSpeed = 160.0f; private Rectangle playerAreaLimit; public long PlayerScore = 0; public int LivesRemaining = 3; public bool Destroyed = false; private Vector2 gunOffset = new Vector2(25, 10); private float shotTimer = 0.0f; private float minShotTimer = 0.2f; private int playerRadius = 15; public ShotManager PlayerShotManager;
Add a constructor to the PlayerManager class:
public PlayerManager( Texture2D texture, Rectangle initialFrame, int frameCount, Rectangle screenBounds) { playerSprite = new Sprite( new Vector2(500, 500), texture, initialFrame, Vector2.Zero...