// Use this for initialization void Start() { GameObject gc = GameObject.FindGameObjectWithTag("GameController"); m_BG = gc.GetComponent <BoxGenerator>(); Coord2D coord = m_BG.PosToCoord(new Vector2(transform.localPosition.x, transform.localPosition.y)); if (coord.x != -1 && coord.y != -1) { GameObject element = m_BG.GetElementByCoord(coord); if (element != null) { var type = element.GetComponent <BoxElementControl>().m_Type; m_BG.AttachRandomSpecies(element); var count = 1; //尋找同類方塊,加上物種 for (int y = 0; y < m_BG.m_BoxNumH; y++) { for (int x = 0; x < m_BG.m_BoxNumW; x++) { Coord2D targetCoord = new Coord2D(x, y); GameObject target = m_BG.GetElementByCoord(targetCoord); if (target != null) { BoxElementControl bec = target.GetComponent <BoxElementControl>(); if (bec.m_Type == type && bec.GetSpecies() == null) { m_BG.AttachRandomSpecies(target); count++; if (count >= m_Count) { return; } } } } } } /*int halfSize = m_Size >> 1; * for (int x = coord.x - halfSize; x < coord.x - halfSize + m_Size; x++){ * for (int y = coord.y - halfSize; y < coord.y - halfSize + m_Size; y++){ * Coord2D targetCoord = new Coord2D(x, y); * GameObject element = m_BG.GetElementByCoord(targetCoord); * if (element != null) { * m_BG.AttachRandomSpecies(element); * } * } * }*/ } }
// Update is called once per frame void Update() { if (m_Pause) { return; } m_CurTime += Time.deltaTime; if (m_CurTime >= m_LifeTime) { DestroyObject(gameObject); } else { m_DestroyCountDown -= Time.deltaTime; if (m_DestroyCountDown <= 0) { int halfSize = m_Size >> 1; for (int x = m_Coord.x - halfSize; x < m_Coord.x - halfSize + m_Size; x++) { GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, m_Coord.y)); if (obj != null) { BoxElementControl control = obj.GetComponent <BoxElementControl>(); control.DestroyElement(); } } m_DestroyCountDown = m_DestroyTime; } } }
// Use this for initialization void Start() { GameObject gc = GameObject.FindGameObjectWithTag("GameController"); m_BG = gc.GetComponent <BoxGenerator>(); //寬度是偶數行時需shift,特效跟消融方塊的區域重疊位置才會一樣 float offsetX = 0, offsetY = 0; if (m_Size % 2 == 0) { offsetX = 0.5f; offsetY = 0.5f; } Coord2D coord = m_BG.PosToCoord(new Vector2(transform.localPosition.x + offsetX, transform.localPosition.y + offsetY)); if (coord.x != -1 && coord.y != -1) { int halfSize = m_Size >> 1; for (int x = coord.x - halfSize; x < coord.x - halfSize + m_Size; x++) { for (int y = coord.y - halfSize; y < coord.y - halfSize + m_Size; y++) { Coord2D targetCoord = new Coord2D(x, y); GameObject element = m_BG.GetElementByCoord(targetCoord); if (element != null) { BoxElementControl control = element.GetComponent <BoxElementControl>(); control.DestroyElement(); } } } } }
bool FindNextTarget() { m_CurBounce++; if (m_CurBounce >= m_BounceNum) { return(false); } int w = m_BG.GetCoordW(); int h = m_BG.GetCoordH(); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { Coord2D coord = new Coord2D((x + m_TargetCoord.x) % w, y); GameObject obj = m_BG.GetElementByCoord(coord); if (obj == null) { continue; } BoxElementControl objControl = obj.GetComponent <BoxElementControl>(); if (objControl.m_Type == m_TargetType && objControl.GetState() != BoxState.ELIMINATE) { m_Target = obj; m_TargetCoord = coord; return(true); } } } return(false); }
public bool IsReachTop() { int w = m_BG.GetCoordW(); int h = m_BG.GetCoordH(); for (int x = 0; x < w; x++) { GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, h - 1)); if (obj) { BoxElementControl bec = obj.GetComponent <BoxElementControl>(); if (bec.GetState() == BoxState.FIX) { return(true); //element fixed at top } } } return(false); }
bool IsMatch(Coord2D coord) { GameObject nb = m_BG.GetElementByCoord(coord); if (nb == null) { return(false); } BoxElementControl nbControl = nb.GetComponent <BoxElementControl>(); if (nbControl.m_Type == m_Type && (nbControl.m_State == BoxState.FIX || nbControl.m_State == BoxState.ELIMINATE)) { return(true); } else { return(false); } }
public void EliminateRow(int row) { int w = m_BG.GetCoordW(); for (int x = 0; x < w; x++) { GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, row)); if (!obj) { continue; } BoxElementControl control = obj.GetComponent <BoxElementControl>(); control.DestroyElement(); } }
// Use this for initialization void Start() { m_ParticleArray = new GameObject[m_ParticleNum]; for (int i = 0; i < m_ParticleNum; i++) { m_ParticleArray[i] = (GameObject)Instantiate(m_Particle); m_ParticleArray[i].transform.parent = transform; m_ParticleArray[i].transform.localPosition = Vector3.zero; } GameObject gc = GameObject.FindGameObjectWithTag("GameController"); m_BG = gc.GetComponent <BoxGenerator>(); m_CurBounce = 0; Vector2 pos = new Vector2(transform.localPosition.x, transform.localPosition.y); m_TargetCoord = m_BG.PosToCoord(pos); if (m_TargetCoord.x != -1 && m_TargetCoord.y != -1) { m_Target = m_BG.GetElementByCoord(m_TargetCoord); if (m_Target != null) { BoxElementControl targetControl = m_Target.GetComponent <BoxElementControl>(); m_TargetType = targetControl.m_Type; for (int i = 0; i < m_ParticleNum; i++) { m_ParticleArray[i].transform.position = m_Target.transform.position + m_Offset; } } else { DestroyObject(gameObject); } } }