TripleLaserWeapon.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // TripleLaserWeapon.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. #endregion
  13. namespace NetRumble
  14. {
  15. /// <summary>
  16. /// A weapon that shoots a triple stream of laser projectiles.
  17. /// </summary>
  18. public class TripleLaserWeapon : LaserWeapon
  19. {
  20. #region Constants
  21. /// <summary>
  22. /// The spread of the second and third laser projectiles' directions, in radians
  23. /// </summary>
  24. static readonly float laserSpreadRadians = MathHelper.ToRadians(2.5f);
  25. #endregion
  26. #region Initialization Methods
  27. /// <summary>
  28. /// Constructs a new triple-laser weapon.
  29. /// </summary>
  30. /// <param name="owner">The ship that owns this weapon.</param>
  31. public TripleLaserWeapon(Ship owner)
  32. : base(owner)
  33. {
  34. fireDelay = 0.3f;
  35. }
  36. #endregion
  37. #region Interaction Methods
  38. /// <summary>
  39. /// Create and spawn the projectile(s) from a firing from this weapon.
  40. /// </summary>
  41. /// <param name="direction">The direction that the projectile will move.</param>
  42. protected override void CreateProjectiles(Vector2 direction)
  43. {
  44. // calculate the direction vectors for the second and third projectiles
  45. float rotation = (float)Math.Acos(Vector2.Dot(new Vector2(0f, -1f),
  46. direction));
  47. rotation *= (Vector2.Dot(new Vector2(0f, -1f),
  48. new Vector2(direction.Y, -direction.X)) > 0f) ? 1f : -1f;
  49. Vector2 direction2 = new Vector2(
  50. (float)Math.Sin(rotation - laserSpreadRadians),
  51. -(float)Math.Cos(rotation - laserSpreadRadians));
  52. Vector2 direction3 = new Vector2(
  53. (float)Math.Sin(rotation + laserSpreadRadians),
  54. -(float)Math.Cos(rotation + laserSpreadRadians));
  55. // create the first projectile
  56. LaserProjectile projectile = new LaserProjectile(owner,
  57. direction);
  58. projectile.Initialize();
  59. owner.Projectiles.Add(projectile);
  60. // create the second projectile
  61. projectile = new LaserProjectile(owner, direction2);
  62. projectile.Initialize();
  63. owner.Projectiles.Add(projectile);
  64. // create the third projectile
  65. projectile = new LaserProjectile(owner, direction3);
  66. projectile.Initialize();
  67. owner.Projectiles.Add(projectile);
  68. }
  69. #endregion
  70. }
  71. }