当前位置: 首页>>代码示例>>C#>>正文


C# TileMap.inMap方法代码示例

本文整理汇总了C#中TileMap.inMap方法的典型用法代码示例。如果您正苦于以下问题:C# TileMap.inMap方法的具体用法?C# TileMap.inMap怎么用?C# TileMap.inMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileMap的用法示例。


在下文中一共展示了TileMap.inMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateQuadrant

        private static List<Tile> CalculateQuadrant(Tile source, int visionRadius, TileMap map, Line sourceVisionLine)
        {

            List<Tile> quadrant = new List<Tile>();
            List<Tile> visibleTiles = new List<Tile>();

            int xFactor = (int)(sourceVisionLine.start.x * 2 - 1);
            int yFactor = (int)(sourceVisionLine.end.y * 2 - 1);

            for (int x = 1; x <= visionRadius / Math.Cos(45); x++)
            {
                for (int y = 0; y <= x; y++)
                {
                    if (!(visionRadius < Math.Sqrt(Math.Pow(x - y, 2) + Math.Pow(y, 2))))
                    {
                        if (map.inMap(source.x + xFactor * (x - y), source.y + yFactor * y))
                        {
                            quadrant.Add(map[source.x + xFactor * (x - y), source.y + yFactor * y]);
                        }
                    }
                }
            }

#if(FOV)
            for (int i = 0; i < quadrant.Count; i++)
                quadrant[i].num = i;
#endif

            List<View> views = new List<View>();
            views.Add(new View(
                source.x + (int) sourceVisionLine.end.x,
                source.y + (int) sourceVisionLine.end.y, 
                source.x + xFactor * visionRadius + (int) sourceVisionLine.start.x, 
                source.y + (int) sourceVisionLine.start.y,
                source.x + (int) sourceVisionLine.start.x,
                source.y + (int) sourceVisionLine.start.y, 
                source.x + (int) sourceVisionLine.end.x, 
                source.y + yFactor * visionRadius + (int) sourceVisionLine.end.y)); // create shallow and steep initial lines
             
            for (int i = 0; i < quadrant.Count; i++)
            {
                List<View> currentViews = new List<View>();
                currentViews.AddRange(views);

                // fov calculation
                while (currentViews.Count > 0)
                {

                    int j = views.FindIndex(x => x.Equals(currentViews[0]));
                    visibilityStatus? vis = getVisibilityStatus(quadrant[i], source, map, currentViews.ElementAt(0), sourceVisionLine);
                    switch (vis)
                    {
                        case visibilityStatus.outside:
                            //Debug.WriteLine("Outside");
                            //do nothing
                            //quadrant[i].debug = Color.Gold;
                            break;

                        case visibilityStatus.between:
                            //Debug.WriteLine("Between");
#if(FOV)
                            quadrant[i].debug = Color.Green;
#endif
                            visibleTiles.Add(quadrant[i]);
                            if (!quadrant[i].Translucent)
                            {

                                Line possibleNewShallow = new Line(views[j].shallow.start, quadrant[i].position + sourceVisionLine.end);

                                View view = new View(possibleNewShallow, currentViews[0].steep);

                                foreach (Tile tile in View.steepBump)
                                {
                                    if (obstructionCheck(tile, source, view.shallow, sourceVisionLine))
                                    {
                                        view.shallow = new Line(tile.position + sourceVisionLine.start, view.shallow.end);
                                    }
                                }

                                if (!Line.sameLine(view.shallow, currentViews[0].steep))
                                {
                                    views.Add(view);
#if(FOV)
                                    linesToDraw.Add(view.shallow);
                                    linesToDraw.Add(view.steep);
#endif
                                }


                                Line possibleNewSteep = new Line(views[j].steep.start, quadrant[i].position + sourceVisionLine.start);

                                view = new View(currentViews[0].shallow, possibleNewSteep);

                                foreach (Tile tile in View.shallowBump)
                                {
                                    if (obstructionCheck(tile, source, view.steep, sourceVisionLine))
                                    {
                                        view.steep = new Line(tile.position + sourceVisionLine.end, view.steep.end);
                                    }
                                }
//.........这里部分代码省略.........
开发者ID:brokoli78,项目名称:ProjectRogue,代码行数:101,代码来源:FOV.cs

示例2: 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;
            }
开发者ID:nlacombe42,项目名称:forgottenschism,代码行数:87,代码来源:AI.cs


注:本文中的TileMap.inMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。