2
0

MineProjectile.cs 4.7 KB

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