Time for action – the PathNode class
Add a new class called PathNode to the Robot Rampage project.
Add the following
using
directive to the top of the class file:using Microsoft.Xna.Framework;
Add declarations to the PathNode class:
#region Declarations public PathNode ParentNode; public PathNode EndNode; private Vector2 gridLocation; public float TotalCost; public float DirectCost; #endregion
Add properties to the PathNode class:
#region Properties public Vector2 GridLocation { get { return gridLocation; } set { gridLocation = new Vector2( (float)MathHelper.Clamp(value.X,0f,(float)TileMap.MapWidth), (float)MathHelper.Clamp(value.Y,0f,(float)TileMap.MapHeight)); } } public int GridX { get { return (int)gridLocation.X; } } public int GridY { get { return (int)gridLocation.Y; } } #endregion
Add a constructor to the PathNode class:
#region Constructor public PathNode( PathNode parentNode, PathNode endNode, Vector2 gridLocation, ...