MineProjectile.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // MineProjectile.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Graphics;
  13. using Microsoft.Xna.Framework.Content;
  14. #endregion
  15. namespace NetRumble
  16. {
  17. /// <summary>
  18. /// A mine projectile.
  19. /// </summary>
  20. public class MineProjectile : Projectile
  21. {
  22. #region Constants
  23. /// <summary>
  24. /// The initial speed of this projectile.
  25. /// </summary>
  26. const float initialSpeed = 64f;
  27. /// <summary>
  28. /// The amount of drag applied to velocity per second,
  29. /// as a percentage of velocity.
  30. /// </summary>
  31. const float dragPerSecond = 0.9f;
  32. /// <summary>
  33. /// The radians-per-second that this object rotates at.
  34. /// </summary>
  35. const float rotationRadiansPerSecond = 1f;
  36. #endregion
  37. #region Static Graphics Data
  38. /// <summary>
  39. /// Texture for all mine projectiles.
  40. /// </summary>
  41. private static Texture2D texture;
  42. /// <summary>
  43. /// The particle-effect manager which recieves the effects from mines.
  44. /// </summary>
  45. public static ParticleEffectManager ParticleEffectManager;
  46. #endregion
  47. #region Initialization
  48. /// <summary>
  49. /// Constructs a new mine projectile.
  50. /// </summary>
  51. /// <param name="owner">The ship that fired this projectile, if any.</param>
  52. /// <param name="direction">The initial direction for this projectile.</param>
  53. public MineProjectile(Ship owner, Vector2 direction)
  54. : base(owner, direction)
  55. {
  56. // set the gameplay data
  57. this.velocity = initialSpeed * direction;
  58. // set the collision data
  59. this.radius = 10f;
  60. this.mass = 5f;
  61. // set projectile data
  62. this.duration = 15f;
  63. this.damageAmount = 200f;
  64. this.damageOwner = false;
  65. this.damageRadius = 80f;
  66. }
  67. #endregion
  68. #region Updating Methods
  69. /// <summary>
  70. /// Update the mine.
  71. /// </summary>
  72. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  73. public override void Update(float elapsedTime)
  74. {
  75. base.Update(elapsedTime);
  76. this.velocity -= velocity * (elapsedTime * dragPerSecond);
  77. this.rotation += elapsedTime * rotationRadiansPerSecond;
  78. }
  79. #endregion
  80. #region Drawing Methods
  81. /// <summary>
  82. /// Draw the mine.
  83. /// </summary>
  84. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  85. /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
  86. public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
  87. {
  88. // ignore the parameter color if we have an owner
  89. base.Draw(elapsedTime, spriteBatch, texture, null, Color.White);
  90. }
  91. #endregion
  92. #region Interaction Methods
  93. /// <summary>
  94. /// Kills this object, in response to the given GameplayObject.
  95. /// </summary>
  96. /// <param name="source">The GameplayObject responsible for the kill.</param>
  97. /// <param name="cleanupOnly">
  98. /// If true, the object dies without any further effects.
  99. /// </param>
  100. public override void Die(GameplayObject source, bool cleanupOnly)
  101. {
  102. if (active)
  103. {
  104. if (!cleanupOnly)
  105. {
  106. // play the explosion sound effect
  107. AudioManager.PlaySoundEffect("explosion_large");
  108. // play the mine particle-effect
  109. if (ParticleEffectManager != null)
  110. {
  111. ParticleEffectManager.SpawnEffect(
  112. ParticleEffectType.MineExplosion, Position);
  113. }
  114. }
  115. }
  116. base.Die(source, cleanupOnly);
  117. }
  118. #endregion
  119. #region Static Graphics Methods
  120. /// <summary>
  121. /// Load all of the static graphics content for this class.
  122. /// </summary>
  123. /// <param name="contentManager">The content manager to load with.</param>
  124. public static void LoadContent(ContentManager contentManager)
  125. {
  126. // safety-check the parameters
  127. if (contentManager == null)
  128. {
  129. throw new ArgumentNullException("contentManager");
  130. }
  131. // load the texture
  132. texture = contentManager.Load<Texture2D>("Textures/mine");
  133. }
  134. /// <summary>
  135. /// Unload all of the static graphics content for this class.
  136. /// </summary>
  137. public static void UnloadContent()
  138. {
  139. texture = null;
  140. }
  141. #endregion
  142. }
  143. }