ExtensionMethods.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //-----------------------------------------------------------------------------
  2. // ExtensionMethods.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. namespace HoneycombRush
  9. {
  10. /// <summary>
  11. /// A class containing extension methods.
  12. /// </summary>
  13. public static class ExtensionMethods
  14. {
  15. /// <summary>
  16. /// Returns a vector pointing to the rectangle's top left corner.
  17. /// </summary>
  18. /// <param name="rect">The rectangle for which to produce the vector.</param>
  19. /// <returns>A vector pointing to the rectangle's top left corner.</returns>
  20. public static Vector2 GetVector(this Rectangle rect)
  21. {
  22. return new Vector2(rect.X, rect.Y);
  23. }
  24. /// <summary>
  25. /// Returns a vector pointing to the specified point.
  26. /// </summary>
  27. /// <param name="point">The point for which to produce the vector.</param>
  28. /// <returns>A vector pointing to the specified point.</returns>
  29. public static Vector2 GetVector(this Point point)
  30. {
  31. return new Vector2(point.X, point.Y);
  32. }
  33. /// <summary>
  34. /// Check for collision between two rectangle.
  35. /// </summary>
  36. /// <param name="first">The first rectangle.</param>
  37. /// <param name="second">The second rectangle.</param>
  38. /// <returns>Returns true if the two rectangles collide,
  39. /// false otherwise.</returns>
  40. public static bool HasCollision(this Rectangle first, Rectangle second)
  41. {
  42. return first.Intersects(second);
  43. }
  44. }
  45. }