/// <summary> /// Unloads the game's particle system and saves the high-score. /// </summary> public void UnloadContent() { SaveHighscore(); particles = null; }
/// <summary> /// Creates a new instance of the game helper. /// </summary> /// <param name="contentManager">The content manager to use for loading the games content.</param> /// <param name="spriteBatch">The sprite batch to use for drawing the game's gameplay screen.</param> /// <param name="graphicsDevice">The graphics device on which the game is rendered.</param> public GameplayHelper(ContentManager contentManager, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice) { random = new Random(); worldBounds = new Rectangle(0, 0, (int)screenWidth, (int)screenHeight); gameOver = true; player = new Player(); playerBullets = new List<Bullet>(); aliens = new List<Alien>(); alienBullets = new List<Bullet>(); particles = new ParticleSystem(contentManager, spriteBatch); InitializeAssets(contentManager, spriteBatch, graphicsDevice); }
/// <summary> /// Deserializes the game's state from a supplied XML reader. /// </summary> /// <param name="reader">The reader from which to deserialize game state data.</param> public void ReadXml(XmlReader reader) { // Read the wrapper element reader.Read(); // deserialize basic gameplay elements DeserializeGameplayMembers(reader); // Deserialize the particle system XmlSerializer particleSystemSerializer = new XmlSerializer(typeof(ParticleSystem)); particles = particleSystemSerializer.Deserialize(reader) as ParticleSystem; // Deserialize the player XmlSerializer playerSerializer = new XmlSerializer(typeof(Player)); player = playerSerializer.Deserialize(reader) as Player; // Deserialize the various bullets XmlSerializer bulletSerializer = new XmlSerializer(typeof(Bullet)); int playerBulletCount = int.Parse(reader.GetAttribute("Count")); // Read past the opening element for the player bullet list reader.Read(); for (int i = 0; i < playerBulletCount; i++) { playerBullets.Add(bulletSerializer.Deserialize(reader) as Bullet); } // Advance past the closing element if it exists if (playerBulletCount > 0) { reader.Read(); } int alienBulletCount = int.Parse(reader.GetAttribute("Count")); // Read past the opening element for the alien bullet list reader.Read(); for (int i = 0; i < alienBulletCount; i++) { alienBullets.Add(bulletSerializer.Deserialize(reader) as Bullet); } // Advance past the closing element if it exists if (alienBulletCount > 0) { reader.Read(); } // Deserialize the aliens XmlSerializer alienSerializer = new XmlSerializer(typeof(Alien)); int alienCount = int.Parse(reader.GetAttribute("Count")); // Read past the opening element for the alien list reader.Read(); for (int i = 0; i < alienCount; i++) { aliens.Add(alienSerializer.Deserialize(reader) as Alien); } // Advance past the closing element if it exists if (alienCount > 0) { reader.Read(); } reader.Read(); }
/// <summary> /// This constructor should only be used by the XML serializer. /// </summary> public GameplayHelper() { random = new Random(); worldBounds = new Rectangle(0, 0, (int)screenWidth, (int)screenHeight); gameOver = true; player = new Player(); playerBullets = new List<Bullet>(); aliens = new List<Alien>(); alienBullets = new List<Bullet>(); particles = new ParticleSystem(); }