Skip to content
Snippets Groups Projects
Commit a0dc77c4 authored by Susan Yuen's avatar Susan Yuen
Browse files

Changed path finder function to incorporate obstacles and occupied nodes

parent 79cf07f7
No related branches found
No related tags found
No related merge requests found
......@@ -299,10 +299,18 @@ namespace Controller
if (unitType == UnitType.Warrior)
{
return new Warrior(Content.Load<Texture2D>("warrior"), attackButton, moveButton,
Unit unit = new Warrior(Content.Load<Texture2D>("warrior"), attackButton, moveButton,
itemButton, waitButton, Content.Load<Texture2D>("warrior_Info"), unitPosition);
graph.getNode(unitPosition).setUnitOnNode(unit);
return unit;
}
return null;
}
private void setObstacles()
{
}
}
}
......@@ -176,7 +176,7 @@ namespace Controller
{
// TODO: (OPTIONAL, IGNORE FOR NOW) incorporate movability of nodes in the calculation
if (end.getIsObstacle())
if (end.getIsObstacle() || end.isOccupied())
{
return null;
}
......@@ -201,28 +201,36 @@ namespace Controller
}
// check if left gets closer to end node
if (!nodeAdded && Math.Abs(currentNodeX - 1 - endNodeX) < Math.Abs(currentNodeX - endNodeX))
if (!nodeAdded && Math.Abs(currentNodeX - 1 - endNodeX) < Math.Abs(currentNodeX - endNodeX)
&& !graph.getNode(currentNodeX - 1, currentNodeY).isOccupied()
&& !graph.getNode(currentNodeX - 1, currentNodeY).getIsObstacle())
{
path.AddLast(graph.getNode(currentNodeX - 1, currentNodeY));
nodeAdded = true;
}
// check if right gets closer to end node
if (!nodeAdded && Math.Abs(currentNodeX + 1 - endNodeX) < Math.Abs(currentNodeX - endNodeX))
if (!nodeAdded && Math.Abs(currentNodeX + 1 - endNodeX) < Math.Abs(currentNodeX - endNodeX)
&& !graph.getNode(currentNodeX + 1, currentNodeY).isOccupied()
&& !graph.getNode(currentNodeX + 1, currentNodeY).getIsObstacle())
{
path.AddLast(graph.getNode(currentNodeX + 1, currentNodeY));
nodeAdded = true;
}
// check if up gets closer to end node
if (!nodeAdded && Math.Abs(currentNodeY + 1 - endNodeY) < Math.Abs(currentNodeY - endNodeY))
if (!nodeAdded && Math.Abs(currentNodeY + 1 - endNodeY) < Math.Abs(currentNodeY - endNodeY)
&& !graph.getNode(currentNodeX, currentNodeY + 1).isOccupied()
&& !graph.getNode(currentNodeX, currentNodeY + 1).getIsObstacle())
{
path.AddLast(graph.getNode(currentNodeX, currentNodeY + 1));
nodeAdded = true;
}
// check if down gets closer to end node
if (!nodeAdded && Math.Abs(currentNodeY - 1 - endNodeY) < Math.Abs(currentNodeY - endNodeY))
if (!nodeAdded && Math.Abs(currentNodeY - 1 - endNodeY) < Math.Abs(currentNodeY - endNodeY)
&& !graph.getNode(currentNodeX, currentNodeY - 1).isOccupied()
&& !graph.getNode(currentNodeX, currentNodeY - 1).getIsObstacle())
{
path.AddLast(graph.getNode(currentNodeX, currentNodeY - 1));
nodeAdded = true;
......
......@@ -48,6 +48,8 @@ namespace Controller
Vector2 mouseClickCoordinates = new Vector2(currentMouseState.X, currentMouseState.Y); // mouse click coordinates
Node nodeClickedOn = graph.getNode(mouseClickCoordinates);
#region Check if a unit is clicked
// if player clicks after unit is already selected ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment