summaryrefslogtreecommitdiff
path: root/Pathfinding Visualizer/Assets/UI Elements/UI
diff options
context:
space:
mode:
Diffstat (limited to 'Pathfinding Visualizer/Assets/UI Elements/UI')
-rw-r--r--Pathfinding Visualizer/Assets/UI Elements/UI/Scripts/nMain.cs31
1 files changed, 25 insertions, 6 deletions
diff --git a/Pathfinding Visualizer/Assets/UI Elements/UI/Scripts/nMain.cs b/Pathfinding Visualizer/Assets/UI Elements/UI/Scripts/nMain.cs
index 30f3b49..f6bb494 100644
--- a/Pathfinding Visualizer/Assets/UI Elements/UI/Scripts/nMain.cs
+++ b/Pathfinding Visualizer/Assets/UI Elements/UI/Scripts/nMain.cs
@@ -27,9 +27,9 @@ public class nMain : MonoBehaviour
void Start()
{
// Create world
- int width = 32;
- int height = 16;
- float cellSize = 5f;
+ int width = 16;
+ int height = 8;
+ float cellSize = 10f;
Vector3 origin = new Vector3(-77, -34);
world = new LogicGrid(width, height, cellSize, origin);
@@ -107,11 +107,15 @@ public class nMain : MonoBehaviour
public void ResetGrid()
{
world.reset();
+ agent = new Vector2Int();
+ obstacles = new List<Vector2Int>();
+ samples = new List<Vector2Int>();
}
public void StartAlgorithm()
{
Vector2Int coord = new Vector2Int();
+ bool agentFound = false;
// Collect information about world
for (int x = 0; x < world.GetWidth(); x++)
@@ -120,7 +124,7 @@ public class nMain : MonoBehaviour
int index = x * world.GetHeight() + y;
int value = world.GetValue(x, y);
- Debug.Log("x: " + x + " y: " + y + " | value: " + value);
+ //Debug.Log("x: " + x + " y: " + y + " | value: " + value);
// Add coordinate to obstacle array
if (value == 1)
@@ -140,18 +144,33 @@ public class nMain : MonoBehaviour
if (!samples.Contains(coord))
samples.Add(coord);
}
- // Add coordinate to obstacle array
+ // Add coordinate to agent array
if (value == 3)
{
agent.x = x;
agent.y = y;
+ agentFound = true;
}
}
+ if (!agentFound)
+ {
+ Debug.Log("NO AGENT!");
+ return;
+ }
+
+ if (samples.Count == 0)
+ {
+ Debug.Log("NO SAMPLES!");
+ return;
+ }
if (true)
{
- Pathfinder astar = new Pathfinder(world, agent, obstacles, samples, algorithm, 0);
+ Pathfinder path = new Pathfinder(world, agent, obstacles, samples, 0, 0);
+ Stack<Node> result = path.result;
+ Debug.Log("GO ANIMATE");
+ cellMesh.Animate(result);
}
}