Beispiel #1
0
        public static void GeneratePath(Level.Tunnel tunnel, Level level)
        {
            var targetCells = new List <VoronoiCell>();

            for (int i = 0; i < tunnel.Nodes.Count; i++)
            {
                var closestCell = level.GetClosestCell(tunnel.Nodes[i].ToVector2());
                if (closestCell != null && !targetCells.Contains(closestCell))
                {
                    targetCells.Add(closestCell);
                }
            }
            tunnel.Cells.AddRange(GeneratePath(targetCells, level.GetAllCells()));
        }
Beispiel #2
0
        public static void GeneratePath(Level.Tunnel tunnel, List <VoronoiCell> cells, List <VoronoiCell>[,] cellGrid, int gridCellSize, Rectangle limits)
        {
            var targetCells = new List <VoronoiCell>();

            for (int i = 0; i < tunnel.Nodes.Count; i++)
            {
                //a search depth of 2 is large enough to find a cell in almost all maps, but in case it fails, we increase the depth
                int searchDepth = 2;
                while (searchDepth < 5)
                {
                    int cellIndex = FindCellIndex(tunnel.Nodes[i], cells, cellGrid, gridCellSize, searchDepth);
                    if (cellIndex > -1)
                    {
                        targetCells.Add(cells[cellIndex]);
                        break;
                    }

                    searchDepth++;
                }
            }
            tunnel.Cells.AddRange(GeneratePath(targetCells, cells, limits));
        }