public static NodeMap CreateFromTileMap(TileMap tileMap, SpritePolygon collisionPolygon) { NodeMap nodeMap = new NodeMap(tileMap.MapWidthTiles, tileMap.MapHeightTiles, tileMap.TileHeight, tileMap.TileWidth); nodeMap.generationPolygon = (SpritePolygon)collisionPolygon.Clone(); for (int i = 0; i < nodeMap.XSize; i++) { for (int j = 0; j < nodeMap.YSize; j++) { Vector2 position = new Vector2 { X = nodeMap.Nodes[i, j].X, Y = nodeMap.Nodes[i, j].Y }; collisionPolygon.MoveTo(position); Collision collision = tileMap.CheckCollisionWithTerrain(collisionPolygon); if (collision == Collision.Solid || collision == Collision.Water) { nodeMap.Nodes[i, j].IsFree = false; nodeMap.Nodes[i, j].IsTerrain = true; } } } return(nodeMap); }
public static NodeMap GetNodeMap(SpritePolygon collisionPolygon) { var polygon = (SpritePolygon)collisionPolygon.Clone(); polygon.MoveTo(Vector2.Zero); if (nodeMaps.TryGetValue(polygon, out NodeMap nodeMap)) { return(nodeMap); } var map = NodeMap.CreateFromTileMap(GameState.TileMap, polygon); polygon.MoveTo(Vector2.Zero); nodeMaps.Add(polygon, map); return(map); }