예제 #1
0
 // Update display blocks and load previous settings
 void Start()
 {
     BlockUpdater.updateSprites();
     BlockUpdater.updateColors();
     dynamicColor.isOn = Settings.dynamicColor;
     moveDelay.value   = Settings.moveDelay * 100;
     moveSpeed.value   = Settings.moveSpeed * 100;
     fullScreen.isOn   = Screen.fullScreen;
 }
예제 #2
0
 // Makes the screen flash rapidly
 private IEnumerator flashRoutine()
 {
     uint[] pallet = BlockUpdater.currentPallet();
     for (uint j = 0; j < numFlashes; j++)
     {
         Color32 c = flashColors.Dequeue();
         materials[0].SetColor("_Color", Color32.Lerp(Hex2Color(pallet[0]), c, flashLerpRatio));
         flashColors.Enqueue(c);
         yield return(new WaitForSeconds(flashDelay));
     }
     materials[0].SetColor("_Color", Hex2Color(pallet[0]));
 }
예제 #3
0
 public void changeBlockSprite(bool next)
 {
     if (next)
     {
         BlockUpdater.nextSprite();
     }
     else
     {
         BlockUpdater.prevSprite();
     }
     BlockUpdater.updateSprites();
 }
예제 #4
0
 public void changeBlockColor(bool next)
 {
     if (next)
     {
         BlockUpdater.nextColorPallet();
     }
     else
     {
         BlockUpdater.prevColorPallet();
     }
     BlockUpdater.updateColors();
 }
예제 #5
0
    // Shuffle Tetromino colors on first awake and load keybinds
    private void Awake()
    {
        // First awake. Not sure if this is necessary but just in case
        if (Time.time == 0)
        {
            BlockUpdater.shuffleColorPallet();
            Settings.fullScreen = Screen.fullScreen;  // Just set the settings to whatever the screen starts as
        }


        BlockUpdater.updateColors();
        BlockUpdater.updateSprites();

        //if (!false) {                // Check for saved player prefs here?
        Settings.keyBinds = new Dictionary <Board.PlayerInput, KeyCode>(Settings.defaultKeybinds);
        //}

        particleEffectMain            = particleEffect.main;
        particleEffectMain.startColor = new ParticleSystem.MinMaxGradient(titleText.fontSharedMaterial.GetColor(ShaderUtilities.ID_FaceColor));
    }
예제 #6
0
    // Lerps from one color to another in a smooth animation
    private IEnumerator fadeColorPalletRoutine( )
    {
        uint[] pallet = BlockUpdater.currentPallet();

        float h, s, v;

        Color.RGBToHSV(Hex2Color(pallet[0]), out h, out s, out v);

        Color32 fontColor = Color.HSVToRGB(h, s * 3, v * 3);

        // Save Old Colors for Lerp
        Color32[] oldColors = new Color32[materials.Length];
        for (int i = 0; i < oldColors.Length; i++)
        {
            oldColors[i] = materials[i].color;
        }
        Color32 oldFontColor = uiFontPrefab.fontSharedMaterial.GetColor(ShaderUtilities.ID_FaceColor);

        // Slowly transition
        float lerp = 0;

        while (lerp <= 1)
        {
            uiFontPrefab.fontSharedMaterial.SetColor(ShaderUtilities.ID_FaceColor, Color32.Lerp(oldFontColor, fontColor, lerp));
            uiFontPrefab.fontSharedMaterial.SetColor(ShaderUtilities.ID_OutlineColor, Color32.Lerp(oldFontColor, fontColor, lerp));
            for (int i = 0; i < materials.Length; i++)
            {
                materials[i].SetColor("_Color", Color32.Lerp(oldColors[i], Hex2Color(pallet[i]), lerp));
            }

            lerp += dLerpRatio;
            yield return(new WaitForSeconds(colorTransitionDelay));
        }
        //

        BlockUpdater.updateColors();
    }
예제 #7
0
    /*
     * Color
     */

    public void fadeToNextColorPallet()
    {
        BlockUpdater.nextColorPallet();

        StartCoroutine(fadeColorPalletRoutine());
    }
