Пример #1
0
        void Update()
        {
            if (_bubbleBoard.IsLevelCompleted() || _waitForBubbleToArrive)
            {
                return;
            }

            if (IsAiming())
            {
                aimLineRenderer.positionCount = 3;

                _aimTarget = null;
                HandleAim();
            }
            else if (FinishedAiming())
            {
                if (_aimTarget != null)
                {
                    _aimTarget.BubbleSlotView().Reserve();
                    OnBubbleShot();
                    _bubbleShoot.Shoot(_aimTarget);
                    _aimTarget             = null;
                    _waitForBubbleToArrive = true;
                }

                OnNoBubbleSlotPreviewActivated();
            }
            else
            {
                aimLineRenderer.positionCount = 1;
                OnNoBubbleSlotPreviewActivated();
            }
        }
Пример #2
0
        private IEnumerator ShootBubble(BubbleAimTarget aimTarget, BubbleAmmoView ammoView)
        {
            if (aimTarget.Bounces())
            {
                yield return(StartCoroutine(MoveTo(aimTarget.BouncePosition(), ammoView)));
            }

            yield return(StartCoroutine(MoveTo(aimTarget.BubbleSlotView().transform.position, ammoView)));

            OnBubbleAdded(aimTarget.BubbleSlotView(), ammoView.BubbleConfig());

            yield return(null);

            Destroy(ammoView.gameObject);
        }
Пример #3
0
 public void Shoot(BubbleAimTarget aimTarget)
 {
     StartCoroutine(ShootBubble(aimTarget, _bubbleAmmo.TakeCurrentAmmo()));
 }
Пример #4
0
        private void HandleAim()
        {
            var touchPosition = AimingPosition();

            var aimHits = Physics2D.RaycastAll(transform.position, touchPosition - transform.position);

            for (var i = 0; i < aimHits.Length; i++)
            {
                var aimHit = aimHits[i];

                if (IsAimingAtEmptySlot(aimHit))
                {
                    continue;
                }

                if (IsAimingAtAvailableBubble(aimHit))
                {
                    aimLineRenderer.SetPosition(1, aimHit.point);
                    aimLineRenderer.SetPosition(2, aimHit.point);
                    if (i > 0)
                    {
                        var targetSlot = aimHits[i - 1].transform.GetComponent <BubbleSlotView> ();
                        OnBubbleSlotPreviewActivated(targetSlot);

                        _aimTarget = new BubbleAimTarget(targetSlot);
                    }

                    break;
                }

                if (IsAimingAtWall(aimHit))
                {
                    aimLineRenderer.SetPosition(1, aimHit.point);

                    var reflectionDirection = Vector3.Reflect(touchPosition - transform.position, aimHit.normal);

                    var reflectionHits = Physics2D.RaycastAll(aimHit.point, reflectionDirection, 100, ~(1 << LayerMask.NameToLayer(Layers.BOUNCE_SIDE)));

                    for (var j = 0; j < reflectionHits.Length; j++)
                    {
                        var reflectionHit = reflectionHits[j];

                        if (IsAimingAtEmptySlot(reflectionHit))
                        {
                            continue;
                        }

                        if (IsAimingAtAvailableBubble(reflectionHit))
                        {
                            aimLineRenderer.SetPosition(2, reflectionHit.point);
                            if (j > 0)
                            {
                                var targetSlot = reflectionHits[j - 1].transform.GetComponent <BubbleSlotView> ();
                                OnBubbleSlotPreviewActivated(targetSlot);

                                _aimTarget = new BubbleAimTarget(targetSlot, aimHit.point);
                            }

                            else if (i > 0)
                            {
                                var targetSlot = aimHits[i - 1].transform.GetComponent <BubbleSlotView> ();
                                OnBubbleSlotPreviewActivated(targetSlot);

                                _aimTarget = new BubbleAimTarget(targetSlot, aimHit.point);
                            }

                            break;
                        }

                        if (IsAimingAtUpperEnd(reflectionHit))
                        {
                            aimLineRenderer.SetPosition(2, aimHit.point);
                            _aimTarget = null;
                            OnNoBubbleSlotPreviewActivated();

                            break;
                        }
                    }

                    break;
                }

                if (IsAimingAtUpperEnd(aimHit))
                {
                    aimLineRenderer.SetPosition(1, aimHit.point);
                    aimLineRenderer.SetPosition(2, aimHit.point);
                    _aimTarget = null;
                    OnNoBubbleSlotPreviewActivated();
                    break;
                }
            }
        }