public WayPoint(Point Position, WayPoint Parent, bool type) { this.PositionX = Position.X; this.PositionY = Position.Y; this.Parent = Parent; this.type = type; }
public void Add(WayPoint point) { Count++; Array.Resize<WayPoint>(ref List, Count + 1); List[Count] = point; int CurrentIndex = Count; int parentIndex = CurrentIndex / 2; while (CurrentIndex != 1) { parentIndex = CurrentIndex / 2; if (List[parentIndex] == null) { WayPoint tmpValue = this.List[parentIndex]; this.List[parentIndex] = this.List[CurrentIndex]; this.List[CurrentIndex] = tmpValue; CurrentIndex = parentIndex; } else if (this.List[CurrentIndex].Cost <= List[parentIndex].Cost) { WayPoint tmpValue = this.List[parentIndex]; this.List[parentIndex] = this.List[CurrentIndex]; this.List[CurrentIndex] = tmpValue; CurrentIndex = parentIndex; } else { break; } } }
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; } }