示例#1
0
 public void SoftDrop()
 {
     if (currentBlock == null || landed)
     {
         return;
     }
     moveDelta = MoveDelda.SoftDrop;
 }
示例#2
0
 public void NormalDrop()
 {
     if (currentBlock == null || landed)
     {
         return;
     }
     moveDelta = MoveDelda.Normal;
 }
示例#3
0
    public void HoldBlock()
    {
        if (currentBlock == null)
        {
            return;
        }

        if (holdedThisTurn)
        {
            return;
        }

        originSize = currentBlock.transform.localScale;

        if (holded != null)
        {
            var tmp = currentBlock;
            currentBlock = holded;
            holded       = tmp;

            currentBlock.transform.position   = new Vector3(Tetris.Width / 2, Tetris.Height);
            currentBlock.transform.localScale = originSize;

            DestroyPreview();
            InitPreview();
            UpdatePreview();
        }
        else
        {
            DestroyPreview();
            holded = currentBlock;
            NextBlock();
        }

        vfx?.PlayClip(SV.ClipHold);

        // reset block state
        moveDelta = MoveDelda.Normal;

        holdedThisTurn = true;
        if (holded is BlockO || holded is BlockI)
        {
            holded.transform.position = new Vector3(holdedViewPosX - holdedViewPosOffset, holdedViewPosY, 0);
        }
        else
        {
            holded.transform.position = new Vector3(holdedViewPosX, holdedViewPosY, 0);
        }
        holded.transform.localScale = new Vector3(sizeScale, sizeScale);
        holded.transform.rotation   = Quaternion.Euler(0, 0, 0);
        holded.ResetState();
    }
示例#4
0
    public void Fall(float deltaTime)
    {
        if (gameOver)
        {
            return;
        }

        time += deltaTime;
        OnTimeChanged?.Invoke(time);

        if (currentBlock == null)
        {
            return;
        }

        if (!landed)
        {
            if (!isLanding)
            {
                if (lastFallTime >= FallDeltaTime)
                {
                    isLanding    = !currentBlock.MoveDown();
                    lastFallTime = 0;
                }
                else
                {
                    lastFallTime += deltaTime;
                }
            }
            else
            {
                if (lastWaitTime >= waitLandTime)
                {
                    landed       = true;
                    lastWaitTime = 0;
                    vfx?.PlayClip(SV.ClipSoftDrop);
                }
                else
                {
                    isLanding     = !currentBlock.MoveDown();
                    lastWaitTime += Time.deltaTime;
                }
            }
        }
        else
        {
            // trigger vfx before check(), because the currentBlock reference has been cleared after check() method.
            vfx?.PlayClip(SV.ClipLanding);

            DestroyPreview();

            AddToGrid();

            if (gameOver)
            {
                return;
            }

            Check();

            moveDelta = MoveDelda.Normal;
            isLanding = false;
            landed    = false;
        }
    }