Ejemplo n.º 1
0
    void Hold()
    {
        canHold = false;
        TetrominoBase toHold = currentTetromino;

        currentTetromino.CancelLock();
        currentTetromino.transform.SetParent(holdPosition);
        currentTetromino.transform.position = (
            holdPosition.position - (Vector3)currentTetromino.centerOffset
            );
        currentTetromino.ResetRotation();
        currentTetromino.ghost.gameObject.SetActive(false);

        if (holdTetromino)
        {
            holdTetromino.transform.SetParent(null);
            holdTetromino.transform.position = new Vector3(
                instance.dimensions.x / 2 - 1,
                instance.dimensions.y
                );
            holdTetromino.ResetRotation();
            currentTetromino = holdTetromino;
        }
        else
        {
            SpawnTetromino();
        }

        holdTetromino = toHold;
    }
Ejemplo n.º 2
0
    public static bool ValidPosition(
        TetrominoBase tetromino
        )
    {
        foreach (Block block in tetromino.blocks)
        {
            if (
                (
                    tetromino.isLanded &&
                    block.matrixPosition.y >= instance.dimensions.y
                ) ||
                block.matrixPosition.x < 0 ||
                block.matrixPosition.x >= instance.dimensions.x ||
                block.matrixPosition.y < 0 ||
                (
                    block.matrixPosition.y < instance.dimensions.y &&
                    matrix[
                        block.matrixPosition.x,
                        block.matrixPosition.y
                    ]
                )
                )
            {
                return(false);
            }
        }

        return(true);
    }
Ejemplo n.º 3
0
    public TetrominoBase GetNextTetromino()
    {
        TetrominoBase t = queueNow.Dequeue();

        queueNow.Enqueue(RandomTetromino());
        UpdatePos();
        t.Initial();
        return(t);
    }
Ejemplo n.º 4
0
        public void Reside(TetrominoBase tetromino, int floorIndex, int roomIndex)
        {
            var data = tetromino.GetUnderlyingDataUpward();

            foreach (var item in data)
            {
                if (floorIndex > -1)
                {
                    Reside(item, tetromino.ForeColor, floorIndex, roomIndex);
                }
                floorIndex++;
            }
        }
Ejemplo n.º 5
0
    private TetrominoBase RandomTetromino()
    {
        TetrominoBase tb = null;
        int           i  = UnityEngine.Random.Range(0, DataManager.Instance.tetrominoSpriteName.Count - 1);

        foreach (var t in DataManager.Instance.tetrominoSpriteName.Keys)
        {
            if (i == 0)
            {
                tb = PoolManager.Instance.TetrominoPop(t);
                tb.Initial();
                tb.InitialOnQueue();
            }
            i--;
        }
        return(tb);
    }
Ejemplo n.º 6
0
    void SetNextTetramino()
    {
        nextTetromino = instance.bag[0];
        instance.bag.RemoveAt(0);

        nextTetromino = Instantiate(
            nextTetromino.gameObject,
            nextPosition.position -
            (Vector3)nextTetromino.centerOffset,
            nextPosition.localRotation,
            nextPosition
            ).GetComponent <TetrominoBase>();

        nextTetromino.transform.eulerAngles = nextPosition.eulerAngles;

        if (instance.bag.Count == 0)
        {
            instance.FillBag();
        }
    }