PathNode.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. namespace Robot_Rampage
  7. {
  8. class PathNode
  9. {
  10. #region Declarations
  11. public PathNode ParentNode;
  12. public PathNode EndNode;
  13. private Vector2 gridLocation;
  14. public float TotalCost;
  15. public float DirectCost;
  16. #endregion
  17. #region Properties
  18. public Vector2 GridLocation
  19. {
  20. get { return gridLocation; }
  21. set
  22. {
  23. gridLocation = new Vector2(
  24. (float)MathHelper.Clamp(value.X, 0f, (float)TileMap.MapWidth),
  25. (float)MathHelper.Clamp(value.Y, 0f, (float)TileMap.MapHeight));
  26. }
  27. }
  28. public int GridX
  29. {
  30. get { return (int)gridLocation.X; }
  31. }
  32. public int GridY
  33. {
  34. get { return (int)gridLocation.Y; }
  35. }
  36. #endregion
  37. #region Constructor
  38. public PathNode(
  39. PathNode parentNode,
  40. PathNode endNode,
  41. Vector2 gridLocation,
  42. float cost)
  43. {
  44. ParentNode = parentNode;
  45. GridLocation = gridLocation;
  46. EndNode = endNode;
  47. DirectCost = cost;
  48. if (!(endNode == null))
  49. {
  50. TotalCost = DirectCost + LinearCost();
  51. }
  52. }
  53. #endregion
  54. #region Helper Methods
  55. public float LinearCost()
  56. {
  57. return (
  58. Vector2.Distance(
  59. EndNode.GridLocation,
  60. this.GridLocation));
  61. }
  62. #endregion
  63. #region Public Methods
  64. public bool IsEqualToNode(PathNode node)
  65. {
  66. return (GridLocation == node.GridLocation);
  67. }
  68. #endregion
  69. }
  70. }