123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- #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
- {
- /// <summary>
- /// A rocket projectile.
- /// </summary>
- public class RocketProjectile : Projectile
- {
- #region Constants
- /// <summary>
- /// The initial speed of the rocket.
- /// </summary>
- const float initialSpeed = 650f;
- #endregion
- #region Static Graphics Data
- /// <summary>
- /// Texture for all rocket projectiles.
- /// </summary>
- private static Texture2D texture;
- /// <summary>
- /// The particle-effect manager which recieves the effects from rockets.
- /// </summary>
- public static ParticleEffectManager ParticleEffectManager;
- #endregion
- #region Graphics Data
- /// <summary>
- /// The trailing effect behind a rocket.
- /// </summary>
- protected ParticleEffect rocketTrailEffect = null;
- #endregion
- #region Audio Data
- /// <summary>
- /// The sound effect of the rocket as it flies.
- /// </summary>
- protected SoundEffectInstance rocketSound = null;
- #endregion
- #region Initialization
- /// <summary>
- /// Constructs a new rocket projectile.
- /// </summary>
- /// <param name="owner">The ship that fired this projectile, if any.</param>
- /// <param name="direction">The initial direction for this projectile.</param>
- 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;
- }
- /// <summary>
- /// Initialize the rocket projectile to it's default gameplay states.
- /// </summary>
- 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
- /// <summary>
- /// Draw the rocket.
- /// </summary>
- /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
- /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
- 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
- /// <summary>
- /// Kills this object, in response to the given GameplayObject.
- /// </summary>
- /// <param name="source">The GameplayObject responsible for the kill.</param>
- /// <param name="cleanupOnly">
- /// If true, the object dies without any further effects.
- /// </param>
- 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
- /// <summary>
- /// Load all of the static graphics content for this class.
- /// </summary>
- /// <param name="contentManager">The content manager to load with.</param>
- public static void LoadContent(ContentManager contentManager)
- {
- // safety-check the parameters
- if (contentManager == null)
- {
- throw new ArgumentNullException("contentManager");
- }
- // load the texture
- texture = contentManager.Load<Texture2D>("Textures/rocket");
- }
- /// <summary>
- /// Unload all of the static graphics content for this class.
- /// </summary>
- public static void UnloadContent()
- {
- texture = null;
- }
- #endregion
- }
- }
|