コード例 #1
0
        /*
         * Delegate Handlers
         */
        /*
         * Collision Delegate Handler
         */
        void onBubbleCollision(GameObject bubble)
        {
            // If the ball falls under the amoun of rows, the game is over
            Vector2 bubblePos = BubbleMatrixControllerHelper.CellForPosition(bubble.transform.position, this.geometry, this._matrix.isBaselineAlignedLeft);

            if ((int)bubblePos.x >= this.geometry.rows)
            {
                this.FinishGame(GameState.Loose);
                return;
            }

            // Create the new bubble
            BubbleController bubbleController = bubble.GetComponent <BubbleController>();
            Vector2          matrixPosition   = BubbleMatrixControllerHelper.CellForPosition(bubble.transform.position, this.geometry, this._matrix.isBaselineAlignedLeft);

            // Update the model
            this._matrix.insert(bubbleController.bubble, (int)matrixPosition.x, (int)matrixPosition.y);

            // if we don't have to add a new row (because of the timer), move the bubble smoothly to its snapping point
            if (!this._pendingToAddRow)
            {
                bubbleController.moveTo(BubbleMatrixControllerHelper.PositionForCell(matrixPosition, geometry, this._matrix.isBaselineAlignedLeft), 0.1f);
            }
            else
            {
                // otherwise move it rapidly
                bubbleController.transform.position = BubbleMatrixControllerHelper.PositionForCell(matrixPosition, geometry, this._matrix.isBaselineAlignedLeft);
            }

            // Explode the bubbles that need to explode
            // The the cluster of bubbles with a similar color as the colliding one
            ArrayList cluster = this._matrix.colorCluster(bubbleController.bubble);

            if (cluster.Count > 2)
            {
                // Explode the cluster
                bubbleController.transform.position = BubbleMatrixControllerHelper.PositionForCell(matrixPosition, geometry, this._matrix.isBaselineAlignedLeft);
                this.destroyCluster(cluster, true);
                // Notify that bubbles have been removed
                GameEvents.BubblesRemoved(cluster.Count, true);
            }

            // Drop the bubbles that fall
            cluster = this._matrix.looseBubbles();
            this.destroyCluster(cluster, false);
            if (cluster.Count > 0)
            {
                GameEvents.BubblesRemoved(cluster.Count, false);
            }

            // Add a new Row of random bubbles if required
            if (_pendingToAddRow)
            {
                this.addRow();
                StartCoroutine("addRowScheduler");
            }

            // If there are no bubble lefts, win the game
            if (this._matrix.bubbles.Count == 0)
            {
                this.FinishGame(GameState.Win);
                return;
            }

            // Prepare the new bubble to shoot it
            this._currentBubble = this.createBubble();
        }