Example #1
0
    private List <Vector3> getWaypointPositions(Maze maze)
    {
        MazeCell[,] cells = maze.Labrynth;

        List <Vector3> result = new List <Vector3>();

        //is a corner if wall-count is 1 in a four-circle
        for (int i = 1; i < maze.Rows; i++)
        {
            for (int k = 1; k < maze.Columns; k++)
            {
                MazeCell cell = cells[i, k];
                //cell is open space
                if (cell.RightCell.CanGoLeft())
                {
                    //and cell is corner
                    if (cell.CanGoDown() && cell.CanGoRight() && !cell.RightCell.CanGoDown() ||
                        cell.CanGoUp() && cell.CanGoRight() && !cell.RightCell.CanGoUp() ||
                        cell.CanGoUp() && cell.CanGoLeft() && !cell.LeftCell.CanGoUp() ||
                        cell.CanGoDown() && cell.CanGoLeft() && !cell.LeftCell.CanGoDown())
                    {
                        Vector3 position = new Vector3(World.Instance.Center.x - World.Instance.Size.x / 2 + i * cellWidth + cellWidth / 2.0f,
                                                       transform.position.y,
                                                       World.Instance.Center.y - World.Instance.Size.y / 2 + k * cellWidth + cellWidth / 2.0f);
                        result.Add(position);
                        Debug.Log("Found a corner!");
                    }
                    else
                    {
                        Debug.Log("Not a corner..");
                    }
                }
            }
        }

        return(result);
    }