LaserProjectile.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //-----------------------------------------------------------------------------
  2. // LaserProjectile.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 laser bolt projectile.
  15. /// </summary>
  16. public class LaserProjectile : Projectile
  17. {
  18. /// <summary>
  19. /// The length of the laser-bolt line, expressed as a percentage of velocity.
  20. /// </summary>
  21. const float initialSpeed = 640f;
  22. /// <summary>
  23. /// Texture for all laser projectiles.
  24. /// </summary>
  25. private static Texture2D texture;
  26. /// <summary>
  27. /// The particle-effect manager which receives the effects from lasers.
  28. /// </summary>
  29. public static ParticleEffectManager ParticleEffectManager;
  30. /// <summary>
  31. /// Constructs a new laser projectile.
  32. /// </summary>
  33. /// <param name="owner">The ship that fired this projectile, if any.</param>
  34. /// <param name="direction">The initial direction for this projectile.</param>
  35. public LaserProjectile(Ship owner, Vector2 direction)
  36. : base(owner, direction)
  37. {
  38. // set the gameplay data
  39. this.velocity = initialSpeed * direction;
  40. // set the collision data
  41. this.radius = 4f;
  42. this.mass = 0.5f;
  43. // set the projectile data
  44. this.duration = 5f;
  45. this.damageAmount = 20f;
  46. this.damageRadius = 0f;
  47. this.damageOwner = false;
  48. }
  49. /// <summary>
  50. /// Draw the laser projectile.
  51. /// </summary>
  52. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  53. /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
  54. public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
  55. {
  56. // ignore the parameter color if we have an owner
  57. base.Draw(elapsedTime, spriteBatch, texture, null,
  58. owner != null ? owner.Color : Color.White);
  59. }
  60. /// <summary>
  61. /// Kills this object, in response to the given GameplayObject.
  62. /// </summary>
  63. /// <param name="source">The GameplayObject responsible for the kill.</param>
  64. /// <param name="cleanupOnly">
  65. /// If true, the object dies without any further effects.
  66. /// </param>
  67. public override void Die(GameplayObject source, bool cleanupOnly)
  68. {
  69. if (active)
  70. {
  71. // display the laser explosion
  72. if (!cleanupOnly && (ParticleEffectManager != null))
  73. {
  74. ParticleEffectManager.SpawnEffect(ParticleEffectType.LaserExplosion,
  75. Position);
  76. }
  77. }
  78. base.Die(source, cleanupOnly);
  79. }
  80. /// <summary>
  81. /// Load all of the static graphics content for this class.
  82. /// </summary>
  83. /// <param name="contentManager">The content manager to load with.</param>
  84. public static void LoadContent(ContentManager contentManager)
  85. {
  86. // safety-check the parameters
  87. if (contentManager == null)
  88. {
  89. throw new ArgumentNullException("contentManager");
  90. }
  91. // load the texture
  92. texture = contentManager.Load<Texture2D>("Textures/laser");
  93. }
  94. /// <summary>
  95. /// Unload all of the static graphics content for this class.
  96. /// </summary>
  97. public static void UnloadContent()
  98. {
  99. texture = null;
  100. }
  101. }
  102. }