diff --git a/HexGrid.cs b/HexGrid.cs index 1de91f0..3700c1a 100644 --- a/HexGrid.cs +++ b/HexGrid.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Linq; using Godot; -using GodotComponentTest.utils; using Priority_Queue; using AxialCoordDirectionPair = System.Tuple; @@ -22,7 +21,7 @@ public class HexGrid : Resource public float PathCostDefault = 1; - public int FindPathCheckedCells = 0; + public int FindPathCheckedCellCount; public Vector2 HexSize { @@ -76,11 +75,6 @@ public class HexGrid : Resource return result; } - public void SetBoundsOffset(Vector2 minOffset, Vector2 maxOffset) - { - SetBounds(HexCell.FromOffsetCoords(minOffset), HexCell.FromOffsetCoords(maxOffset)); - } - public void SetBounds(Vector2 minAxial, Vector2 maxAxial) { SetBounds(new HexCell(minAxial), new HexCell(maxAxial)); @@ -94,6 +88,13 @@ public class HexGrid : Resource (_maxCoords.AxialCoords - _minCoords.AxialCoords) + Vector2.One); } + public void SetBounds(HexCell center, int size) + { + Vector2 centerOffset = center.OffsetCoords; + SetBounds(GetHexAtOffset(centerOffset - Vector2.One * size / 2), + GetHexAtOffset(centerOffset + Vector2.One * size / 2)); + } + public void AddObstacle(Vector2 axialCoords, float cost = 0) { AddObstacle(new HexCell(axialCoords), cost); @@ -221,11 +222,11 @@ public class HexGrid : Resource cameFrom.Add(startHex.AxialCoords, startHex.AxialCoords); costSoFar.Add(startHex.AxialCoords, 0); - FindPathCheckedCells = 0; + FindPathCheckedCellCount = 0; while (frontier.Any()) { - FindPathCheckedCells++; + FindPathCheckedCellCount++; HexCell currentHex = new HexCell(frontier.Dequeue()); Vector2 currentAxial = currentHex.AxialCoords; @@ -264,7 +265,7 @@ public class HexGrid : Resource } } - // GD.Print("Checked Cell Count: " + FindPathCheckedCells); + // GD.Print("Checked Cell Count: " + FindPathCheckedCellCount); List result = new List(); if (!cameFrom.ContainsKey(goalHex.AxialCoords)) @@ -293,7 +294,6 @@ public class HexGrid : Resource { List result = new List(); - HexCell toCell = GetHexAt(toPlane); float distance = (toPlane - fromPlane).Length(); Vector2 direction = (toPlane - fromPlane) / distance; diff --git a/components/NavigationComponent.cs b/components/NavigationComponent.cs index f8e97e4..f029a1a 100644 --- a/components/NavigationComponent.cs +++ b/components/NavigationComponent.cs @@ -140,6 +140,7 @@ public class NavigationComponent : Spatial return; } + TileWorld.HexGrid.SetBounds(fromCell, 40); List path = TileWorld.HexGrid.FindPath(fromCell, toCell); // Generate grid navigation points