Time for action – creating the StarField class
Add a new class called StarField 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.Graphics;
Add the following declarations to the StarField class:
private List<Sprite> stars = new List<Sprite>(); private int screenWidth = 800; private int screenHeight = 600; private Random rand = new Random(); private Color[] colors = { Color.White, Color.Yellow, Color.Wheat, Color.WhiteSmoke, Color.SlateGray };
Add a constructor to the StarField class:
public StarField( int screenWidth, int screenHeight, int starCount, Vector2 starVelocity, Texture2D texture, Rectangle frameRectangle) { this.screenWidth = screenWidth; this.screenHeight = screenHeight; for (int x = 0; x < starCount; x++) { stars.Add(new Sprite( new Vector2...