/// <summary> /// Creates the effect for when the player fires a bullet. /// </summary> /// <param name="position">Where on the screen to create the effect.</param> public void CreatePlayerFireSmoke(Player player) { for (int i = 0; i < 8; ++i) { Particle p = CreateParticle(); p.TextureName = "smoke"; p.Texture = textureDictionary[p.TextureName]; p.Color = Color.White; p.Position.X = player.Position.X + player.Width / 2; p.Position.Y = player.Position.Y; p.Alpha = 1.0f; p.AlphaRate = -1.0f; p.Life = 1.0f; p.Rotation = 0.0f; p.RotationRate = -2.0f + 4.0f * (float)random.NextDouble(); p.Scale = 0.25f; p.ScaleRate = 0.25f; p.Velocity.X = -4 + 8.0f * (float)random.NextDouble(); p.Velocity.Y = -16.0f + -32.0f * (float)random.NextDouble(); } }
/// <summary> /// Creates the mud/dust effect when the player moves. /// </summary> /// <param name="position">Where on the screen to create the effect.</param> public void CreatePlayerDust(Player player) { for (int i = 0; i < 2; ++i) { Particle p = CreateParticle(); p.TextureName = "smoke"; p.Texture = textureDictionary[p.TextureName]; p.Color = new Color(125, 108, 43); p.Position.X = player.Position.X + player.Width * (float)random.NextDouble(); p.Position.Y = player.Position.Y + player.Height - 3.0f * (float)random.NextDouble(); p.Alpha = 1.0f; p.AlphaRate = -2.0f; p.Life = 0.5f; p.Rotation = 0.0f; p.RotationRate = -2.0f + 4.0f * (float)random.NextDouble(); p.Scale = 0.25f; p.ScaleRate = 0.5f; p.Velocity.X = -4 + 8.0f * (float)random.NextDouble(); p.Velocity.Y = -8 + 4.0f * (float)random.NextDouble(); } }
/// <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(); }