Example #1
0
        // Prepare a bubble at the starting point.
        public void LoadBubble()
        {
            loadedBubble = Instantiate(bubblePrefab, transform.position, Quaternion.identity) as GameObject;

            Bubble bubble = loadedBubble.GetComponent <Bubble> ();

            bubble.Color          = pallette.GetRandomBubbleColor();
            bubble.State          = BubbleState.Loaded;
            bubble.GameBoard      = gameBoard;
            bubble.BubbleLauncher = this;

            SpriteRenderer renderer = loadedBubble.GetComponent <SpriteRenderer> ();

            renderer.color = pallette.GetColor(bubble.Color);
        }
Example #2
0
        public frmBubbbleShooter()
        {
            InitializeComponent();


            for (int i = 0; i < 50; i++)
            {
                for (int j = 0; j < 50; j++)
                {
                    bubbles[i, j] = new Bubble();
                }
            }

            start();
        }
Example #3
0
        public void EraseAndFall(Bubble alignedBubble)
        {
            ArrayList bubbleIndexList = GetAdjacentSameColorBubbles (alignedBubble.Index, alignedBubble.Color);
              // Do nothing if the number of same color connecting bubbles is less than three.
              if (bubbleIndexList.Count < 3)
            return;

              // Get the list of all bubbles that should fall.
              ArrayList fallBubbleList = GetFallBubbles (bubbleIndexList);

              // Remove direct nodes from bubbleMap.
              DestroyBubbles (bubbleIndexList);
              // Make these bubbles to fall.
              MakeBubblesFall (fallBubbleList);
        }
Example #4
0
        // Stop on game board.
        private void StopOnBoard(Bubble collidedBubble)
        {
            Rigidbody2D rb = GetComponent <Rigidbody2D> ();

            rb.velocity    = Vector2.zero;
            rb.isKinematic = true;
            // Snap this bubble to game board.
            this.GameBoard.SnapBubble(this, collidedBubble);
            // Erase and fall bubbles if possible.
            this.GameBoard.EraseAndFall(this);
            // Set stopping flag.
            this.State = BubbleState.Stopped;
            // Load a new bubble.
            this.BubbleLauncher.LoadBubble();
        }
        public void RemoveBubble(Bubble bubble)
        {
            _bubblePool.Push(bubble.BubbleObject);

            var color = bubble.Color;

            if (!_colorsCount.ContainsKey(color))
            {
                return;
            }

            _colorsCount[color]--;

            if (_colorsCount[color] == 0)
            {
                _colorsCount.Remove(color);
            }
        }
Example #6
0
        public void EraseAndFall(Bubble alignedBubble)
        {
            ArrayList bubbleIndexList = GetAdjacentSameColorBubbles(alignedBubble.Index, alignedBubble.Color);

            // Do nothing if the number of same color connecting bubbles is less than three.
            if (bubbleIndexList.Count < 3)
            {
                return;
            }

            // Get the list of all bubbles that should fall.
            ArrayList fallBubbleList = GetFallBubbles(bubbleIndexList);

            // Remove direct nodes from bubbleMap.
            DestroyBubbles(bubbleIndexList);
            // Make these bubbles to fall.
            MakeBubblesFall(fallBubbleList);
        }
Example #7
0
        private void StickBubble(Bubble bubble, Coordinate coordinate)
        {
            if (coordinate.Row >= _tiles.Count)
            {
                AddNewRow();

                _rows++;
            }

            AddBubble(bubble, coordinate);

            var cluster = GetCluster(coordinate, true, true);

            var position = _tiles[coordinate.Row][coordinate.Column].Anchor.transform.position;

            StartCoroutine(ActivateEffector(position));

            if (cluster.Count >= 3)
            {
                foreach (var tile in cluster)
                {
                    BurstsBubble(tile.Coordinate);
                }

                var floatingClusters = GetFloatingClusters();

                foreach (var floatingCluster in floatingClusters)
                {
                    foreach (var tile in floatingCluster)
                    {
                        UnstickBubble(tile.Coordinate);
                    }
                }
            }

            if (_fallingBubbles == 0)
            {
                RemoveEmptyTiles();

                Context.Instance.NotificationService.Notify(NotificationType.BoardReady);
            }
        }
        private void ChangeColorWhenNecessary(Bubble bubble, int maxCount)
        {
            var color = bubble.Color;
            var count = _colorsCount.ContainsKey(color) ? _colorsCount[color] : maxCount - 1;

            if (count > maxCount)
            {
                return;
            }

            if (count == maxCount)
            {
                _colorsCount.Remove(color);
            }

            color        = GetRandomColor();
            bubble.Color = color;

            _colorsCount[color]++;
        }
Example #9
0
        // Launch the bubble.
        public void LaunchBubble(Vector2 direction)
        {
            if (loadedBubble == null)
            {
                return;
            }

            // Set the velocity of the bubble.
            Rigidbody2D rb = loadedBubble.GetComponent <Rigidbody2D> ();

            rb.velocity = launchSpeed * direction.normalized;

            Bubble bubble = loadedBubble.GetComponent <Bubble> ();

            bubble.State = BubbleState.Launched;

            loadedBubble = null;

            Debug.LogFormat("A new bubble is launched towards direction: {0}.", direction.normalized);
        }
