ExtensionMethods.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // ExtensionMethods.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 Microsoft.Xna.Framework;
  11. #endregion
  12. namespace HoneycombRush
  13. {
  14. /// <summary>
  15. /// A class containing extension methods.
  16. /// </summary>
  17. public static class ExtensionMethods
  18. {
  19. /// <summary>
  20. /// Returns a vector pointing to the rectangle's top left corner.
  21. /// </summary>
  22. /// <param name="rect">The rectangle for which to produce the vector.</param>
  23. /// <returns>A vector pointing to the rectangle's top left corner.</returns>
  24. public static Vector2 GetVector(this Rectangle rect)
  25. {
  26. return new Vector2(rect.X, rect.Y);
  27. }
  28. /// <summary>
  29. /// Returns a vector pointing to the specified point.
  30. /// </summary>
  31. /// <param name="point">The point for which to produce the vector.</param>
  32. /// <returns>A vector pointing to the specified point.</returns>
  33. public static Vector2 GetVector(this Point point)
  34. {
  35. return new Vector2(point.X, point.Y);
  36. }
  37. /// <summary>
  38. /// Check for collision between two rectangle.
  39. /// </summary>
  40. /// <param name="first">The first rectangle.</param>
  41. /// <param name="second">The second rectangle.</param>
  42. /// <returns>Returns true if the two rectangles collide,
  43. /// false otherwise.</returns>
  44. public static bool HasCollision(this Rectangle first, Rectangle second)
  45. {
  46. return first.Intersects(second);
  47. }
  48. }
  49. }