DoubleLaserPowerUp.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // DoubleLaserPowerUp.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 power-up that gives a player a double-laser-shooting weapon.
  19. /// </summary>
  20. public class DoubleLaserPowerUp : PowerUp
  21. {
  22. #region Static Graphics Data
  23. /// <summary>
  24. /// Texture for the double-laser power-up.
  25. /// </summary>
  26. private static Texture2D texture;
  27. #endregion
  28. #region Initialization Methods
  29. /// <summary>
  30. /// Constructs a new DoubleLaserPowerUp.
  31. /// </summary>
  32. public DoubleLaserPowerUp()
  33. : base() { }
  34. #endregion
  35. #region Drawing Methods
  36. /// <summary>
  37. /// Draw the double-laser power-up.
  38. /// </summary>
  39. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  40. /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
  41. public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
  42. {
  43. // ignore the parameter color if we have an owner
  44. base.Draw(elapsedTime, spriteBatch, texture, null, Color.White);
  45. }
  46. #endregion
  47. #region Interaction Methods
  48. /// <summary>
  49. /// Defines the interaction between this power-up and a target GameplayObject
  50. /// when they touch.
  51. /// </summary>
  52. /// <param name="target">The GameplayObject that is touching this one.</param>
  53. /// <returns>True if the objects meaningfully interacted.</returns>
  54. public override bool Touch(GameplayObject target)
  55. {
  56. // if we hit a ship, give it the weapon
  57. Ship ship = target as Ship;
  58. if (ship != null)
  59. {
  60. ship.Weapon = new DoubleLaserWeapon(ship);
  61. }
  62. return base.Touch(target);
  63. }
  64. #endregion
  65. #region Static Graphics Methods
  66. /// <summary>
  67. /// Load all of the static graphics content for this class.
  68. /// </summary>
  69. /// <param name="contentManager">The content manager to load with.</param>
  70. public static void LoadContent(ContentManager contentManager)
  71. {
  72. // safety-check the parameters
  73. if (contentManager == null)
  74. {
  75. throw new ArgumentNullException("contentManager");
  76. }
  77. // load the texture
  78. texture = contentManager.Load<Texture2D>("Textures/powerupDoubleLaser");
  79. }
  80. /// <summary>
  81. /// Unload all of the static graphics content for this class.
  82. /// </summary>
  83. public static void UnloadContent()
  84. {
  85. texture = null;
  86. }
  87. #endregion
  88. }
  89. }