MineProjectile.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #endregion
  14. namespace VectorRumble
  15. {
  16. /// <summary>
  17. /// A mine projectile.
  18. /// </summary>
  19. class MineProjectile : Projectile
  20. {
  21. #region Constants
  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. #endregion
  32. #region Initialization
  33. /// <summary>
  34. /// Constructs a new mine projectile.
  35. /// </summary>
  36. /// <param name="world">The world that this projectile belongs to.</param>
  37. /// <param name="owner">The ship that fired this projectile, if any.</param>
  38. /// <param name="direction">The initial direction for this projectile.</param>
  39. public MineProjectile(World world, Ship owner, Vector2 direction)
  40. : base(world, owner, direction)
  41. {
  42. this.radius = 16f;
  43. this.life = 15f;
  44. this.speed = 64f;
  45. this.duration = 15f;
  46. this.mass = 5f;
  47. this.damageAmount = 200f;
  48. this.damageOwner = true;
  49. this.damageRadius = 80f;
  50. this.explodes = true;
  51. this.explosionColors = new Color[]
  52. { Color.Red, Color.Maroon, Color.White, Color.Silver };
  53. this.polygon = VectorPolygon.CreateMine();
  54. this.color = Color.Red;
  55. }
  56. #endregion
  57. #region Update
  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. #endregion
  69. #region Interaction
  70. /// <summary>
  71. /// Damages all actors in a radius around the mine.
  72. /// </summary>
  73. /// <param name="touchedActor">The actor that was originally hit.</param>
  74. public override void Explode(Actor touchedActor)
  75. {
  76. // play the explosion cue
  77. world.AudioManager.PlayCue("explosionLarge");
  78. // add a double-particle system effect
  79. world.ParticleSystems.Add(new ParticleSystem(this.position,
  80. Vector2.Zero, 64, 32f, 64f, 3f, 0.05f, explosionColors));
  81. world.ParticleSystems.Add(new ParticleSystem(this.position,
  82. Vector2.Zero, 16, 128f, 256f, 4f, 0.1f, explosionColors));
  83. base.Explode(touchedActor);
  84. }
  85. #endregion
  86. }
  87. }