public List<Vector2> FindCellWay(Point startCell, Point endCell) { pointMap = new byte[_tileMap.Width, _tileMap.Height]; OpenList = new BinaryHeap(); WayPoint startPoint = new WayPoint(startCell, null, true); startPoint.CalculateCost(_tileMap, Creature, endCell,0, ImprovedPathFinding); OpenList.Add(startPoint); while (OpenList.Count != 0) { WayPoint node = OpenList.Get(); if (node.PositionX == endCell.X && node.PositionY == endCell.Y) { WayPoint nodeCurrent = node; List<Vector2> points = new List<Vector2>(); while (nodeCurrent != null) { points.Insert(0, new Vector2(nodeCurrent.PositionX, nodeCurrent.PositionY)); nodeCurrent = nodeCurrent.Parent; } return points; } OpenList.Remove(); Point temp = new Point(node.PositionX, node.PositionY); if (DiagonalMovesAllowed) { // if (CheckPassability(temp.X - 1, temp.Y) || CheckPassability(temp.X, temp.Y - 1)) // AddNode(node, -1, -1, false, endCell); if (CheckPassability(temp.X, temp.Y - 1) && _tileMap[temp.X + 1, temp.Y] == CellType.Wall) AddNode(node, 1, -1, false, endCell); if (CheckPassability(temp.X, temp.Y - 1) && _tileMap[temp.X - 1, temp.Y] == CellType.Wall) AddNode(node, -1, -1, false, endCell); if (CheckPassability(temp.X + 1, temp.Y) && _tileMap[temp.X, temp.Y + 1] == CellType.Wall) AddNode(node, 1, 1, false, endCell); if (CheckPassability(temp.X - 1, temp.Y) && _tileMap[temp.X , temp.Y + 1] == CellType.Wall) AddNode(node, -1, 1, false, endCell); // if (CheckPassability(temp.X + 1, temp.Y) || CheckPassability(temp.X, temp.Y + 1)) // AddNode(node, 1, 1, false, endCell); if (CheckPassability(temp.X, temp.Y)) { } } AddNode(node, -1, 0, true, endCell); AddNode(node, 0, -1, true, endCell); AddNode(node, 1, 0, true, endCell); AddNode(node, 0, 1, true, endCell); } return null; }
private void AddPlatformerNode(WayPoint node, sbyte offSetX, sbyte offSetY, bool type, Point endCell) { Point pos = new Point(node.PositionX + offSetX, node.PositionY + offSetY); if (!CheckPlatformPassability(pos.X, pos.Y)) return; if (pointMap[pos.X, pos.Y] != 1) { byte addCost = 0;// _tileMap[pos.X, pos.Y + 1] == CellType.Free ? (byte)20 : (byte)0; WayPoint temp = new WayPoint(pos, node, type); temp.CalculateCost(_tileMap, Creature, endCell, addCost, ImprovedPathFinding); OpenList.Add(temp); pointMap[pos.X, pos.Y] = 1; } }