Time for action – building the AsteroidManager class
Add a new class called
AsteroidManager
to the Asteroid Belt Assault project.Add the following declarations to the
AsteroidManager
class:Private screenWidth As Integer = 800 Private screenHeight As Integer = 600 Private screenPadding As Integer = 10 Private initialFrame As Rectangle Private asteroidFrames As Integer Private texture As Texture2D Public Asteroids As List(Of Sprite) = new List(Of Sprite)() Private minSpeed As Integer = 60 Private maxSpeed As Integer = 120 Private rand As Random = new Random()
Add a
helper
method that will be used in theAsteroidManager
constructor:Public Sub AddAsteroid() Dim newAsteroid As Sprite = new Sprite( new Vector2(-500, -500), texture, initialFrame, Vector2.Zero) for X as Integer = 1 to asteroidFrames - 1 newAsteroid.AddFrame(new Rectangle( CInt(initialFrame.X) + (initialFrame.Width * x), CInt(initialFrame.Y), ...