Esempio n. 1
0
    private void AddToGrid()
    {
        bool res = true;

        foreach (Transform child in currentBlock.transform)
        {
            var x = EX.Float2Int(child.transform.position.x);
            var y = EX.Float2Int(child.transform.position.y);

            if (y < Height)
            {
                res = false;
            }

            Grid[x, y] = child;
        }

        // check game over
        if (res)
        {
            OnGameOver?.Invoke();
            gameOver     = true;
            currentBlock = null;
        }
    }
Esempio n. 2
0
 // 1 0 1
 // 0 0 0
 // 1 0 1
 private Vector2Int[] GetPoints()
 {
     return(new Vector2Int[4]
     {
         new Vector2Int(EX.Float2Int(transform.position.x + 1), EX.Float2Int(transform.position.y + 1)),
         new Vector2Int(EX.Float2Int(transform.position.x + 1), EX.Float2Int(transform.position.y - 1)),
         new Vector2Int(EX.Float2Int(transform.position.x - 1), EX.Float2Int(transform.position.y + 1)),
         new Vector2Int(EX.Float2Int(transform.position.x - 1), EX.Float2Int(transform.position.y - 1)),
     });
 }
Esempio n. 3
0
 private bool ValidChild(Vector2 move)
 {
     foreach (Transform child in transform)
     {
         var x = EX.Float2Int(child.position.x + move.x);
         var y = EX.Float2Int(child.position.y + move.y);
         if (!Valid(x, y))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 4
0
    public void NextBlock()
    {
        if (gameOver)
        {
            return;
        }

        currentBlock = m_spawner.NextBlock();

        // check game over
        if (!currentBlock.MoveDown())
        {
            foreach (Transform child in currentBlock.transform)
            {
                var x = EX.Float2Int(child.transform.position.x);
                var y = EX.Float2Int(child.transform.position.y);

                if (Grid[x, y] != null)
                {
                    OnGameOver?.Invoke();
                    gameOver     = true;
                    currentBlock = null;
                    return;
                }
            }
        }

        InitPreview();

        UpdatePreview();

        m_spawner.UpdateNextChainSlot();

        holdedThisTurn = false;

        landedWithRotate = false;

        isTSpin = false;
    }
Esempio n. 5
0
    private void Check()
    {
        // check T-Spin
        if (currentBlock is BlockT blockT)
        {
            isTSpin = blockT.IsTSpin(out isMini) && landedWithRotate;
            Debug.LogFormat("roateted {0}, special {1}", landedWithRotate, isTSpin);
        }

        foreach (Transform child in currentBlock.transform)
        {
            var y = EX.Float2Int(child.transform.position.y);

            if (!m_rows.Contains(y))
            {
                m_rows.Add(y);
            }
        }

        // lock block move
        currentBlock = null;

        for (int i = m_rows.Count - 1; i >= 0; i--)
        {
            if (!HasLine(m_rows[i]))
            {
                m_rows.RemoveAt(i);
            }
            else
            {
                ClearLine(m_rows[i]);

                //OnLineClear?.Invoke(m_rows[i]);
                vfx.VFX_LineClear(m_rows[i]);
            }
        }

        if (m_rows.Count > 0)
        {
            m_rows.Sort();

            // update score, etc.
            UpdateData(m_rows.Count);
            ren++;

            if (ren > 0)
            {
                vfx.UpdateTextRen(ren);
            }

            Saro.Timer.Register(.3f, () =>
            {
                for (int i = m_rows.Count - 1; i >= 0; i--)
                {
                    DownLine(m_rows[i]);
                }

                NextBlock();

                m_rows.Clear();
            }).Start();
        }
        else
        {
            NextBlock();
            m_rows.Clear();

            // clear combo data
            ren = -1;
            vfx.HideTextRen();
        }
    }