RocketPowerUp.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //-----------------------------------------------------------------------------
  2. // RocketPowerUp.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 power-up that gives a player a rocket-launching weapon.
  15. /// </summary>
  16. public class RocketPowerUp : PowerUp
  17. {
  18. /// <summary>
  19. /// Texture for the rocket power-up.
  20. /// </summary>
  21. private static Texture2D texture;
  22. /// <summary>
  23. /// Constructs a new rocket-launcher power-up.
  24. /// </summary>
  25. public RocketPowerUp()
  26. : base() { }
  27. /// <summary>
  28. /// Draw the rocket power-up.
  29. /// </summary>
  30. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  31. /// <param name="spriteBatch">The SpriteBatch object used to draw.</param>
  32. public override void Draw(float elapsedTime, SpriteBatch spriteBatch)
  33. {
  34. // ignore the parameter color if we have an owner
  35. base.Draw(elapsedTime, spriteBatch, texture, null, Color.White);
  36. }
  37. /// <summary>
  38. /// Defines the interaction between this power-up and a target GameplayObject
  39. /// when they touch.
  40. /// </summary>
  41. /// <param name="target">The GameplayObject that is touching this one.</param>
  42. /// <returns>True if the objects meaningfully interacted.</returns>
  43. public override bool Touch(GameplayObject target)
  44. {
  45. // if we hit a ship, give it the weapon
  46. Ship ship = target as Ship;
  47. if (ship != null)
  48. {
  49. ship.Weapon = new RocketWeapon(ship);
  50. }
  51. return base.Touch(target);
  52. }
  53. /// <summary>
  54. /// Load all of the static graphics content for this class.
  55. /// </summary>
  56. /// <param name="contentManager">The content manager to load with.</param>
  57. public static void LoadContent(ContentManager contentManager)
  58. {
  59. // safety-check the parameters
  60. if (contentManager == null)
  61. {
  62. throw new ArgumentNullException("contentManager");
  63. }
  64. // load the texture
  65. texture = contentManager.Load<Texture2D>("Textures/powerupRocket");
  66. }
  67. /// <summary>
  68. /// Unload all of the static graphics content for this class.
  69. /// </summary>
  70. public static void UnloadContent()
  71. {
  72. texture = null;
  73. }
  74. }
  75. }