/// <summary> /// Handles minimino movement and input, as well as scoring. /// </summary> void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } if (_stopped) { return; } if (_current == null) { DequeueTetrimino(); return; } if (_timeLeft > 0) { _timeLeft -= Time.deltaTime; } else { bool isCurrentAtBottom = _current.Move(); // in the case that isCurrentAtBottom = false and _currentAtBottom = true, // the player moved the tetrimino along the bottom of a row. if (isCurrentAtBottom && _currentAtBottom) { _current.ToSingleMinos(); int linesCleared = CheckLines(); if (linesCleared > 0) { _score += (_combo == 0 ? 1 : Constants.ComboMultiplier * _combo) * Constants.PointsPerClear * linesCleared; } DequeueTetrimino(); } // keeping this below allows the user to move this tetrimino around the bottom of a row. _currentAtBottom = isCurrentAtBottom; _score += Constants.PointsPerRow; pointsText.text = _score.ToString(); _timeLeft = Constants.TimePerRow; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { if (_currentAtBottom) { _timeLeft = Constants.TimePerRow; } _current.Move(Vector3.left); } if (Input.GetKeyDown(KeyCode.RightArrow)) { if (_currentAtBottom) { _timeLeft = Constants.TimePerRow; } _current.Move(Vector3.right); } if (Input.GetKeyDown(KeyCode.DownArrow)) { _timeLeft = -1; } // "slam" -- puts the tetrimino all the way to the bottom. if (Input.GetKeyDown(KeyCode.Space)) { int rowsDropped = 0; while (!_current.Move()) { rowsDropped++; } _score += rowsDropped * Constants.DropLineMultiplier * Constants.PointsPerRow; pointsText.text = _score.ToString(); _currentAtBottom = true; _timeLeft = -1; } // rotation creates a new GameObject, so we reassign current. if (Input.GetKeyDown(KeyCode.RightShift)) { _current = _current.RotateClockwise().GetComponent <Tetrimino>(); } if (Input.GetKeyDown(KeyCode.Slash)) { _current = _current.RotateCounterClockwise().GetComponent <Tetrimino>(); } }