Time for action – updating and drawing asteroids
Add the
Update()
andDraw()
methods to the AsteroidManager class:public void Update(GameTime gameTime) { foreach (Sprite asteroid in Asteroids) { asteroid.Update(gameTime); if (!isOnScreen(asteroid)) { asteroid.Location = randomLocation(); asteroid.Velocity = randomVelocity(); } } } public void Draw(SpriteBatch spriteBatch) { foreach (Sprite asteroid in Asteroids) { asteroid.Draw(spriteBatch); } }
Add a declaration for the AsteroidManager in the declarations section of the Game1 class:
AsteroidManager asteroidManager;
In the Game1 class'
LoadContent()
method, initializeasteroidManager
after the initialization of thestarField
object:asteroidManager = new AsteroidManager( 10, spriteSheet, new Rectangle(0, 0, 50, 50), 20, this.Window.ClientBounds.Width, this.Window.ClientBounds.Height);
Add the following line to Game1's
Update()
method...