O'Reilly logo

Learning XNA 4.0 by Aaron Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a ModelManager

I hate to break it to you, but the hard part is over already for this chapter. Coding for Windows Phone 7 is so similar to coding for Windows and Xbox 360 that there really aren’t that many key differences. That’s awesome for developers wishing to build games across multiple platforms, but not too great for authors trying to explain the differences between those development platforms. That said, you still need to flesh out the rest of your game. To do that, add a class to your project called ModelManager.cs, and replace the default code with the following:

using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace PhoneAsteroids { /// <summary> /// This is a game component that implements IUpdateable. /// </summary> public class ModelManager : DrawableGameComponent { // List of models List<AsteroidModel> asteroidList = new List<AsteroidModel>(); List<ShotModel> shotList = new List<ShotModel>(); PlayerModel player; // Spawning Asteroid stuff int timeSinceLastSpawn = 0; int nextSpawnTime = 0; int maxSpawnTime = 4000; int minSpawnTime = 2000; // Sounds SoundEffect trackSound; SoundEffect collisionSound; SoundEffectInstance trackSoundInstance; public ModelManager(Game game) : base(game) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required