Ejemplo n.º 1
0
        public void HoldPiece()
        {
            if (_canHold)
            {
                _activePiece.Despawn();

                if (_heldPiece == null)
                {
                    _heldPiece = _activePiece;
                    SpawnNextPiece();
                }
                else
                {
                    Tetrimino tempPiece = _heldPiece;
                    _heldPiece   = _activePiece;
                    _activePiece = tempPiece;
                    _activePiece.Spawn();
                    _activeOutline = GeneratePiece(_activePiece.GetBlockValue());
                }

                _holdSound.Play();
            }

            _canHold = false;
        }
Ejemplo n.º 2
0
        public void LegalMoveLeftRight(int moveVal)
        {
            // Copy Active Piece And Simulate Move
            Tetrimino copy = GeneratePiece(_activePiece.GetBlockValue());

            _activePiece.MakeCopy(copy);
            copy.MoveLeftRight(moveVal);

            // If In Bounds, Perform Actual Move
            if (copy.IsInBounds(_tower))
            {
                _activePiece.MoveLeftRight(moveVal);
            }
        }
Ejemplo n.º 3
0
        public void DrawPreviewImage(GameData data, Sprite pieceImg, Tetrimino piece)
        {
            if (piece != null)
            {
                int textureOffset = 0;

                switch (piece.GetBlockValue())
                {
                case BlockValue.IShape:
                    textureOffset = 0;
                    break;

                case BlockValue.LShape:
                    textureOffset = 1;
                    break;

                case BlockValue.JShape:
                    textureOffset = 2;
                    break;

                case BlockValue.SShape:
                    textureOffset = 3;
                    break;

                case BlockValue.ZShape:
                    textureOffset = 4;
                    break;

                case BlockValue.TShape:
                    textureOffset = 5;
                    break;

                case BlockValue.OShape:
                    textureOffset = 6;
                    break;
                }

                pieceImg.TextureRect = new IntRect(textureOffset * Constants.PreviewImageSize, 0, Constants.PreviewImageSize, Constants.PreviewImageSize);
                data.Window.Draw(pieceImg);
            }
        }
Ejemplo n.º 4
0
        public bool CheckForMoveCollision(Tetrimino piece, int moveVal)
        {
            // Copy Active Piece And Simulate Move
            Tetrimino copy = GeneratePiece(piece.GetBlockValue());

            piece.MakeCopy(copy);
            copy.MoveUpDown(moveVal);

            // Check If Block Collides With Pile
            if (_tower.CheckPieceOverlap(copy))
            {
                return(true);
            }

            // Check If Block Collides With Bottom
            if (!copy.IsInBounds(_tower))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public void SpawnNextPiece()
        {
            if (_randomPieceIndex > 6)
            {
                _randomPieceIndex = 0;
                ShuffleRandomPieceBag();
            }

            if (_nextPiece == null)
            {
                _nextPiece = GeneratePiece(_randomPieceBag[_randomPieceIndex]);
                _randomPieceIndex++;
            }

            _activePiece = _nextPiece;
            _activePiece.Spawn();
            _nextPiece = GeneratePiece(_randomPieceBag[_randomPieceIndex]);
            _randomPieceIndex++;

            // Create Piece For Outline
            _activeOutline = GeneratePiece(_activePiece.GetBlockValue());
        }
Ejemplo n.º 6
0
        public void TryRotate(Tetrimino piece, bool clockwise)
        {
            // Copy Active Piece And Simulate Rotation
            Tetrimino copy = GeneratePiece(piece.GetBlockValue());

            piece.MakeCopy(copy);
            copy.Rotate(clockwise);

            // If Everything Looks Good, Rotate Active Piece
            if (copy.IsInBounds(_tower))
            {
                piece.Rotate(clockwise);
            }
            // If It Doesn't, Try To Apply An Offset To The Rotation
            else
            {
                int rotationOffsetValue = -1;

                while (!copy.IsInBounds(_tower))
                {
                    rotationOffsetValue++;

                    switch (rotationOffsetValue)
                    {
                    case 0:
                        // 1 Space Left
                        copy.MoveLeftRight(-1);
                        break;

                    case 1:
                        // 2 Spaces Left
                        copy.MoveLeftRight(-1);
                        break;

                    case 2:
                        // 1 Space Right
                        copy.MoveLeftRight(3);
                        break;

                    case 3:
                        // 2 Spaces Right
                        copy.MoveLeftRight(1);
                        break;

                    case 4:
                        // 1 Space Down
                        copy.MoveLeftRight(-2);
                        copy.MoveUpDown(1);
                        break;

                    case 5:
                        // 2 Spaces Down
                        copy.MoveUpDown(1);
                        break;

                    default:
                        return;
                    }
                }

                // Rotate And Apply Offset
                piece.Rotate(clockwise);
                switch (rotationOffsetValue)
                {
                case 0:
                    piece.MoveLeftRight(-1);
                    break;

                case 1:
                    piece.MoveLeftRight(-2);
                    break;

                case 2:
                    piece.MoveLeftRight(1);
                    break;

                case 3:
                    piece.MoveLeftRight(2);
                    break;

                case 4:
                    piece.MoveUpDown(1);
                    break;

                case 5:
                    piece.MoveUpDown(2);
                    break;
                }
            }

            _rotateSound.Play();
        }