Ejemplo n.º 1
0
    /// <summary>
    /// Generates the map.
    /// </summary>
    private void GenerateMap()
    {
        // initialises the map based on the width and height
        m_map = new int[width, height];
        // fills the map
        RandomFillMap();

        // smooths the map multiple times
        for (int i = 0; i < 5; i++)
        {
            SmoothMap();
        }

        ProcessMap();

        int borderSize = 1;

        int[,] borderedMap = new int[width + borderSize * 2, height + borderSize * 2];

        for (int x = 0; x < borderedMap.GetLength(0); x++)
        {
            for (int y = 0; y < borderedMap.GetLength(1); y++)
            {
                if (x >= borderSize && x < width + borderSize && y >= borderSize && y < height + borderSize)
                {
                    borderedMap[x, y] = m_map[x - borderSize, y - borderSize];
                }
                else
                {
                    borderedMap[x, y] = 1;
                }
            }
        }

        TileGenerator tileGen = GetComponent <TileGenerator>();

        if (tileGen != null)
        {
            tileGen.GenerateMesh(borderedMap, 1);
        }

        MeshGenerator meshGen = GetComponent <MeshGenerator>();

        if (meshGen != null)
        {
            meshGen.GenerateMesh(borderedMap, 1);
        }
    }