Example #10
0
 // Snap the bubble to the game board.
 public void SnapBubble(Bubble newBubble, Bubble collidedBubble)
 {
     int snappedXIndex = 1;
       int snappedYIndex = 1;
       if (collidedBubble == null) {
     // Collision object is UpperBorder.
     float minDistance = 2 * bubbleRadius;
     for (int i = 1; i <= numBubblesEachRow; i++) {
       float distance = Vector2.Distance (newBubble.transform.position, bubbleMapPosition [1, i]);
       if (distance < minDistance) {
     minDistance = distance;
     snappedYIndex = i;
       }
     }
       } else {
     // Collision object is an existing bubble.
     int collidedX = collidedBubble.Index.X;
     int collidedY = collidedBubble.Index.Y;
     IndexPair[] nearbyIndex = getAllNearbyIndex (collidedX, collidedY);
     float minDistance = 2 * bubbleRadius;
     snappedXIndex = collidedX;
     snappedYIndex = collidedY;
     for (int i = 0; i <= 5; i++) {
       if (!IndexCheck (nearbyIndex [i].X, nearbyIndex [i].Y))
     continue;
       if (bubbleMap [nearbyIndex [i].X, nearbyIndex [i].Y] != null)
     continue;
       float distance = Vector2.Distance (newBubble.transform.position, bubbleMapPosition [nearbyIndex [i].X, nearbyIndex [i].Y]);
       if (distance < minDistance) {
     minDistance = distance;
     snappedXIndex = nearbyIndex [i].X;
     snappedYIndex = nearbyIndex [i].Y;
       }
     }
     // This should never happen.
     if (snappedXIndex == collidedX && snappedYIndex == collidedY)
       return;
       }
       newBubble.transform.position = new Vector2 (bubbleMapPosition [snappedXIndex, snappedYIndex].x, bubbleMapPosition [snappedXIndex, snappedYIndex].y);
       StoreBubbleToMap (newBubble, snappedXIndex, snappedYIndex);
 }
Example #11
0
 public BubbleBurstingState(Bubble bubble) : base(bubble, BubbleStateType.Bursting)
 {
 }
 public BubbleStickedState(Bubble bubble) : base(bubble, BubbleStateType.Sticked)
 {
 }
Example #13
0
 private void StoreBubbleToMap(Bubble bubble, int xIndex, int yIndex)
 {
     bubble.Index = new IndexPair(xIndex, yIndex);
     bubbleMap [xIndex, yIndex] = bubble;
 }
 public BubbleAimingState(Bubble bubble) : base(bubble, BubbleStateType.Aiming)
 {
 }
        public override void Update()
        {
            if (_inputService.HoldPressed)
            {
                var position = _inputService.CursorPosition;
                var distance = Vector2.Distance(position, _startingPosition);

                if (distance > _pullingDistance)
                {
                    position = _startingPosition + (position - _startingPosition).normalized * _pullingDistance;
                }

                if (position.y > _startingPosition.y)
                {
                    position.y = _startingPosition.y;
                }

                Bubble.transform.position = position;

                var force = GetForce();

                var velocityA = GetDirection() * (force * _maxSpeed);

                if (1 - force < AllowableError)
                {
                    var velocityB = Quaternion.Euler(0, 0, _angularDisplacement) * (velocityA - position);
                    velocityA = Quaternion.Euler(0, 0, -_angularDisplacement) * (velocityA - position);

                    _trajectoryA.SetValues(Bubble.transform.position, velocityA, force);
                    _trajectoryB.SetValues(Bubble.transform.position, velocityB, force);

                    Context.Instance.LevelController.Trajectories.DrawTrajectories(_trajectoryA, _trajectoryB);
                }
                else
                {
                    _trajectoryA.SetValues(Bubble.transform.position, velocityA, force);

                    Context.Instance.LevelController.Trajectories.DrawTrajectory(_trajectoryA);
                }
            }
            else
            {
                var force = GetForce();

                if (force >= _minForce)
                {
                    if (1 - force < AllowableError)
                    {
                        var randomAngle = Random.Range(-_angularDisplacement, _angularDisplacement);
                        var velocity    = Quaternion.Euler(0, 0, -randomAngle) * GetDirection() * (force * _maxSpeed);

                        _trajectoryA.SetValues(Bubble.transform.position, velocity, force);
                    }

                    Bubble.Trajectory = _trajectoryA;

                    Bubble.SwitchState(BubbleStateType.Moving);
                }
                else
                {
                    Bubble.transform.position = _startingPosition;
                }

                Context.Instance.LevelController.Trajectories.HideTrajectories();
            }
        }
 public BubbleFallingState(Bubble bubble) : base(bubble, BubbleStateType.Falling)
 {
 }
Example #17
0
 protected override void SetReferences()
 {
     _transform           = Instance.transform;
     _bubble              = Instance.GetComponent <Bubble>();
     _bubble.BubbleObject = this;
 }
Example #18
0
 // Stop on game board.
 private void StopOnBoard(Bubble collidedBubble)
 {
     Rigidbody2D rb = GetComponent<Rigidbody2D> ();
       rb.velocity = Vector2.zero;
       rb.isKinematic = true;
       // Snap this bubble to game board.
       this.GameBoard.SnapBubble (this, collidedBubble);
       // Erase and fall bubbles if possible.
       this.GameBoard.EraseAndFall (this);
       // Set stopping flag.
       this.State = BubbleState.Stopped;
       // Load a new bubble.
       this.BubbleLauncher.LoadBubble ();
 }
 public BubbleIdleState(Bubble bubble) : base(bubble, BubbleStateType.Idle)
 {
 }
Example #20
0
        public void StickBubble(Bubble bubble)
        {
            var coordinate = bubble.transform.position.ToCoordinateWorld();

            StickBubble(bubble, coordinate);
        }
Example #21
0
 private void StoreBubbleToMap(Bubble bubble, int xIndex, int yIndex)
 {
     bubble.Index = new IndexPair (xIndex, yIndex);
       bubbleMap [xIndex, yIndex] = bubble;
 }