Time for action – updating and drawing asteroids

  1. Add the Update() and Draw() 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);
        }
    }
  2. Add a declaration for the AsteroidManager in the declarations section of the Game1 class:
    AsteroidManager asteroidManager;
  3. In the Game1 class' LoadContent() method, initialize asteroidManager after the initialization of the starField object:
    asteroidManager = new AsteroidManager( 10, spriteSheet, new Rectangle(0, ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.