LaserProjectile.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // LaserProjectile.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 laser bolt projectile.
  19. /// </summary>
  20. public class LaserProjectile : Projectile
  21. {
  22. #region Constants
  23. /// <summary>
  24. /// The length of the laser-bolt line, expressed as a percentage of velocity.
  25. /// </summary>
  26. const float initialSpeed = 640f;
  27. #endregion
  28. #region Static Graphics Data
  29. /// <summary>
  30. /// Texture for all laser projectiles.
  31. /// </summary>
  32. private static Texture2D texture;
  33. /// <summary>
  34. /// The particle-effect manager which receives the effects from lasers.
  35. /// </summary>
  36. public static ParticleEffectManager ParticleEffectManager;
  37. #endregion
  38. #region Initialization
  39. /// <summary>
  40. /// Constructs a new laser 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 LaserProjectile(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 = 4f;
  51. this.mass = 0.5f;
  52. // set the projectile data
  53. this.duration = 5f;
  54. this.damageAmount = 20f;
  55. this.damageRadius = 0f;
  56. this.damageOwner = false;
  57. }
  58. #endregion
  59. #region Drawing Methods
  60. /// <summary>
  61. /// Draw the laser projectile.
  62. /// </summary>
  63. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  64. /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
  65. public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
  66. {
  67. // ignore the parameter color if we have an owner
  68. base.Draw(elapsedTime, spriteBatch, texture, null,
  69. owner != null ? owner.Color : Color.White);
  70. }
  71. #endregion
  72. #region Interaction Methods
  73. /// <summary>
  74. /// Kills this object, in response to the given GameplayObject.
  75. /// </summary>
  76. /// <param name="source">The GameplayObject responsible for the kill.</param>
  77. /// <param name="cleanupOnly">
  78. /// If true, the object dies without any further effects.
  79. /// </param>
  80. public override void Die(GameplayObject source, bool cleanupOnly)
  81. {
  82. if (active)
  83. {
  84. // display the laser explosion
  85. if (!cleanupOnly && (ParticleEffectManager != null))
  86. {
  87. ParticleEffectManager.SpawnEffect(ParticleEffectType.LaserExplosion,
  88. Position);
  89. }
  90. }
  91. base.Die(source, cleanupOnly);
  92. }
  93. #endregion
  94. #region Static Graphics Methods
  95. /// <summary>
  96. /// Load all of the static graphics content for this class.
  97. /// </summary>
  98. /// <param name="contentManager">The content manager to load with.</param>
  99. public static void LoadContent(ContentManager contentManager)
  100. {
  101. // safety-check the parameters
  102. if (contentManager == null)
  103. {
  104. throw new ArgumentNullException("contentManager");
  105. }
  106. // load the texture
  107. texture = contentManager.Load<Texture2D>("Textures/laser");
  108. }
  109. /// <summary>
  110. /// Unload all of the static graphics content for this class.
  111. /// </summary>
  112. public static void UnloadContent()
  113. {
  114. texture = null;
  115. }
  116. #endregion
  117. }
  118. }