本文整理汇总了C#中TileMap.get方法的典型用法代码示例。如果您正苦于以下问题:C# TileMap.get方法的具体用法?C# TileMap.get怎么用?C# TileMap.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileMap
的用法示例。
在下文中一共展示了TileMap.get方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: pathfindFallback
/// <summary>
/// Finds the path from source to destination point (does not consider ally unit)
/// </summary>
/// <param name="tm">TileMap</param>
/// <param name="src">Source point (the Unit or Character moving)</param>
/// <param name="dest">Destination point (the target)</param>
/// <returns>A point adjacent to the source which is the next move of the character or unit
/// in order to arrive to destination. or the source point if no path is found</returns>
public static Point pathfindFallback(TileMap tm, Point src, Point dest)
{
Dictionary<Point, int> map = new Dictionary<Point, int>();
Queue<PointCounter> main = new Queue<PointCounter>();
Queue<PointCounter> temp = new Queue<PointCounter>();
PointCounter cur;
PointCounter tcur;
main.Enqueue(new PointCounter(dest, 0));
map[dest] = 0;
int cc;
bool f = false;
while (main.Count > 0)
{
cur = main.Dequeue();
temp.Clear();
if (cur.p == src)
{
f = true;
break;
}
cc = cur.c + 1;
temp.Enqueue(new PointCounter(cur.p.X, cur.p.Y - 1, cc));
temp.Enqueue(new PointCounter(cur.p.X + 1, cur.p.Y, cc));
temp.Enqueue(new PointCounter(cur.p.X, cur.p.Y + 1, cc));
temp.Enqueue(new PointCounter(cur.p.X - 1, cur.p.Y, cc));
while (temp.Count > 0)
{
tcur = temp.Dequeue();
if (tcur.p != src)
{
if (!tm.inMap(tcur.p) || tm.get(tcur.p.X, tcur.p.Y) == TileMap.Tile_Type.BLOCK_TERRAIN)
continue;
if (map.ContainsKey(tcur.p) && map[tcur.p] <= tcur.c)
continue;
}
map[tcur.p] = tcur.c;
main.Enqueue(tcur);
}
}
if (!f)
return new Point(-1, -1);
Point ret = src;
cc = map[src];
temp.Clear();
temp.Enqueue(new PointCounter(src.X, src.Y - 1, 0));
temp.Enqueue(new PointCounter(src.X + 1, src.Y, 0));
temp.Enqueue(new PointCounter(src.X, src.Y + 1, 0));
temp.Enqueue(new PointCounter(src.X - 1, src.Y, 0));
while (temp.Count > 0)
{
tcur = temp.Dequeue();
if (map.ContainsKey(tcur.p) && map[tcur.p] < cc)
{
cc = map[tcur.p];
ret = tcur.p;
}
}
if (tm.get(ret.X, ret.Y) != TileMap.Tile_Type.NOTHING||ret==dest)
return src;
return ret;
}