Ejemplo n.º 1
0
    private void GenerateBricks()
    {
        this.remainingBricks    = new List <BrickHandler>();
        int[,] currentLevelData = this.LevelsData[this.CurrentLevel];
        float currentSpawnX = initialBrickSpawnPositionX;
        float currentSpawnY = initialBrickSpawnPositionY;
        float zShift        = 0;

        for (int row = 0; row < this.maxRows; row++)
        {
            for (int col = 0; col < this.maxCols; col++)
            {
                int brickType = currentLevelData[row, col];

                if (brickType > 0)
                {
                    BrickHandler newBrick = Instantiate(brickPrefab, new Vector3(currentSpawnX, currentSpawnY, 0 - zShift), Quaternion.identity) as BrickHandler;
                    newBrick.Init(bricksContainer.transform, this.sprites[brickType - 1], this.BrickColors[brickType], brickType);

                    this.remainingBricks.Add(newBrick);
                    zShift += 0.0001f;
                }

                currentSpawnX += shiftAmount;
                if (col + 1 == this.maxCols)
                {
                    currentSpawnX = initialBrickSpawnPositionX;
                }
            }

            currentSpawnY -= shiftAmount;
        }

        this.initialBricksCount = this.remainingBricks.Count;
        OnLevelLoaded?.Invoke();
    }