コード例 #1
0
        private void Kill()
        {
            _deadBlocks.AddRange(_activeTetromino.GetBlocks());

            Blow();

            SetRandomActiveTetromino();
            DrawBoard();
        }
コード例 #2
0
    private void IntegrateBlocks()
    {
        foreach (var block in _currentTetromino.GetBlocks())
        {
            var blockTransform = block.transform;
            var blockPosition  = Vector2Int.FloorToInt(blockTransform.position);

            blockTransform.SetParent(transform);

            _gridCells[blockPosition.x, blockPosition.y].Fill(block);
        }
    }
コード例 #3
0
        private bool WillCollide(Tetromino tetromino, Position newPosition)
        {
            var blocks     = tetromino.GetBlocks().ToList();
            var deadBlocks = false;

            if (_deadBlocks.Count > 0)
            {
                deadBlocks = _deadBlocks.Any(db => blocks.Any(b => db.Position == b.Position + newPosition));
            }

            var bounds = blocks.Any(b => IsOutOfBoardBounds(b.Position + newPosition));

            return(bounds || deadBlocks);
        }
コード例 #4
0
    void Update()
    {
        if (currentTetromino == null) //the tetromino is never generated on its own, it is cloned from the next tetromino
        {
            StopAllCoroutines();
            currentTetromino = TetrominoControls.cloneTetromino(nextTetromino, field);
            TetrominoControls.CreateGhost(currentTetromino);

            blockControl.blk_cnj_clear(nextTetromino.GetBlocks());
            nextTetromino = TetrominoControls.createTetromino(next);

            StartCoroutine(goDown());
            changeColor(currentTetromino.GetBlocks());
        }
        if (Input.GetKeyDown("d")) // Moves to the right
        {
            if (blockControl.blk_cnj_foreach(blockControl.blk_solo_checkRight, currentTetromino.GetBlocks(), 0))
            {
                blockControl.blk_cnj_foreach(blockControl.blk_solo_moveRight, currentTetromino.GetBlocks(), 0);
                currentTetromino.SetLocation(new Vector2Int(1, 0));
                TetrominoControls.CreateGhost(currentTetromino);
            }
        }
        if (Input.GetKeyDown("a"))// Moves to the left
        {
            if (blockControl.blk_cnj_foreach(blockControl.blk_solo_checkLeft, currentTetromino.GetBlocks(), 0))
            {
                blockControl.blk_cnj_foreach(blockControl.blk_solo_moveLeft, currentTetromino.GetBlocks(), 0);
                currentTetromino.SetLocation(new Vector2Int(-1, 0));
                TetrominoControls.CreateGhost(currentTetromino);
            }
        }
        if (Input.GetKeyDown("s"))// Moves Down
        {
            if (currentTetromino != null)
            {
                StopAllCoroutines();
                tick = 0.05f;
                StartCoroutine(goDown());
            }
        }
        if (Input.GetKeyUp("s"))// Moves Down
        {
            StopAllCoroutines();
            tick = 1f;
            StartCoroutine(goDown());
        }
        if (Input.GetKeyDown("w"))
        {
            rotation();
            TetrominoControls.CreateGhost(currentTetromino);
        }
        if (Input.GetKeyDown("f"))
        {
            TetrominoControls.fitPiece(currentTetromino, currentTetromino.GetField());
            UiControl.scr_add(score, 36);
            checkDown(currentTetromino);
        }
        if (Input.GetKeyDown("c") && recentlyChanged == false)
        {
            Tetromino cloneAux = null;

            if (holdTetromino != null)
            {
                cloneAux = holdTetromino;
                blockControl.blk_cnj_clear(holdTetromino.GetBlocks());
            }

            holdTetromino = TetrominoControls.cloneTetromino(currentTetromino, hold);
            blockControl.blk_cnj_clear(currentTetromino.GetBlocks());
            blockControl.blk_cnj_clear(currentTetromino.GetGhost().GetBlocks());
            currentTetromino = TetrominoControls.cloneTetromino(cloneAux, field);
            TetrominoControls.CreateGhost(currentTetromino);
            recentlyChanged = true;
        }
    }