#region File Description //----------------------------------------------------------------------------- // RocketProjectile.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- #endregion #region Using Statements using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; #endregion namespace NetRumble { /// /// A rocket projectile. /// public class RocketProjectile : Projectile { #region Constants /// /// The initial speed of the rocket. /// const float initialSpeed = 650f; #endregion #region Static Graphics Data /// /// Texture for all rocket projectiles. /// private static Texture2D texture; /// /// The particle-effect manager which recieves the effects from rockets. /// public static ParticleEffectManager ParticleEffectManager; #endregion #region Graphics Data /// /// The trailing effect behind a rocket. /// protected ParticleEffect rocketTrailEffect = null; #endregion #region Audio Data /// /// The sound effect of the rocket as it flies. /// protected SoundEffectInstance rocketSound = null; #endregion #region Initialization /// /// Constructs a new rocket projectile. /// /// The ship that fired this projectile, if any. /// The initial direction for this projectile. public RocketProjectile(Ship owner, Vector2 direction) : base(owner, direction) { // set the gameplay data this.velocity = initialSpeed * direction; // set the collision data this.radius = 14f; this.mass = 10f; // set the projectile data this.duration = 4f; this.damageAmount = 150f; this.damageOwner = false; this.damageRadius = 128f; this.rotation += MathHelper.Pi; } /// /// Initialize the rocket projectile to it's default gameplay states. /// public override void Initialize() { if (!active) { // get and play the rocket-flying sound effect AudioManager.PlaySoundEffect("rocket", true, out rocketSound); // start the rocket-trail effect if (ParticleEffectManager != null) { rocketTrailEffect = ParticleEffectManager.SpawnEffect( ParticleEffectType.RocketTrail, this); } } base.Initialize(); } #endregion #region Drawing Methods /// /// Draw the rocket. /// /// The amount of elapsed time, in seconds. /// The SpriteBatch object used to draw. public override void Draw(float elapsedTime, SpriteBatch spriteBatch) { // ignore the parameter color if we have an owner base.Draw(elapsedTime, spriteBatch, texture, null, Color.White); } #endregion #region Interaction Methods /// /// Kills this object, in response to the given GameplayObject. /// /// The GameplayObject responsible for the kill. /// /// If true, the object dies without any further effects. /// public override void Die(GameplayObject source, bool cleanupOnly) { if (active) { if (!cleanupOnly) { // play the explosion sound AudioManager.PlaySoundEffect("explosion_medium"); // display the rocket explosion if (ParticleEffectManager != null) { ParticleEffectManager.SpawnEffect( ParticleEffectType.RocketExplosion, Position); } } // stop the rocket-flying sound effect if (rocketSound != null) { rocketSound.Stop(true); rocketSound.Dispose(); rocketSound = null; } // stop the rocket-trail effect if (rocketTrailEffect != null) { rocketTrailEffect.Stop(false); } } base.Die(source, cleanupOnly); } #endregion #region Static Graphics Methods /// /// Load all of the static graphics content for this class. /// /// The content manager to load with. public static void LoadContent(ContentManager contentManager) { // safety-check the parameters if (contentManager == null) { throw new ArgumentNullException("contentManager"); } // load the texture texture = contentManager.Load("Textures/rocket"); } /// /// Unload all of the static graphics content for this class. /// public static void UnloadContent() { texture = null; } #endregion } }