Time for action – building the AsteroidManager class
Add a new class called "AsteroidManager" to the Asteroid Belt Assault project.
Add the following
using
directives to the top of the AsteroidManager class:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
Add the following declarations to the AsteroidManager class:
private int screenWidth = 800; private int screenHeight = 600; private int screenPadding = 10; private Rectangle initialFrame; private int asteroidFrames; private Texture2D texture; public List<Sprite> Asteroids = new List<Sprite>(); private int minSpeed = 60; private int maxSpeed = 120; private Random rand = new Random();
Add a helper method that will be used in the AsteroidManager constructor:
public void AddAsteroid() { Sprite newAsteroid = new Sprite( new Vector2(-500, -500), texture, initialFrame, Vector2.Zero); for (int x = 1; x < asteroidFrames; x++) { newAsteroid.AddFrame(new Rectangle...