Beispiel #1
0
    private void GeneratePiece()
    {
        CurrPiece.Reset(templatePieces[nextPieceTemplateIndex]);
        nextPieceTemplateIndex = Random.Range(0, templatePieces.Length);
        NextPiece.Reset(templatePieces[nextPieceTemplateIndex]);
        EventSystem <TetrisGameEvent, TemplatePiece> .TriggerEvent(TetrisGameEvent.NextPiece,
                                                                   templatePieces[nextPieceTemplateIndex]);

        PiecePos = new Vector2Int(5, 20);
        ComputeProjection();
    }
Beispiel #2
0
    public void RotatePiece()
    {
        CurrPiece.RotateCW();
        if (!ValidBoard(PiecePos))
        {                              //maybe rotation is valid if we shift either left...
            PiecePos += Vector2Int.left;
            if (!ValidBoard(PiecePos)) //...or right
            {
                PiecePos += 2 * Vector2Int.right;
            }

            if (!ValidBoard(PiecePos))
            {//the rotation is invalid, so revert
                PiecePos += Vector2Int.left;
                CurrPiece.RotateCCW();
            }
        }
        ComputeProjection();
    }