本文整理汇总了C#中PathNode.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# PathNode.GetLength方法的具体用法?C# PathNode.GetLength怎么用?C# PathNode.GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode.GetLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapToArray
private void MapToArray(ref PathNode[,] searchmap)
{
Node[,] map = AStarMap.Mapnodes;
//searchmap = new PathNode[AStarMap.GetLength(0),AStarMap.GetLength(1)];
int ymax = searchmap.GetLength(0);
int xmax = searchmap.GetLength(1);
for (int y = 0; y < ymax; y++)
{
for (int x = 0; x < xmax; x++)
{
searchmap[y, x].FromNode(map[y, x]);
}
}
//return searchmap;
}
示例2: GetNewNode
private void GetNewNode(PathNode rootNode, int xOffset, int yOffset,PathNode[,] searchMap)
{
//Check if xOffset is in Bounds
if(rootNode.MapXPosition + xOffset >= 0 && rootNode.MapXPosition + xOffset < searchMap.GetLength(1))
if (rootNode.MapYPosition + yOffset >= 0 && rootNode.MapYPosition + yOffset < searchMap.GetLength(0))
{
PathNode newNode = searchMap[rootNode.MapYPosition + yOffset, rootNode.MapXPosition + xOffset];
//Check if its not the RootNode
if (newNode != rootNode)
//Exclude Closed Nodes
if (newNode.State == NodeState.Unknown)
{
if (newNode.Walkable != Walkable.Blocked)
{
if (!(newNode.Walkable == Walkable.NotReachable && yOffset < 0) && !(newNode.Walkable == Walkable.Platform && yOffset > 0))
{
newNode.RootNode = rootNode;
newNode.State = NodeState.Known;
newNode.CalculateFCost(aimglobal.Rectangle.CenterToVector2());
//openList.Add(newNode);
try
{
LinkedListNode<PathNode> smaller = openLinkedList.First;
while (newNode.FCost > smaller.Value.FCost)
{
smaller = smaller.Next;
}
openLinkedList.AddBefore(smaller, newNode);
}
catch (Exception)
{
openLinkedList.AddLast(newNode);
}
}
}
}
else if (newNode.State == NodeState.Known)
{
float oldFCost = newNode.FCostNoAim;
//Calculate new F Cost
float newFCost = newNode.CalculateFCost(aimglobal.Rectangle.CenterToVector2(), rootNode);
//If newFcost ist smaller than the old F Cost, we found a shorter way to this node
if (newFCost < oldFCost)
{
openLinkedList.Remove(newNode);
newNode.RootNode = rootNode;
newNode.CalculateFCost(aimglobal.Rectangle.CenterToVector2());
try
{
LinkedListNode<PathNode> smaller = openLinkedList.First;
while (newNode.FCost > smaller.Value.FCost)
{
smaller = smaller.Next;
}
openLinkedList.AddBefore(smaller, newNode);
}
catch (Exception)
{
openLinkedList.AddLast(newNode);
}
}
//openList.Add(newNode);
}
}
}