コード例 #1
0
        private void addRow()
        {
            this._pendingToAddRow = false;
            bool overflows = this._matrix.shiftOneRow();


            for (int i = 0; i < this.geometry.columns; i++)
            {
                BubbleController bubbleController = this.createBubble();
                bubbleController.isMoving = false;
                this._matrix.insert(bubbleController.bubble, 0, i);
            }

            foreach (BubbleController bubbleController in this._bubbleControllers)
            {
                if (bubbleController != this._currentBubble)
                {
                    Vector3 position = BubbleMatrixControllerHelper.PositionForCell(this._matrix.location(bubbleController.bubble), geometry, this._matrix.isBaselineAlignedLeft);
                    //bubbleController.moveTo(position, this._shiftAnimationDuration);
                    bubbleController.transform.position = position;
                }
            }

            if (overflows)
            {
                this.FinishGame(GameState.Loose);
                return;
            }
        }
コード例 #2
0
        void runTest()
        {
            BubbleMatrixGeometry geometry  = new BubbleMatrixGeometry(0.0f, 10.5f, 10.0f, 0.0f, 10, 10, 0.5f);
            Vector3 position1              = new Vector3(0.6f, 9.6f, 0.0f);
            bool    isBaselineAlignedLeft1 = true;
            Vector2 expectedAnswer1        = new Vector2(0f, 0f);
            Vector2 answer1 = BubbleMatrixControllerHelper.CellForPosition(position1, geometry, isBaselineAlignedLeft1);

            Debug.Log("[BubbleMatrixControllerHelper] Test correct?  " + ((expectedAnswer1.x == answer1.x) && (expectedAnswer1.y == answer1.y)));


            position1 = new Vector3(0.6f, 9.6f, 0.0f);
            isBaselineAlignedLeft1 = false;
            expectedAnswer1        = new Vector2(0f, 0f);
            answer1 = BubbleMatrixControllerHelper.CellForPosition(position1, geometry, isBaselineAlignedLeft1);
            Debug.Log("[BubbleMatrixControllerHelper] Test correct?  " + ((expectedAnswer1.x == answer1.x) && (expectedAnswer1.y == answer1.y)));


            position1 = new Vector3(1.2f, 9.6f, 0.0f);
            isBaselineAlignedLeft1 = true;
            expectedAnswer1        = new Vector2(0f, 1f);
            answer1 = BubbleMatrixControllerHelper.CellForPosition(position1, geometry, isBaselineAlignedLeft1);
            bool correct = ((expectedAnswer1.x == answer1.x) && (expectedAnswer1.y == answer1.y));

            Debug.Log("[BubbleMatrixControllerHelper] Test correct?  " + correct);


            position1 = new Vector3(1.2f, 9.6f, 0.0f);
            isBaselineAlignedLeft1 = false;
            expectedAnswer1        = new Vector2(0f, 0f);
            answer1 = BubbleMatrixControllerHelper.CellForPosition(position1, geometry, isBaselineAlignedLeft1);
            correct = ((expectedAnswer1.x == answer1.x) && (expectedAnswer1.y == answer1.y));
            Debug.Log("[BubbleMatrixControllerHelper] Test correct?  " + correct);


            position1 = new Vector3(0.2f, 11.0f, 0.0f);
            isBaselineAlignedLeft1 = false;
            expectedAnswer1        = new Vector2(0f, 0f);
            answer1 = BubbleMatrixControllerHelper.CellForPosition(position1, geometry, isBaselineAlignedLeft1);
            correct = ((expectedAnswer1.x == answer1.x) && (expectedAnswer1.y == answer1.y));
            Debug.Log("[BubbleMatrixControllerHelper] Test correct?  " + correct);



            position1 = new Vector3(-2.2f, 13.0f, 0.0f);
            isBaselineAlignedLeft1 = true;
            expectedAnswer1        = new Vector2(0f, 0f);
            answer1 = BubbleMatrixControllerHelper.CellForPosition(position1, geometry, isBaselineAlignedLeft1);
            correct = ((expectedAnswer1.x == answer1.x) && (expectedAnswer1.y == answer1.y));
            Debug.Log("[BubbleMatrixControllerHelper] Test correct?  " + correct);


            position1 = new Vector3(10.45f, 13.0f, 0.0f);
            isBaselineAlignedLeft1 = false;
            expectedAnswer1        = new Vector2(0f, 9f);
            answer1 = BubbleMatrixControllerHelper.CellForPosition(position1, geometry, isBaselineAlignedLeft1);
            correct = ((expectedAnswer1.x == answer1.x) && (expectedAnswer1.y == answer1.y));
            Debug.Log("[BubbleMatrixControllerHelper] Test correct?  " + correct);
            //public static Vector2 CellForPosition(Vector3 position, BubbleMatrixGeometry geometry, bool isBaselineAlignedLeft){
        }
コード例 #3
0
        /*
         * Delegate method to lets the bubble controler know if the move to location is allowed
         * Used to avoid a situation when two balls can end up in the same snapping point
         * if the Time.delta is sufficently large between two frames
         *
         */
        bool canMoveToPosition(Vector3 position)
        {
            Vector2 location = BubbleMatrixControllerHelper.CellForPosition(position, this.geometry, this._matrix.isBaselineAlignedLeft);

            if ((int)location.x <= this.geometry.rows - 1)
            {
                return(!this._matrix.hasBubble((int)location.x, (int)location.y));
            }
            return(true);
        }
コード例 #4
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();
        }