// 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;
         }
     }
 }
示例#2
0
    // 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();
                    }
                }
            }
        }
    }
    public void SpeciesRescued()
    {
        for (int i = 0; i < m_SkillBt.Length; i++)
        {
            if (m_SkillBt[i] != null)
            {
                m_SkillBt[i].AddAmount(m_Amount[i]);
            }
        }

        UserData.RescueSpecies(m_SpeciesID);
        int count = UserData.m_EnabledSpecies[m_SpeciesID];

        if (count == 1)
        {
            m_ConfirmPanel.m_Title.text   = "救援成功";
            m_ConfirmPanel.m_Image.sprite = GetComponent <SpriteRenderer>().sprite;
            m_ConfirmPanel.m_Info.text    = m_SpeciesName;
            m_ConfirmPanel.OpenMenu();
        }
        else if (count % 10 == 0)
        {
            m_ConfirmPanel.m_Title.text   = "救援 " + count + " 次";
            m_ConfirmPanel.m_Image.sprite = GetComponent <SpriteRenderer>().sprite;
            m_ConfirmPanel.m_Info.text    = m_SpeciesName;
            m_ConfirmPanel.OpenMenu();
            //消除跟目前物種同色的方塊
            GameObject        gc  = GameObject.FindGameObjectWithTag("GameController");
            GameObject        box = gameObject.transform.parent.gameObject;
            BoxElementControl bec = box.GetComponent <BoxElementControl>();
            Debug.Log(bec.m_Type);
            gc.GetComponent <BoxGenerator>().EliminateBoxWithType(bec.m_Type);
        }
    }
示例#4
0
    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);
    }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        if (m_Pause)
        {
            return;
        }

        if (m_Target == null)
        {
            if (!FindNextTarget())
            {
                DestroyObject(gameObject);
            }
        }
        else if (Vector3.Distance(m_ParticleArray[0].transform.position, m_Target.transform.position + m_Offset) < 0.5f)
        {
            BoxElementControl control = m_Target.GetComponent <BoxElementControl>();
            control.DestroyElement();
            if (!FindNextTarget())
            {
                DestroyObject(gameObject);
            }
        }
        else
        {
            TraceTarget();
        }
    }
示例#6
0
    public void SwipeElement(MoveDir dir)
    {
        if (m_Pause)
        {
            return;
        }
        if (m_TouchElement == null)
        {
            return;
        }
        BoxElementControl curControl = m_TouchElement.GetComponent <BoxElementControl>();

        GameObject nbObj = curControl.GetNeighbor(dir);

        if (nbObj == null)
        {
            return;
        }

        BoxElementControl nbControl = nbObj.GetComponent <BoxElementControl>();
        MoveDir           opDir     = BoxElementControl.OppositeDir(dir);

        if (curControl.GetState() == BoxState.FIX && nbControl.GetState() == BoxState.FIX)
        {
            curControl.SwipeTo(dir);
            nbControl.SwipeTo(opDir);
        }
        m_TouchElement = null;
    }
示例#7
0
    // 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);
             *      }
             *  }
             * }*/
        }
    }
    public void MarkEliminate(Coord2D coord)
    {
        GameObject obj = m_BG.GetElementByCoord(coord);

        if (obj == null)
        {
            return;
        }
        BoxElementControl objControl = obj.GetComponent <BoxElementControl>();

        objControl.MarkEliminate();
    }
    // Use this for initialization
    void Start()
    {
        m_ConfirmPanel = GameObject.Find("ConfirmPanel").GetComponentInChildren <ConfirmPanel>();

        for (int i = 0; i < m_SkillBt.Length; i++)
        {
            m_SkillBt[i] = BoxElementControl.GetSkillButton(i);
        }
        m_Amount[0] = m_MetalAmount;
        m_Amount[1] = m_WoodAmount;
        m_Amount[2] = m_WaterAmount;
        m_Amount[3] = m_FireAmount;
        m_Amount[4] = m_EarthAmount;
    }
示例#10
0
    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();
        }
    }
示例#11
0
 public void EliminateBoxWithType(int type)
 {
     for (int i = 0; i < m_ElementArray.Length; i++)
     {
         if (m_ElementArray[i] == null)
         {
             continue;
         }
         BoxElementControl bec = m_ElementArray[i].GetComponent <BoxElementControl>();
         if (bec.m_Type == type)
         {
             bec.MarkEliminate();
         }
     }
 }
示例#12
0
    public void CheckEliminate()
    {
        int w = m_BG.GetCoordW();
        int h = m_BG.GetCoordH();

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, y));
                if (obj == null)
                {
                    continue;               //no object
                }
                BoxElementControl bec = obj.GetComponent <BoxElementControl>();
                bec.CheckEliminate();
            }
        }
    }
示例#13
0
    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);
        }
    }
示例#15
0
    // 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);
            }
        }
    }
示例#16
0
    public void CheckMoveBack()
    {
        int w = m_BG.GetCoordW();
        int h = m_BG.GetCoordH();

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, y));
                if (obj == null)
                {
                    continue;               //no object
                }
                BoxElementControl curControl = obj.GetComponent <BoxElementControl>();
                if (curControl.ReadyToMoveBack())
                {
                    MoveDir    swipeDir = curControl.GetSwipeDir();
                    MoveDir    opDir    = BoxElementControl.OppositeDir(swipeDir);
                    GameObject nb       = curControl.GetNeighbor(opDir);
                    if (nb == null)
                    {
                        continue;
                    }
                    BoxElementControl nbControl = nb.GetComponent <BoxElementControl>();
                    if (nbControl.ReadyToMoveBack())    //no match
                    {
                        curControl.MoveBack();
                        nbControl.MoveBack();
                    }
                    else    //nb match success
                    {
                        curControl.DoNotMoveBack();
                    }
                }
            }
        }
    }