Beispiel #1
0
        private IEnumerator ControlTetromino()
        {
            float gravityInterval = _levelController.GravityInterval;
            float elapsedTime     = 0f;

            while (elapsedTime < gravityInterval)
            {
                if (_inputController.Pause)
                {
                    BoardView.UpdateView(BoardModel, _blocks);

                    IsPaused = true;
                    _pausePanel.SetActive(true);
                }

                if (!IsPaused)
                {
                    // if drop hard is activated, we skip control
                    if (_inputController.DropHard)
                    {
                        yield break;
                    }

                    if (_inputController.HoldPiece && !_isHoldPiece)
                    {
                        yield break;
                    }

                    if (_inputController.DropSoft)
                    {
                        gravityInterval = _levelController.DropSoftGravityInterval;
                    }

                    ClearTetromino(_ghostTetromino);
                    ClearTetromino(_currentTetromino);

                    if (_inputController.MoveLeft)
                    {
                        _currentTetromino.CurrentColumn -= 1;

                        if (!CanPlaceTetromino(_currentTetromino))
                        {
                            // Disable previous move
                            _currentTetromino.CurrentColumn += 1;
                        }
                        else
                        {
                            _soundController.PlayMoveTetromino();
                        }
                    }

                    if (_inputController.MoveRight)
                    {
                        _currentTetromino.CurrentColumn += 1;
                        if (!CanPlaceTetromino(_currentTetromino))
                        {
                            // Disable previous move
                            _currentTetromino.CurrentColumn -= 1;
                        }
                        else
                        {
                            _soundController.PlayMoveTetromino();
                        }
                    }

                    if (_inputController.RotateClockwise)
                    {
                        _currentTetromino.Rotation += 1;
                        if (!CanPlaceTetrominoWithWallKick(_currentTetromino))
                        {
                            // Disable previous rotation
                            _currentTetromino.Rotation -= 1;
                        }
                        else if (_currentTetromino.MaxRotations > 1)
                        {
                            _soundController.PlayRotateTetromino();
                        }
                    }

                    if (_inputController.RotateCounterClockwise)
                    {
                        _currentTetromino.Rotation -= 1;
                        if (!CanPlaceTetrominoWithWallKick(_currentTetromino))
                        {
                            // Disable previous rotation
                            _currentTetromino.Rotation += 1;
                        }
                        else if (_currentTetromino.MaxRotations > 1)
                        {
                            _soundController.PlayRotateTetromino();
                        }
                    }

                    elapsedTime = Mathf.MoveTowards(elapsedTime, gravityInterval, Time.deltaTime);

                    UpdateGhostTetromino(_currentTetromino, _ghostTetromino);
                    DrawGhostTetromino(_ghostTetromino);
                    DrawTetromino(_currentTetromino);
                }

                yield return(null);
            }
        }