Ejemplo n.º 1
0
    public void GenerateNewLevel()
    {
        CreateClearScene();

        if (MainLevel >= 1)
        {
            Color classicColor = new Color(0.855f, 0.855f, 0.855f, 1);
            Camera.main.backgroundColor = Color.Lerp(classicColor, Random.ColorHSV(), 0.8f * Mathf.Clamp01((MainLevel - 1) / 10.0f));
        }
        else
        {
            Camera.main.backgroundColor = new Color(0.855f, 0.855f, 0.855f, 1);
        }

        TrueSize = Random.Range(MinMaxSize.x, MinMaxSize.y);

        int colOfFigures   = 5 + (int)(PointLevel * 1.5f);
        int idOfTrueFigure = Random.Range(0, colOfFigures);

        float LevelOut = MainLevel / 3;

        LevelOut = Mathf.Clamp(MainLevel - LevelOut * 3, 0, 2);

        for (int i = 0; i < colOfFigures; i++)
        {
            GameObject newFigure = Instantiate(_gameElementPrefab, _gameElementContainerBodyChild);

            newFigure.name = "figure_" + i;
            GameElement FigureGameElement = newFigure.GetComponent <GameElement>();
            if (idOfTrueFigure == i)
            {
                FigureGameElement.Generate(this, TrueSize, true);
                _trueVariantOfElement = FigureGameElement;
            }
            else
            {
                if (Random.Range(0.0f, 1.0f) >= 0.5f)
                {
                    float sizeFigure = Mathf.Clamp(TrueSize + Random.Range(1, colOfFigures + 1) * LevelsSizeOffset[(int)LevelOut], MinMaxSize.x, 1.5f * MinMaxSize.y);
                    if (MainLevel >= 6)
                    {
                        sizeFigure = Mathf.Lerp(sizeFigure, TrueSize, ((MainLevel - 5.0f) / 10.0f));
                    }
                    FigureGameElement.Generate(this, sizeFigure);
                }
                else
                {
                    float sizeFigure = Mathf.Clamp(TrueSize - Random.Range(1, colOfFigures + 1) * LevelsSizeOffset[(int)LevelOut], 0.5f * MinMaxSize.x, MinMaxSize.y);
                    sizeFigure = Mathf.Lerp(sizeFigure, TrueSize, ((MainLevel - 5.0f) / 10.0f));
                    FigureGameElement.Generate(this, sizeFigure);
                }
            }
        }

        colOfFigures = Random.Range(0, 3);
        for (int i = 0; i < colOfFigures; i++)
        {
            GameObject newFigure = Instantiate(_gameElementPrefab, _gameElementContainerBodyChild);
            newFigure.name = "figure_FAKE_" + i;
            GameElement FigureGameElement = newFigure.GetComponent <GameElement>();

            float sizeFigure = Mathf.Clamp(TrueSize - Random.Range(1, colOfFigures + 1) * LevelsSizeOffset[(int)LevelOut], 0.25f * MinMaxSize.x, MinMaxSize.y);
            FigureGameElement.Generate(this, sizeFigure);
        }

        GameObject newArea = Instantiate(_gameAreaPrefab, _gameAreaContainerChild);

        newArea.transform.localPosition = Vector3.zero;
        newArea.transform.localScale    = Vector3.one * TrueSize;

        if (MainLevel >= 4)
        {
            newArea.transform.Rotate(Vector3.forward * Random.Range(0, 360));
        }


        _trueVariantOfElement.gameObject.transform.SetAsLastSibling();
    }