Exemplo n.º 1
0
    void BubbleMoving()
    {
        CurrentBubble.transform.position = Vector3.MoveTowards(CurrentBubble.transform.position, TargetLine[currentIndex], BubbleSpeed * Time.deltaTime * 5);

        if (CurrentBubble.transform.position.Equals(TargetLine[currentIndex]))
        {
            if (currentIndex == TargetLine.Count - 1)
            {
                BubbleToMergeInto = Instantiate(BubblePrefab, TargetLine[TargetLine.Count - 1], Quaternion.identity, BubbleHolder.transform).GetComponent <BubbleScript>();
                BubbleToMergeInto.SetValue(CurrentBubbleValue);
                CurrentBubble.transform.position = TargetLine[0];
                if (CurrentBubble.GetComponent <TrailRenderer>() != null)
                {
                    CurrentBubble.GetComponent <TrailRenderer>().enabled = false;
                }
                SetNeighborBubbles();
                currentState = ShootState.MergingBubbles;
                currentIndex = 0;
            }
            else
            {
                currentIndex++;
            }
        }
    }
Exemplo n.º 2
0
    void MergeBubbles()
    {
        if (!IsMovingToMergeBubble)
        {
            BubblesToMove.Clear();
            BubbleScript.BubbleValue targetValue = CurrentBubbleValue;
            BubblesToMove.Add(BubbleToMergeInto);
            bool FirstCheck = BubbleToMergeInto.GetNeighBorsOfvalue(targetValue, ref BubblesToMove);

            if (FirstCheck)
            {
                for (int i = 0; i < BubblesToMove.Count; i++)
                {
                    BubblesToMove[i].GetNeighBorsOfvalue(targetValue, ref BubblesToMove);
                }

                BubbleToMergeInto = BubblesToMove[BubblesToMove.Count - 1];

                if ((int)(BubbleToMergeInto.ThisValue) + BubblesToMove.Count >= (int)BubbleScript.BubbleValue.Count)
                {
                    BubblesToMove.Remove(BubbleToMergeInto);
                    BubblesToMove.TrimExcess();

                    IsMovingToMergeBubble = true;
                }
                else
                {
                    int NewNearbyMerges = 0;
                    for (int i = 0; i < BubblesToMove.Count; i++)
                    {
                        List <BubbleScript> valid = new List <BubbleScript>();
                        BubblesToMove[i].GetNeighBorsOfvalue((BubbleScript.BubbleValue)((int)(BubbleToMergeInto.ThisValue) + BubblesToMove.Count - 1), ref valid);

                        if (valid.Count > NewNearbyMerges)
                        {
                            NewNearbyMerges   = valid.Count;
                            BubbleToMergeInto = BubblesToMove[i];
                        }
                    }
                    BubblesToMove.Remove(BubbleToMergeInto);
                    BubblesToMove.TrimExcess();

                    IsMovingToMergeBubble = true;
                }
            }
            else
            {
                currentState = ShootState.RemovingfloatingBubbles;
            }
        }
        else
        {
            bool allArrived = true;
            for (int i = 0; i < BubblesToMove.Count; i++)
            {
                if (!BubbleToMergeInto.transform.position.Equals(BubblesToMove[i].transform.position))
                {
                    allArrived = false;
                    BubblesToMove[i].transform.position = Vector3.MoveTowards(BubblesToMove[i].transform.position, BubbleToMergeInto.transform.position, BubbleSpeed * Time.deltaTime * 5);
                }
            }

            if (allArrived)
            {
                if ((int)(BubbleToMergeInto.ThisValue) + BubblesToMove.Count >= (int)BubbleScript.BubbleValue.Count)
                {
                    BubbleToMergeInto.SetValue(BubbleScript.BubbleValue.TwoK);
                }
                else
                {
                    BubbleToMergeInto.SetValue((BubbleScript.BubbleValue)((int)BubbleToMergeInto.ThisValue + BubblesToMove.Count));
                }

                if (BubbleToMergeInto.ThisValue == BubbleScript.BubbleValue.TwoK)
                {
                    for (int i = 0; i < BubblesToMove.Count; i++)
                    {
                        BubblesToMove[i].Pop();
                    }

                    SetNeighborBubbles();

                    BubbleToMergeInto.Explode();
                    currentState          = ShootState.RemovingfloatingBubbles;
                    IsMovingToMergeBubble = false;
                }
                else
                {
                    for (int i = 0; i < BubblesToMove.Count; i++)
                    {
                        BubblesToMove[i].Pop();
                    }

                    BubblesToMove.Clear();

                    if (BubbleToMergeInto.GetNeighBorsOfvalue(BubbleToMergeInto.ThisValue, ref BubblesToMove))
                    {
                        IsMovingToMergeBubble = false;
                        CurrentBubbleValue    = BubbleToMergeInto.ThisValue;
                    }
                    else
                    {
                        currentState          = ShootState.RemovingfloatingBubbles;
                        IsMovingToMergeBubble = false;
                    }
                }
            }
        }
    }