public float[,] GenerateFallOffMap()
    {
        // create fallOffMap 2D array
        float[,] fallOffMap = new float[mapWidth, mapHeight];

        // add pattern to the array
        switch (fallOffPattern)
        {
        case (int)FallOffPattern.NONE:
        {
            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    fallOffMap[x, y] = 0;
                }
            }
        }
        break;

        case (int)FallOffPattern.CENTER:
        {
            fallOffMap = BrickPatterns.FallOffCenter(mapWidth, mapHeight, edge, size);
        }
        break;

        case (int)FallOffPattern.BOTTOM:
        {
            fallOffMap = BrickPatterns.FallOffBottom(mapWidth, mapHeight, edge, size);
        }
        break;

        case (int)FallOffPattern.TOP:
        {
            fallOffMap = BrickPatterns.FallOffTop(mapWidth, mapHeight, edge, size);
        }
        break;

        case (int)FallOffPattern.SIDES:
        {
            fallOffMap = BrickPatterns.FallOffSides(mapWidth, mapHeight, edge, size);
        }
        break;

        case (int)FallOffPattern.VERTICAL_SLICES:
        {
            fallOffMap = BrickPatterns.FallOffVerticalSlices(mapWidth, mapHeight, edge, size);
        }
        break;

        case (int)FallOffPattern.HORIZONTAL_SLICES:
        {
            fallOffMap = BrickPatterns.FallOffHorizontalSlices(mapWidth, mapHeight, edge, size);
        }
        break;
        }

        return(fallOffMap);
    }
    public float[,] GeneratePerlinNoiseMap()
    {
        // create and initialize brickSpace 2D array to zeros
        float[,] noiseMap = new float[mapWidth, mapHeight];

        noiseMap = BrickPatterns.PerlinNoiseMap(mapWidth, mapHeight, seed, mapScale, octaves, persistance, lacunarity, offset);

        return(noiseMap);
    }
    public float[,] GenerateExplosiveMap()
    {
        explosiveMap = new float[mapWidth, mapHeight];

        // add pattern to the array
        switch (explosivePattern)
        {
        case (int)ExplosivePattern.NONE:
        {
            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    explosiveMap[x, y] = 0;
                }
            }
        }
        break;

        case (int)ExplosivePattern.RANDOM:
        {
            InitializePlacementWeights(explosiveWeight, emptyExplosiveWeight);

            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    if (unbreakableMap[x, y] == empty)
                    {
                        // set point
                        explosiveMap[x, y] = placementExplosive[RandomWeighted(placementWeights, placementWeightTotal)];
                    }
                }
            }

            // mirror unbreakable map
            if (mirrorExplosive)
            {
                explosiveMap = BrickPatterns.Mirror(explosiveMap);
            }
        }
        break;
        }

        return(explosiveMap);
    }
    public void Generate()
    {
        mapWidth  = brickSpaceDimensions.x;
        mapHeight = brickSpaceDimensions.y;

        // generate unbreakable brick map
        unbreakableMap = GenerateUnbreakableMap();

        // generate explosive brick map
        explosiveMap = GenerateExplosiveMap();

        // generate noise map
        float[,] noiseMap = GeneratePerlinNoiseMap();

        // generate fall off map
        float[,] fallOffMap = GenerateFallOffMap();

        // mix noise map with fall off map
        noiseMap = MixMaps(noiseMap, fallOffMap);

        // mirror map
        noiseMap = BrickPatterns.Mirror(noiseMap);

        // mix unbreakable map with explosive map;
        MixMapsExplosive(unbreakableMap, explosiveMap);

        // mix noise map with unbreakable map;
        MixMapsUnbreakable(noiseMap, unbreakableMap);

        // remove random horizontal lines
        RemoveRandomHorizontalLines(noiseMap);

        // remove rogue explosive bricks
        RemoveRogueExplosives(noiseMap);

        // add bricks if empty
        noiseMap = CheckAndFixEmptyMap(noiseMap);

        // display map
        //MapDisplay display = FindObjectOfType<MapDisplay>();
        //display.DrawNoiseMap(noiseMap);

        // generate bricks
        if (generateBricks)
        {
            generateBricks = false;

            DestroyPreviousStuff();

            // spawn bricks
            float[,] brickSpace = noiseMap;

            for (int y = 0; y < brickSpace.GetLength(1); y++)
            {
                for (int x = 0; x < brickSpace.GetLength(0); x++)
                {
                    float sample = brickSpace[x, y];
                    //Debug.Log(sample);
                    if (sample == unbreakableBrickValue)
                    {
                        Instantiate(unbreakableBrick, startingPosition + new Vector2(x * brickOffset.x, y * brickOffset.y), transform.rotation);
                    }
                    else if (sample == explosiveBrickValue)
                    {
                        Instantiate(explosiveBrick, startingPosition + new Vector2(x * brickOffset.x, y * brickOffset.y), transform.rotation);
                    }
                    else if (sample > 0)
                    {
                        GameObject newBrick = (GameObject)GameObject.Instantiate(brick, startingPosition + new Vector2(x * brickOffset.x, y * brickOffset.y), transform.rotation);

                        float brHits = sample * brickFactor * 9;
                        newBrick.GetComponent <Brick>().hits = Mathf.Clamp(Mathf.RoundToInt(brHits), 1, 3);
                        //Debug.Log(brHits);

                        /*if (sample > 0 && sample <= hitsPercentage1)
                         * {
                         *  newBrick.GetComponent<Brick>().hits = 1;
                         * }
                         * else if (sample > hitsPercentage1 && sample <= hitsPercentage2)
                         * {
                         *  newBrick.GetComponent<Brick>().hits = 2;
                         * }
                         * else if (sample > hitsPercentage2)
                         * {
                         *  newBrick.GetComponent<Brick>().hits = 3;
                         * }*/
                    }
                }
            }
        }
    }
    public float[,] GenerateUnbreakableMap()
    {
        // create fallOffMap 2D array
        unbreakableMap = new float[mapWidth, mapHeight];

        // add pattern to the array
        switch (unbreakablePattern)
        {
        case (int)UnbreakablePattern.NONE:
        {
            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    unbreakableMap[x, y] = 0;
                }
            }
        }
        break;

        case (int)UnbreakablePattern.RANDOM:
        {
            InitializePlacementWeights(wallWeight, emptyWeight);

            do
            {
                for (int y = 0; y < mapHeight; y++)
                {
                    for (int x = 0; x < mapWidth; x++)
                    {
                        if (y == 0 || y == mapHeight - 1)
                        {
                            unbreakableMap[x, y] = empty;
                        }
                        else
                        {
                            //int[] numbers = { Placement.wall, Placement.empty, Placement.empty, Placement.empty };
                            unbreakableMap[x, y] = placement[RandomWeighted(placementWeights, placementWeightTotal)];         //numbers[UnityEngine.Random.Range(0, numbers.Length)]; //
                            //Debug.Log(unbreakableMap[x, y]);
                        }
                    }
                }

                // mirror unbreakable map
                if (mirrorUnbreakable)
                {
                    unbreakableMap = BrickPatterns.Mirror(unbreakableMap);
                }                                                                                         // && emptyWeight > 6
            } while (ConfirmPath(unbreakableMap) == false);
        }
        break;

        case (int)UnbreakablePattern.MAZE:
        {
            //unbreakableMap = BrickPatterns.UnbreakableMaze(mapWidth, mapHeight, emptyWeight);
        }
        break;
        }

        return(unbreakableMap);
    }