void InitBlockTeamPos(BlockTeam bt) { int iX = (this.GetWidth() - bt.GetWidth()) / 2; int iY = 0 - bt.GetTopOffset(); bt.SetPos(iX, iY); }
void EnqueueBlockTeam() { int iIndex = m_Rand.Next(0, m_BlockTeamType.Count); Type type = m_BlockTeamType[iIndex]; BlockTeam bt = Activator.CreateInstance(type) as BlockTeam; m_BlockTeamQueue.Enqueue(bt); }
bool IsCollide(BlockTeam bt, BT_Move_Type eBTMove = BT_Move_Type.BTM_None) { if (bt == null) { return(true); } Vector2Int vPos = bt.GetPos(); int iX = vPos.x; int iY = vPos.y; switch (eBTMove) { case BT_Move_Type.BTM_Left: iX = vPos.x - 1; break; case BT_Move_Type.BTM_Right: iX = vPos.x + 1; break; case BT_Move_Type.BTM_Down: iY = vPos.y + 1; break; default: break; } for (int i = 0; i < bt.GetWidth(); i++) { for (int j = 0; j < bt.GetHeight(); j++) { int iBTValue, iWallValue; if (bt.GetValue(i, j, out iBTValue)) { if (iBTValue != 0) { if (GetValue(i + iX, j + iY, out iWallValue)) { if (iWallValue != 0) { return(true); } } else { return(true); } } } else { return(true); } } } return(false); }
public void OnRight() { BlockTeam bt = m_CurBlockTeam; if (!IsCollide(bt, BT_Move_Type.BTM_Right)) { bt.MoveRight(); } }
public void OnLeft() { BlockTeam bt = m_CurBlockTeam; if (!IsCollide(bt, BT_Move_Type.BTM_Left)) { bt.MoveLeft(); } }
public virtual BlockTeam Clone() { BlockTeam bt = Activator.CreateInstance(this.GetType()) as BlockTeam; bt.SetPos(this.GetPos().x, this.GetPos().y); bt.SetRotIndex(m_iIndexPos); return(bt); }
void NewBlockTeam() { EnqueueBlockTeam(); BlockTeam bt = m_BlockTeamQueue.Dequeue(); InitBlockTeamPos(bt); m_CurBlockTeam = bt; m_DropDownBT = m_CurBlockTeam.Clone(); m_CurBlockTeam.OnBlockMove += OnCurBlockTeamUpdate; m_CurBlockTeam.OnBlockRot += OnCurBlockTeamUpdate; OnCurBlockTeamUpdate(); }
void Reset() { for (int i = 0; i < m_WallData.GetLength(0); i++) { for (int j = 0; j < m_WallData.GetLength(1); j++) { m_WallData[i, j] = 0; } } m_CurBlockTeam = null; m_DropDownBT = null; m_BlockTeamQueue.Clear(); }
public void OnDown() { BlockTeam bt = m_CurBlockTeam; if (!IsCollide(bt, BT_Move_Type.BTM_Down)) { bt.MoveDown(); } else { Merge(bt); m_CurBlockTeam = null; m_DropDownBT = null; } }
void Merge(BlockTeam bt) { Vector2Int vPos = bt.GetPos(); for (int i = 0; i < bt.GetWidth(); i++) { for (int j = 0; j < bt.GetHeight(); j++) { int iBTValue; if (bt.GetValue(i, j, out iBTValue)) { if (iBTValue == 1) { SetValue(i + vPos.x, j + vPos.y, iBTValue); } } } } }
public void OnRot() { if (m_CurBlockTeam == null) { return; } BlockTeam bt = m_CurBlockTeam.Clone(); bt.Rot(); if (!IsCollide(bt, BT_Move_Type.BTM_None)) { m_CurBlockTeam.Rot(); } else { BlockTeam btLeft = bt; BlockTeam btRight = bt.Clone(); for (int i = 0; i < bt.GetBlockWidth(); i++) { btLeft.MoveLeft(); if (!IsCollide(btLeft, BT_Move_Type.BTM_None)) { m_CurBlockTeam.Rot(); for (int j = i; j >= 0; j--) { m_CurBlockTeam.MoveLeft(); } break; } btRight.MoveRight(); if (!IsCollide(btRight, BT_Move_Type.BTM_None)) { m_CurBlockTeam.Rot(); for (int j = i; j >= 0; j--) { m_CurBlockTeam.MoveRight(); } break; } } } }
public void CopyTo(BlockTeam bt) { bt.SetPos(GetPos().x, GetPos().y); bt.SetRotIndex(m_iIndexPos); }