private static void AsyncExample() { Console.WriteLine(nameof(AsyncExample)); //Setup the nodegrid and pathfinder. var pathfindaxManager = new PathfindaxManager(); var factory = new DefinitionNodeGridFactory(); var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, 3, 3); var definitionNodeGrid = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1)); var pathfinder = pathfindaxManager.CreateAstarPathfinder(definitionNodeGrid, new ManhattanDistance()); var exampleGameObject = new ExampleAsyncGameObject(pathfinder); //Wait till callback is called. while (!exampleGameObject.CallBackCalled) { exampleGameObject.Update(); } Console.ReadKey(); }
public void CalculateGridNodeClearances_FilledNodeGrid_Passes() { const int width = 4; const int height = 4; var factory = new DefinitionNodeGridFactory(); var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, width, height); var sourceNodeGrid = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1)); var astarNodeNetwork = new AstarNodeNetwork(sourceNodeGrid, new BrushfireClearanceGenerator(sourceNodeGrid, 5)); var sourceNodeNetworkCat1 = new Array2D <AstarNode>(astarNodeNetwork.GetCollisionLayerNetwork(PathfindaxCollisionCategory.Cat1), width, height); Assert.AreEqual(1, sourceNodeNetworkCat1[0, 0].Clearance); Assert.AreEqual(1, sourceNodeNetworkCat1[1, 0].Clearance); Assert.AreEqual(1, sourceNodeNetworkCat1[2, 0].Clearance); Assert.AreEqual(1, sourceNodeNetworkCat1[3, 0].Clearance); Assert.AreEqual(1, sourceNodeNetworkCat1[0, 1].Clearance); Assert.AreEqual(3, sourceNodeNetworkCat1[1, 1].Clearance); Assert.AreEqual(3, sourceNodeNetworkCat1[2, 1].Clearance); Assert.AreEqual(1, sourceNodeNetworkCat1[3, 1].Clearance); }
private static TestCaseData GeneratePathTestCase(int width, int height, Point2 start, Point2 end, Point2[] blockedNodes = null) { var factory = new DefinitionNodeGridFactory(); var collisionMask = new NodeGridCollisionMask(PathfindaxCollisionCategory.Cat1, width, height); if (blockedNodes != null) { foreach (var blockedNode in blockedNodes) { collisionMask.Layers[0].CollisionDirections[blockedNode.X, blockedNode.Y] = CollisionDirection.Solid; } } var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, collisionMask, true); var grid = new DefinitionNodeGrid(nodeGrid, new Vector2(1, 1)); var description = blockedNodes != null ? $"Path from {start} to {end} on a {width} by {height} grid with blocked nodes {string.Join(", ", blockedNodes)}" : $"Path from {start} to {end} on a {width} by {height} grid"; return(new TestCaseData(grid, start, end).SetName(description)); }
public IDefinitionNodeGrid GenerateGrid2D() { if (_definitionNodeGrid == null) { var factory = new DefinitionNodeGridFactory(); var nodeGrid = factory.GeneratePreFilledArray(GenerateNodeGridConnections.All, 320, 200); var definitionNodeGrid = new DefinitionNodeGrid(nodeGrid, new Vector2(32, 32)); /*definitionNodeGrid.PotentialArray[5, 4].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[5, 5].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[5, 6].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[5, 7].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[5, 8].CollisionCategory = PathfindaxCollisionCategory.Cat1; * * definitionNodeGrid.PotentialArray[5, 10].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[6, 10].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[7, 10].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[8, 10].CollisionCategory = PathfindaxCollisionCategory.Cat1; * definitionNodeGrid.PotentialArray[9, 10].CollisionCategory = PathfindaxCollisionCategory.Cat1;*/ _definitionNodeGrid = definitionNodeGrid; } return(_definitionNodeGrid); }
public DefinitionNodeGrid(GenerateNodeGridConnections generateNodeGridConnections, int width, int height, Vector2 scale, Vector2 offset = default(Vector2)) { Transformer = new GridTransformer(new Point2(width, height), scale, offset); NodeGrid = DefinitionNodeGridFactory.GeneratePreFilledArray(generateNodeGridConnections, width, height); }