Пример #1
0
        public Bubble Attached(Bubble bubble)
        {
            var toJoin = collector.ScoreNeighbours(bubble);

            if (toJoin.Count <= 1)
            {
                CheckRowCount();
                return(null); //nothing to join
            }

            IBubbleScore score    = calculator.CalculateScore(bubble.Score, toJoin.Count);
            Tile         bestTile = collector.SelectBestTile(toJoin, score);

            //detach old bubbles
            foreach (var bb in toJoin)
            {
                bb.Movement.MoveTowards(bestTile.transform.position);
                bb.StartCoroutine(DelayReturn(bb, DelayReturnTime));
            }

            //create new bubble
            var newBubble = spawner.Create(score);

            #if UNITY_EDITOR
            UnityEditor.EditorGUIUtility.PingObject(newBubble.gameObject);
            #endif

            grid.Insert(newBubble, bestTile);

            foreach (var toDrop in FindLooseBubbles(toJoin))
            {
                toDrop.Movement.Drop();
                toDrop.StartCoroutine(DelayReturn(toDrop, DelayReturnTime));
            }

            Debug.Log($"Collected {score.PointsString} points");

            if (newBubble.Score.Exponent > scoreRange.ExplosionExponent)
            {
                exploder.Explode(newBubble);
                CheckRowCount();
                return(null);
            }
            else
            {
                //continue chain
                return(newBubble);
            }
        }
Пример #2
0
        private void FillRow(int q, int r, ref int exponent)
        {
            Tile tile = grid.TileAt(q, r);

            while (tile != null)
            {
                if (exponent >= values.Length)
                {
                    return;
                }
                var value = values[exponent++];
                if (value > 0)
                {
                    var bubble = spawner.Create(new BubbleScore(value));
                    grid.Insert(bubble, tile);
                }
                tile = grid.Neighbour(tile, HexDirection.E);
            }
        }