// 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; }
public void changeBlockSprite(bool next) { if (next) { BlockUpdater.nextSprite(); } else { BlockUpdater.prevSprite(); } BlockUpdater.updateSprites(); }
// 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)); }
// 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(); } } } }