Example #1
0
 /// <summary>
 /// テトロミノが空中にある?
 /// </summary>
 public bool IsTetrominoFlying()
 {
     foreach (TRPanel panel in m_TetrominoParts)
     {
         TRPanelBlock block = panel.Block.GetLink(PlayAreaBlock.Dir.Down) as TRPanelBlock;
         if (block == null || block.AttachedPanel != null)
         {
             return(false);
         }
     }
     return(true);
 }
Example #2
0
    /// <summary>
    /// 指定方向に連続した空ブロック数を取得
    /// </summary>
    public int GetEmptyBlockCountDir(Dir dir)
    {
        int count = 0;

        if (AttachedPanel == null)
        {
            count = 1;
            TRPanelBlock block = this;
            while ((block = block.GetLink(dir) as TRPanelBlock) != null && block.AttachedPanel == null)
            {
                ++count;
            }
        }
        return(count);
    }
Example #3
0
    /// <summary>
    /// 行追加
    /// </summary>
    private void AddLine(int count, bool empty, int emptyRow = -1)
    {
        // ブロック生成
        for (int i = 0; i < count; i++)
        {
            TRPanelBlock[] line = new TRPanelBlock[Width];
            for (int row = 0; row < line.Length; row++)
            {
                line[row] = new TRPanelBlock();
                line[row].BaseTransform = m_BlockParent.transform;

                Vector3 pos = Vector3.zero;
                pos.x = row * BlockSize - (m_Size.x - BlockSize) / 2f;
                pos.y = -(m_Lines.Count * BlockSize + BlockHalfSize);
                line[row].LocalPosition = pos;

                // 連結
                if (row > 0)
                {
                    line[row].SetLink(line[row - 1], PlayAreaBlock.Dir.Left);
                    line[row - 1].SetLink(line[row], PlayAreaBlock.Dir.Right);
                }
                if (m_Lines.Count > 0)
                {
                    line[row].SetLink(m_Lines[m_Lines.Count - 1][row], PlayAreaBlock.Dir.Up);
                    m_Lines[m_Lines.Count - 1][row].SetLink(line[row], PlayAreaBlock.Dir.Down);
                }

                // パネル生成
                if (!empty && row != emptyRow)
                {
                    TRPanel panel;
                    // パネル再利用
                    if (m_UnusedPanels.Count > 0)
                    {
                        panel = m_UnusedPanels[0];
                        m_UnusedPanels.RemoveAt(0);
                    }
                    // パネル生成
                    else
                    {
                        panel = Instantiate(PanelTemplate).GetComponent <TRPanel>();
                        panel.transform.SetParent(m_BlockParent.transform);
                    }
                    panel.Initialize(this, Color.gray);
                    line[row].Attach(panel, true);
                }
            }
            m_Lines.Add(line);
        }

        // 座標を調整
        int dif = m_Lines.Count - Height;

        if (dif > 0)
        {
            foreach (TRPanelBlock[] line in m_Lines)
            {
                foreach (TRPanelBlock block in line)
                {
                    block.LocalPosition += Vector3.up * BlockSize * dif;
                    if (block.AttachedPanel != null)
                    {
                        block.AttachedPanel.transform.localPosition += Vector3.up * BlockSize * dif;
                    }
                    if (block.ReservedPanel != null)
                    {
                        block.ReservedPanel.transform.localPosition += Vector3.up * BlockSize * dif;
                    }
                }
            }

            // 範囲外の分を破棄
            for (int i = 0; i < dif; i++)
            {
                foreach (TRPanelBlock block in m_Lines[i])
                {
                    if (block.AttachedPanel != null)
                    {
                        block.AttachedPanel.Deactivate();
                        RemovePanel(block.AttachedPanel);
                    }
                    else if (block.ReservedPanel != null)
                    {
                        block.ReservedPanel.Deactivate();
                        RemovePanel(block.ReservedPanel);
                    }
                }
                m_Lines.RemoveAt(0);
            }
            foreach (TRPanelBlock block in m_Lines[0])
            {
                block.SetLink(null, PlayAreaBlock.Dir.Up);
            }
        }
    }
Example #4
0
    /// <summary>
    /// テトロミノ姿勢更新
    /// </summary>
    public bool UpdateTetromino(bool apply = true)
    {
        List <int> reserveBlocks = new List <int>();

        for (int y = 0; y < m_Tetromino.ShapeSize; y++)
        {
            for (int x = 0; x < m_Tetromino.ShapeSize; x++)
            {
                // パネルあり
                if (m_Tetromino.GetShapeGrid(x, y))
                {
                    // はまる位置
                    Vector2i grid = m_Tetromino.GridPosition - m_Tetromino.GetAxisGrid() + new Vector2i(x, y);

                    // 範囲外
                    if (grid.x < 0 || grid.x >= Width || grid.y < 0 || grid.y >= Height)
                    {
                        return(false);
                    }

                    // はまる予定のブロック
                    TRPanelBlock block = m_Lines[grid.y][grid.x];

                    // 既に埋まってる
                    if (block != null && block.AttachedPanel != null)
                    {
                        return(false);
                    }

                    // ブロック予約
                    reserveBlocks.Add(grid.y * Width + grid.x);
                }
            }
        }

        if (apply)
        {
            // 前回までの予約キャンセル
            foreach (TRPanel parts in m_TetrominoParts)
            {
                m_UnusedPanels.Add(parts);
                parts.Block.CancelReserve();
                parts.Deactivate();
            }
            m_TetrominoParts.Clear();

            for (int i = 0; i < reserveBlocks.Count; i++)
            {
                TRPanel panel;

                // パネル再利用
                if (m_UnusedPanels.Count > 0)
                {
                    panel = m_UnusedPanels[0];
                    m_UnusedPanels.RemoveAt(0);
                }
                // パネル生成
                else
                {
                    panel = Instantiate(PanelTemplate).GetComponent <TRPanel>();
                    panel.transform.SetParent(m_BlockParent.transform, false);
                }

                panel.Initialize(this, m_Tetromino.PanelColor);
                m_TetrominoParts.Add(panel);

                // ブロック予約
                m_Lines[reserveBlocks[i] / Width][reserveBlocks[i] % Width].Reserve(panel, true);
            }
        }

        return(true);
    }
Example #5
0
 /// <summary>
 /// 落下開始
 /// </summary>
 public void BeginFall(TRPanelBlock target)
 {
     Block.Detach();
     target.Attach(this, true);
 }