Inheritance: UnityEngine.MonoBehaviour
        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;
            }
        }
 private void destroyBubble(BubbleController bubbleController, bool explodes)
 {
     this._matrix.remove(bubbleController.bubble);
     this._bubbleControllers.Remove(bubbleController);
     bubbleController.CollisionDelegate = null;
     bubbleController.kill(explodes);
     //Destroy(bubbleController.gameObject);
 }
		void Update(){
			if (Input.GetMouseButtonDown(0) && this._isPlaying){
				if (this._currentBubble != null){
					this._currentBubble.isMoving = true;
					this._currentBubble.angle = this.shootingRotation();
					this._currentBubble = null;
				}
			}
		}
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && this._isPlaying)
     {
         if (this._currentBubble != null)
         {
             this._currentBubble.isMoving = true;
             this._currentBubble.angle    = this.shootingRotation();
             this._currentBubble          = null;
         }
     }
 }
Example #5
0
 void Update()
 {
     if (CrossPlatformInputManager.GetAxis("Fire") != 0 && this._isPlaying)
     {
         if (this._currentBubble != null)
         {
             this._currentBubble.isMoving = true;
             this._currentBubble.angle    = this.shootingRotation();
             this._currentBubble          = null;
         }
     }
 }
Example #6
0
 void Update()
 {
     if (Input.GetMouseButtonUp(0) && this._isPlaying && !TouchController.Instance.isTouchingUI) //TODO: handle input in TouchController
     {
         if (this._currentBubble != null)
         {
             this._currentBubble.isMoving = true;
             this._currentBubble.angle    = this.shootingRotation();
             this._currentBubble          = null;
         }
     }
 }
        public void startGame()
        {
            this._bubblesContainer = GameObject.Find("Bubbles");
            this._bubbleShooter    = GameObject.Find("BubbleShooter");
            this.geometry          = new BubbleMatrixGeometry(leftBorder, rightBorder, topBorder, 0.0f, rows, columns, bubbleRadius);
            this._currentBubble    = this.createBubble();
            this._isPlaying        = true;
            StartCoroutine("addRowScheduler");

            for (int i = 0; i < _defaultRowsCount; i++)
            {
                this.addRow();
            }
        }
		public void startGame(){
			
			this._bubblesContainer = GameObject.Find("Bubbles");
			this._bubbleShooter = GameObject.Find ("BubbleShooter");
			this.geometry = new BubbleMatrixGeometry(leftBorder, rightBorder, topBorder, 0.0f, rows, columns, bubbleRadius);
			this._currentBubble = this.createBubble();
			this._isPlaying = true;
			StartCoroutine("addRowScheduler");
			
			for (int i =0 ; i < _defaultRowsCount; i++){
				this.addRow();
			}
			
		}
        private BubbleController createBubble()
        {
            GameObject bubblePrefab = Instantiate(Resources.Load(_bubblePrefabName)) as GameObject;

            bubblePrefab.transform.parent   = _bubblesContainer.transform;
            bubblePrefab.transform.position = new Vector3((rightBorder - leftBorder) / 2.0f - geometry.bubbleRadius / 2.0f, -0.65f, 0);
            BubbleController bubbleController = bubblePrefab.GetComponent <BubbleController>();

            bubbleController.leftBorder        = this.geometry.leftBorder;
            bubbleController.rightBorder       = this.geometry.rightBorder;
            bubbleController.topBorder         = this.geometry.topBorder;
            bubbleController.radius            = this.geometry.bubbleRadius;
            bubbleController.linearSpeed       = _bubbleLinearSpeed;
            bubbleController.angle             = 90.0f;
            bubbleController.isMoving          = false;
            bubbleController.CollisionDelegate = onBubbleCollision;
            bubbleController.MotionDelegate    = canMoveToPosition;
            this._bubbleControllers.Add(bubbleController);
            return(bubbleController);
        }
        /*
         * 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();
        }
		/* 
		 * 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();
		}
		private void destroyBubble(BubbleController bubbleController, bool explodes){
			this._matrix.remove(bubbleController.bubble);
			this._bubbleControllers.Remove(bubbleController);
			bubbleController.CollisionDelegate = null;
			bubbleController.kill(explodes);
			//Destroy(bubbleController.gameObject);
		}
Example #13
0
 private void prepareCurrentBubble()
 {
     this._currentBubble = this.createBubble();
     this._currentBubble.setIgnoreRaycast();
 }