public void PreparePath(LevelCreator.Node node) { //get path if (nodeSelected == node) { return; } List <LevelCreator.Node> path = GetPath(node); //if length 0 return if (path.Count == 0) { return; } //disable color for all path parts ColorPath(nodePath, Color.white); nodePath = path; nodeSelected = node; //enable color for all path parts ColorPath(path, pathColor); }
private void CheckNode(int x, int y, int height) { //check if out of bounds if (x < 0 || y < 0) { return; } if (x >= lC.levelW - 1 || y >= lC.levelW - 1) { return; } LevelCreator.Node node = lC.level[x, y, height]; //check if node is in open or closed foreach (Node n in open) { if (n.node == node) { return; } } if (closed.Contains(node)) { return; } //other checks if (!node.filled) { return; } if (node.occupied) { return; } switch (node.tile.type) { case Ground.GroundType.Wall: return; case Ground.GroundType.Unwalkable: return; default: break; } //add parent, cost and add to open Node newNode = new Node(node, curNode); newNode.cost = (int)Vector2.Distance(new Vector2(newNode.node.x, newNode.node.y), new Vector2(myNode.x, myNode.y)); newNode.cost += (int)Vector2.Distance(new Vector2(newNode.node.x, newNode.node.y), new Vector2(destination.x, destination.y)); open.Add(newNode); }
private List <LevelCreator.Node> GetPath(LevelCreator.Node dest) { List <LevelCreator.Node> path = new List <LevelCreator.Node>(); destination = dest; open = new List <Node>(); closed = new List <LevelCreator.Node>(); open.Add(new Node(myNode, null)); curNode = null; LevelCreator.Node n; while (open.Count > 0) { curNode = open[0]; open.Remove(curNode); if (curNode.node == dest) { break; } n = curNode.node; //check around the character closed.Add(curNode.node); CheckNode(n.x, n.y, n.z + 1); CheckNode(n.x + 1, n.y, n.z); CheckNode(n.x, n.y, n.z - 1); CheckNode(n.x - 1, n.y, n.z); //sort open.Sort(); } if (!(curNode != null)) { return(path); } if (curNode.node != dest) { return(path); } path.Add(curNode.node); while (curNode.parent != null) { path.Add(curNode.parent.node); curNode = curNode.parent; } return(path); }
public Node(LevelCreator.Node _node, Node _parent) { node = _node; parent = _parent; }
public void SetPosition(LevelCreator.Node node) { SetPosition(LevelCreator.self.CalcPos(node)); }