Exemplo n.º 1
0
        public void Unselect()
        {
            const float ANIM_DURATION = 0.1f;

            Vector3 scale       = transform.localScale;
            Vector3 targetScale = Vector3.one;

            selectionState = -1;


            StartCoroutine(Interpolators.Curve(
                               Interpolators.EaseOutCurve,
                               0f, 1f,
                               ANIM_DURATION,
                               (step) =>
            {
                if (selectionState == -1)
                {
                    Vector3 newScale     = Vector3.Lerp(scale, targetScale, step);
                    transform.localScale = newScale;

                    Vector3 shiftToCenter = newScale - targetScale;
                    shift = -(shiftToCenter / 2f);
                }
            },
                               () =>
            {
                if (selectionState == -1)
                {
                    shift = Vector3.zero;
                    spriteRenderer.sortingOrder = DEFAULT_ORDER;
                }
            }));
        }
Exemplo n.º 2
0
        public void Select()
        {
            const float ANIM_DURATION = 0.15f;

            Vector3 scale       = Vector3.one;
            Vector3 targetScale = Vector3.one * 1.3f;

            selectionState = 1;

            if (spriteRenderer.sortingOrder == DEFAULT_ORDER)
            {
                spriteRenderer.sortingOrder = SELECT_ORDER;
            }

            shift = Vector3.zero;
            Vector3 oldScale = transform.localScale;

            StartCoroutine(Interpolators.Curve(
                               Interpolators.EaseOutCurve,
                               0f, 1f,
                               ANIM_DURATION,
                               (step) =>
            {
                if (selectionState == 1)
                {
                    Vector3 newScale = Vector3.Lerp(scale, targetScale, step);

                    transform.localScale = newScale;

                    Vector2 shiftToCenter = newScale - oldScale;
                    shift = -(shiftToCenter / 2f);
                }
            },
                               null));
        }
Exemplo n.º 3
0
        private void ActivationChanged(bool activated, bool animate)
        {
            if (block.IsEmpty == false)
            {
                if (activated)
                {
                    darkness = 0f;
                    if (animate == false)
                    {
                        spriteRenderer.color = Color.white;
                    }
                    else
                    {
                        const float DURATION    = 0.2f;
                        const float SCALE_BONUS = 0.1f;

                        // Fade
                        var startColor = spriteRenderer.color;
                        StartCoroutine(Interpolators.Curve(Interpolators.EaseOutCurve, 0f, 1f, DURATION,
                                                           (step) => { spriteRenderer.color = Color.Lerp(startColor, Color.white, step); }, null));

                        Vector3 previousScale = transform.localScale;
                        spriteRenderer.sortingOrder += 10;

                        // Grow
                        StartCoroutine(Interpolators.Curve(Interpolators.EaseOutCurve, 0f, 1f, DURATION,
                                                           (step) =>
                        {
                            transform.localScale = Vector3.one * (1 + (SCALE_BONUS * step));

                            Vector3 shiftToCenter = (transform.localScale - previousScale);
                            shiftToCenter.x       = -shiftToCenter.x / 2f;
                            shiftToCenter.y       = 0;

                            shift = shiftToCenter;
                        }, () =>
                        {
                            // Reverse grow
                            StartCoroutine(Interpolators.Curve(Interpolators.EaseOutCurve, 1f, 0f, DURATION,
                                                               (step) =>
                            {
                                transform.localScale = Vector3.one * (1 + (SCALE_BONUS * step));

                                Vector3 shiftToCenter = (transform.localScale - previousScale);
                                shiftToCenter.x       = -shiftToCenter.x / 2f;
                                shiftToCenter.y       = 0;

                                shift = shiftToCenter;
                            }, () =>
                            {
                                // Reset
                                shift = Vector2.zero;
                                spriteRenderer.sortingOrder -= 10;
                            }));
                        }));
                    }
                }
            }
        }
Exemplo n.º 4
0
        private IEnumerator EmptyAnimation(int n, int count, System.Action callback)
        {
            spriteRenderer.sortingOrder += 10 + n;
            int remaining = count - n;

            // Easy constants access
            //---------------------------------------------------

            // Timings
            const float BLINK_DURATION = 0.5f;
            const float GROW_DURATION  = 0.15f;
            const float WAIT_BEFORE_EXPLOSION_DURATION = 0.2f;
            const float EXPLOSION_DURATION             = 0.1f;
            const float EXPLOSION_DURATION_SHIFT       = 0.1f;

            // Values
            const float GROW_SCALE_BONUS = 0.105f;

            //---------------------------------------------------

            if (IsHidden)
            {
                Reveal(0, 2.5f);
            }

            // Blink fade
            spriteRenderer.DOFade(0.5f, 0.1f).SetLoops(-1, LoopType.Yoyo);

            yield return(new WaitForSeconds(BLINK_DURATION));

            spriteRenderer.DOKill();
            spriteRenderer.DOFade(0.75f, 0f);

            // Grow...
            var previousScale = transform.localScale;

            StartCoroutine(Interpolators.Curve(Interpolators.EaseOutCurve, 0f, 1f, GROW_DURATION,
                                               (step) =>
            {
                transform.localScale = Vector3.one * (1 + (GROW_SCALE_BONUS * step));

                Vector3 shitToCenter = (transform.localScale - previousScale);
                shitToCenter.x       = -shitToCenter.x / 2f;
                shitToCenter.y       = 0;

                shift = shitToCenter;
            }, null));

            yield return(new WaitForSeconds(GROW_DURATION + WAIT_BEFORE_EXPLOSION_DURATION));

            // Wait
            var duration = (n * EXPLOSION_DURATION_SHIFT);

            yield return(new WaitForSeconds(duration));

            // Block disappear
            spriteRenderer.DOFade(0f, 0.15f).SetEase(Ease.InCubic)
            .SetDelay(0.1f);

            yield return(new WaitForSeconds(EXPLOSION_DURATION));

            OnEmpty.Raise(block.Definition);

            // THIS synchronize falls between all blocks.
            yield return(new WaitForSeconds(remaining * EXPLOSION_DURATION_SHIFT));

            // Reset
            shift = Vector2.zero;
            transform.localScale = Vector3.one;

            spriteRenderer.sortingOrder -= 10 + n;

            callback.Raise();
        }