예제 #1
0
        public void SetBulletValueAndColor(Bubble bubble)
        {
            var rndValue = Random.Range(0, _maxGridValue);

            bubble.SetValue(_bubbleValues[rndValue]);
            bubble.SetColor(_bubbleColors[rndValue]);
        }
예제 #2
0
        public void AddBulletBubbleToGrid(Bubble collisionBubble, BulletBubble bullet)
        {
            var adjacentSpots = GetAdjacentSpots(collisionBubble);
            var emptySpots    = adjacentSpots.emptySpots;

            // set bubble to grid
            var    minDis = 1000f;
            Bubble b      = null;

            foreach (var spot in emptySpots)
            {
                var d = Vector2.Distance(spot.transform.position, bullet.transform.position);

                if (!(d < minDis))
                {
                    continue;
                }

                minDis = d;
                b      = spot;
                b.SetColor(bullet.BubbleColor);
                b.SetValue(bullet.BubbleValue);
            }

            bullet.gameObject.SetActive(false);
            b.gameObject.SetActive(true);

            //get chain of neighbors
            StartNeighborChain(b);
            CheckIfGridNeedsToMove();
        }
예제 #3
0
        public void SetNewValueForBubble(Bubble bubble, int sortedNeighborsCount)
        {
            var bubbleValueIndex = _bubbleValues.FindIndex(a => a.Equals(bubble.BubbleValue));

            if (_bubbleValues[bubbleValueIndex] == GetMaxBubbleValue())
            {
                bubble.TriggerMaxValueEffect();

                if (MaxBubblePopped != null)
                {
                    MaxBubblePopped.Invoke(bubble.BubbleValue);
                }

                return;
            }

            try
            {
                bubble.SetValue(_bubbleValues[bubbleValueIndex + sortedNeighborsCount - 1]);
                bubble.SetColor(_bubbleColors[bubbleValueIndex + sortedNeighborsCount - 1]);
            }
            catch (Exception e)
            {
                if (MaxBubblePopped != null)
                {
                    MaxBubblePopped.Invoke(bubble.BubbleValue);
                }

                Debug.LogFormat("{0} for bubble {1}", e, bubble.BubbleValue);
                throw;
            }

            if (bubble.BubbleValue == GetMaxBubbleValue())
            {
                bubble.TriggerMaxValueEffect();

                if (MaxBubblePopped != null)
                {
                    MaxBubblePopped.Invoke(bubble.BubbleValue);
                }

                return;
            }

            CreatePointsPopup(bubble.transform.position, bubble.BubbleValue, bubble.BubbleColor);
            bubble.TriggerParticleEffect(bubble.BubbleColor);

            if (OnBubblePopped != null)
            {
                OnBubblePopped.Invoke(bubble.BubbleValue);
            }
        }