예제 #8
0
파일: Board.cs 프로젝트: e-sanderson/TetrEs
    // Main game loop
    void Update()
    {
        if (paused && !Input.GetKeyDown(keyBinds[PlayerInput.PAUSE]) || gameOptionsMenu.active || controlsMenu.active)
        {
            return;
        }
        if (linesToClear.Count == 0 && !gameOver)
        {
            // Spawn and check GameOver if last piece landed
            if (activePiece == null)
            {
                if (lockDelay <= 0.1f)
                {
                    if (fallTimer.time < fallDelay)
                    {
                        return;
                    }
                }

                // Check GameOver
                gameOver = checkGameOver();
                if (gameOver)
                {
                    Debug.Log("Game Over");
                    StartCoroutine(gameOverRoutine());
                    return;
                }

                // Spawn next piece
                activePiece = spawner.nextTetromino();
                if (!Settings.showGhost)
                {
                    activePiece.setGhostVisible(false);
                }
                resetPiece();
            }

            // Player input
            successfulMovement = false;
            input = getPlayerInput();

            switch (input)
            {
            case PlayerInput.NONE:
                moveRepeatTimer.reset();
                break;

            case PlayerInput.DROP:
                Vector3 prev = activePiece.centerPosition();
                activePiece.moveToGhostPosition();
                Vector3 cur = activePiece.centerPosition();
                hardDrop = (uint)Mathf.Round(prev.y - cur.y);
                graphics.tetrominoBeam(prev, cur, activePiece);
                lastSuccessfulMove = PlayerInput.DROP;
                moveRepeatTimer.reset();
                break;

            case PlayerInput.SWAP:
                activePiece = hold.swap(activePiece);
                if (activePiece == null)
                {
                    return;
                }
                resetPiece();
                moveRepeatTimer.reset();
                BlockUpdater.updateSprites();     // Held ghost could have not been updated when there was a change
                break;

            default:
                if (moveRepeatTimer.time == 0)
                {
                    // Just move, first press
                    successfulMovement = handleMovement(input);
                    if (successfulMovement)
                    {
                        lastSuccessfulMove = input;
                        moveTimer.reset();
                    }
                    moveRepeatTimer.update();
                }
                else if (moveRepeatTimer.time >= Settings.moveDelay)
                {
                    // Only move if delay has been passed and only every so often
                    if (moveTimer.time > Settings.moveSpeed)
                    {
                        successfulMovement = handleMovement(input);
                        if (successfulMovement)
                        {
                            lastSuccessfulMove = input;
                            moveTimer.reset();
                        }
                    }
                }
                else
                {
                    moveRepeatTimer.update();
                }
                break;
            }

            // Move piece down or decrement lock timer
            if (!pieceLanded())
            {
                if (fallTimer.time > (softDropping ? Settings.moveSpeed / 4 : fallDelay))
                {
                    // Down
                    activePiece.translateVertical(-1);
                    lastSuccessfulMove = PlayerInput.NONE;
                    fallTimer.reset();

                    softDrop = softDropping ? softDrop + 1 : 0;
                }
                else
                {
                    softDrop = softDropping ? softDrop : 0;
                }
            }
            else
            {
                // Reset timers on successful move if appropriate
                if (successfulMovement)
                {
                    if (lockResetCount < lockResetCap)
                    {
                        lockTimer.reset();
                        lockResetCount++;
                    }
                    else
                    {
                        lockTimer.update();
                    }
                }
                else
                {
                    lockTimer.update();
                }
            }


            // Lock piece, clear lines, update score
            if ((pieceLanded() && lockTimer.time > lockDelay) || input == PlayerInput.DROP)
            {
                // Note tSpin. Must be done here before piece container is destroyed.
                tspin = isTspin(lastSuccessfulMove);

                // Lock piece, release blocks, any held piece
                lockPiece();
                hold.reset();
                activePiece.pulseDetachMinosAndDestroy();
                activePiece = null;

                // Clear lines
                checkLineClears();

                // Update Score and Level
                bool levelUp = score.updateScore((uint)linesToClear.Count, softDrop, hardDrop, tspin);
                if (levelUp)
                {
                    if (Settings.dynamicColor)
                    {
                        graphics.fadeToNextColorPallet();
                    }

                    fallDelay = calculateFallRate(score.level);
                }

                if (linesToClear.Count > 0)
                {
                    clearLines();
                }
            }
        }
    }