Time for action – creating the StarField class
Add a new class file called
StarField.vb
to the Asteroid Belt Assault project.Add the following declarations to the
StarField
class:Private stars As List(Of Sprite) = new List(Of Sprite) Private screenWidth As Integer = 800 Private screenHeight As Integer = 600 Private rand As Random = new Random() Private colors As Color() = { Color.White, Color.Yellow, Color.Wheat, Color.WhiteSmoke, Color.SlateGray}
Add a constructor to the
StarField
class:Public Sub New( screenWidth As Integer, screenHeight As Integer, starCount As Integer, starVelocity As Vector2, texture As Texture2D, frameRectangle As Rectangle) Me.screenWidth = screenWidth Me.screenHeight = screenHeight For x As Integer = 0 to starCount stars.Add(new Sprite( new Vector2(CSng(rand.Next(0,screenWidth)), CSng(rand.Next(0,screenHeight...