I am making an isometric tower defense game in XNA and trying to implement the A* pathfinding algorithms for my enemy AI. I am quite new to programming, especially AI and pathfinding, so please excuse my lack of knowledge.
I am using an a* tutorial from an XNA game programming book but it is made for standard square tile maps. I am trying to adapt this into my isometric tile engine and running into a few problems. Firstly, here are the major differences between the two maps:
Book:
- Tiles are 32x32.
- directions are up, down, left, right.
- obstacles are wall tiles
My Map:
- tiles are 64 x 64
- 4 directions: NE, NW, SE, SW
- impassable tiles
From these differences, I can figure out that I have to make changes to the grid setup, cost calculation and tile types.
I have made adjustments for the latter two, but I am having problems setting up the grid/gridnodes which is the most important part. Or perhaps, I simply don't understand the code well enough.
Here is the code for the Pathnode:
class PathNode
{
public PathNode ParentNode;
public PathNode EndNode;
private Vector2 gridLocation;
public float TotalCost;
public float DirectCost;
public Vector2 GridLocation
{
get { return gridLocation; }
set
{
gridLocation = new Vector2(
(float)MathHelper.Clamp(value.X, 0f, (float)50),
(float)MathHelper.Clamp(value.Y, 0f, (float)50));
}
}
public int GridX
{
get { return (int)gridLocation.X; }
}
public int GridY
{
get { return (int)gridLocation.Y; }
}
public PathNode(
PathNode parentNode,
PathNode endNode,
Vector2 gridLocation,
float cost)
{
ParentNode = parentNode;
GridLocation = gridLocation;
EndNode = endNode;
DirectCost = cost;
if (!(endNode == null))
{
TotalCost = DirectCost + LinearCost();
}
}
public float LinearCost()
{
return (
Vector2.Distance(
EndNode.GridLocation,
this.GridLocation));
}
public bool IsEqualToNode(PathNode node)
{
return (GridLocation == node.GridLocation);
}
}
What should I change in this class to adapt this pathnode.cs
to an isometric map? It is probably the gridLocation property but I am stumped as to what should be in there.
Any other tips on isometric pathfinding would be greatly appreciated!