Example #1
0
    public override void OnAnimalExit(Animal animal)
    {
        if (_enterCount == 1)
        {
            // Set animal to null
            _animal = null;

            GameManager.Instance.OnAnimalExitFoothold(this);

            _isDouble = false;

            var delay         = DelayAction.Create(0.5f);
            var playExplosion = CallFuncAction.Create(() => {
                // Play sound
                SoundManager.Instance.PlaySound(SoundID.Explose);

                if (explosionPrefab != null)
                {
                    GameObject explosion = explosionPrefab.Create(transform, icon.transform.position);
                    explosion.AddSortingOrder(icon.GetSortingOrder() + 1);
                }
            });
            var fadeOut = FadeAction.FadeOut(0.25f);
            var hide    = HideAction.Create();

            // Hide icon
            icon.Play(SequenceAction.Create(delay, playExplosion, fadeOut, hide));
        }
        else
        {
            base.OnAnimalExit(animal);
        }
    }
Example #2
0
    void Sink()
    {
        var delay        = DelayAction.Create(0.5f);
        var disableSwing = CallFuncAction.Create(() => { _swingEnabled = false; });
        var move         = MoveAction.MoveBy(new Vector3(0, -sinkDelta, 0), 0.5f, Ease.SineIn);
        var fadeOut      = FadeAction.RecursiveFadeOut(0.5f);

        gameObject.Play(SequenceAction.Create(delay, disableSwing, ParallelAction.ParallelAll(move, fadeOut)), () => {
            SelfDestroy();
        });
    }
    void Jump()
    {
        Direction direction = _solution.Dequeue();

        int nextRow    = -1;
        int nextColumn = -1;

        if (NextCell(direction, ref nextRow, ref nextColumn))
        {
            // Set direction
            SetDirection(direction);

            // Get foothold type
            FootholdType type = _types[_curRow, _curColumn];

            // Update foothold
            if (type == FootholdType.Double)
            {
                // Set foothold
                SetFoothold(_curRow, _curColumn, FootholdType.Normal);
            }
            else if (type != FootholdType.None)
            {
                // Set foothold
                SetFoothold(_curRow, _curColumn, FootholdType.None);
            }

            // Set next cell
            _curRow    = nextRow;
            _curColumn = nextColumn;

            // Jump
            var jump     = MoveAction.MoveTo(GetPosition(nextRow, nextColumn), jumpDuration * 0.5f);
            var delay    = DelayAction.Create(jumpDuration * 0.5f);
            var callFunc = CallFuncAction.Create(JumpCallback);
            var action   = SequenceAction.Create(jump, delay, callFunc);

            _frog.gameObject.Play(action);
        }
    }
Example #4
0
    public void JumpToMap(float delay1, Vector3 position, float delay2, Action callback)
    {
        Vector2   start = transform.position;
        Vector2   end   = position;
        Vector2   control;
        Direction direction = DirectionHelper.GetDirection(start, end);

        // Up
        if (direction.IsUp())
        {
            // Left
            if (direction.IsLeft())
            {
                animator.SetTrigger(nhayNgang);
                transform.SetHorizontalFlip(false);

                control = new Vector2((start.x + end.x) * 0.5f, start.y + Mathf.Sqrt(Mathf.Abs(end.x - start.x)) * controlHeightFactor);
            }
            // Right
            else if (direction.IsRight())
            {
                animator.SetTrigger(nhayNgang);
                transform.SetHorizontalFlip(true);

                control = new Vector2((start.x + end.x) * 0.5f, start.y + Mathf.Sqrt(Mathf.Abs(end.x - start.x)) * controlHeightFactor);
            }
            else
            {
                animator.SetTrigger(nhayLen);
                transform.SetHorizontalFlip(false);

                control = new Vector2(start.x, end.y + controlDeltaY);
            }
        }
        else
        {
            // Left
            if (direction.IsLeft())
            {
                animator.SetTrigger(nhayNgang);
                transform.SetHorizontalFlip(false);

                control = new Vector2((start.x + end.x) * 0.5f, start.y + Mathf.Sqrt(Mathf.Abs(end.x - start.x)) * controlHeightFactor);
            }
            // Right
            else if (direction.IsRight())
            {
                animator.SetTrigger(nhayNgang);
                transform.SetHorizontalFlip(true);

                control = new Vector2((start.x + end.x) * 0.5f, start.y + Mathf.Sqrt(Mathf.Abs(end.x - start.x)) * controlHeightFactor);
            }
            else
            {
                animator.SetTrigger(nhayXuong);
                transform.SetHorizontalFlip(false);

                control = new Vector2(start.x, start.y + controlDeltaY);
            }
        }

        var        jump   = SequenceAction.Create(QuadBezierAction.BezierTo(control, end, 0.5f), CallFuncAction.Create(() => { animator.SetTrigger(nghiXuong); }));
        BaseAction action = null;

        if (delay1 > 0)
        {
            if (delay2 > 0)
            {
                action = SequenceAction.Create(DelayAction.Create(delay1), jump, DelayAction.Create(delay2));
            }
            else
            {
                action = SequenceAction.Create(DelayAction.Create(delay1), jump);
            }
        }
        else
        {
            if (delay2 > 0)
            {
                action = SequenceAction.Create(jump, DelayAction.Create(delay2));
            }
            else
            {
                action = jump;
            }
        }

        // Jump
        gameObject.Play(action, callback);
    }
    IEnumerator Try()
    {
        int nextRow    = -1;
        int nextColumn = -1;

        for (int i = 0; i < 4; i++)
        {
            Direction dir = Directions[i];

            if (!dir.IsOpposite(_curDirection))
            {
                if (NextCell(dir, ref nextRow, ref nextColumn))
                {
                    // Push
                    _cells.Push(new Cell(_curRow, _curColumn));

                    // Save cell
                    int row    = _curRow;
                    int column = _curColumn;

                    // Save direction
                    Direction direction = _curDirection;

                    FootholdType type1 = _types[_curRow, _curColumn];
                    FootholdType type2 = _types[nextRow, nextColumn];

                    // Set direction
                    SetDirection(dir);

                    // Update current cell
                    if (type1 == FootholdType.Double)
                    {
                        // Set foothold
                        SetFoothold(_curRow, _curColumn, FootholdType.Normal);

                        // Increase counter
                        _count++;
                    }
                    else if (type1 != FootholdType.None)
                    {
                        // Set foothold
                        SetFoothold(_curRow, _curColumn, FootholdType.None);

                        // Increase counter
                        _count++;
                    }

                    // Jump
                    var jump = MoveAction.MoveTo(GetPosition(nextRow, nextColumn), jumpDuration * 0.5f);

                    if (type2.IsRedirect())
                    {
                        Direction newDirection = type2.GetDirection();

                        _frog.gameObject.Play(SequenceAction.Create(jump, CallFuncAction.Create(() => {
                            SetDirection(newDirection);
                        })));
                    }
                    else
                    {
                        _frog.gameObject.Play(jump);
                    }

                    // Set current cell to next one
                    _curRow    = nextRow;
                    _curColumn = nextColumn;

                    yield return(new WaitForSeconds(jumpDuration));

                    // Check if finished
                    if (_count == _total - 1)
                    {
                        Show();
                    }
                    else
                    {
                        yield return(StartCoroutine(Try()));
                    }

                    // Restore cell
                    _curRow    = row;
                    _curColumn = column;

                    // Restore position
                    _frog.transform.position = GetPosition(_curRow, _curColumn);

                    // Restore type
                    if (type1 != FootholdType.None)
                    {
                        // Set foothold
                        SetFoothold(_curRow, _curColumn, type1);

                        // Decrease counter
                        _count--;
                    }

                    // Restore direction
                    SetDirection(direction);

                    // Pop
                    _cells.Pop();

                    yield return(new WaitForSeconds(unjumpDuration));
                }
            }
        }
    }
Example #6
0
    protected override void OnShowFinished(Action callback)
    {
        // Play firework
        if (fireworkPrefab != null)
        {
            int   total     = fireworkPositions.Length;
            int[] positions = total.RandomIndices();
            int   count     = total > minFirework?UnityEngine.Random.Range(minFirework, total) : total;

            float delay = 0.0f;

            for (int i = 0; i < count; i++)
            {
                GameObject firework = Instantiate(fireworkPrefab);
                firework.transform.position = fireworkPositions[positions[i]].transform.position;

                if (delay > 0)
                {
                    ParticleSystem ps = firework.GetComponent <ParticleSystem>();
                    ps.Pause();

                    firework.Play(SequenceAction.Create(DelayAction.Create(delay), CallFuncAction.Create(() => {
                        SoundManager.Instance.PlaySound(SoundID.BigFirework, SoundType.New);
                        ps.Play();
                    })));
                }
                else
                {
                    SoundManager.Instance.PlaySound(SoundID.BigFirework, SoundType.New);
                }

                delay += 0.3f;
            }

            if (UserData.Instance.Map == 99 && !UserData.Instance.PlayedCutscene4)
            {
                ShowEndgameStory();
            }
        }

        int level = UserData.Instance.Map;

        // Check if win new map
        if (!UserData.Instance.IsWinned(level))
        {
            UserData.Instance.SetWinned(level);

            // Add bonus coins
            int coins = Settings.GetBonusCoins(level);
            NotificationManager.CoinChanged(UserData.Instance.Coin + coins);

            if (bonus != null)
            {
                // Show bonus
                bonus.Show();
                bonus.SetAlpha(1.0f, true);

                if (coinText != null)
                {
                    // Play sound
                    SoundManager.Instance.PlaySound(SoundID.Coin, SoundType.Loop);

                    var action = LerpIntAction.Create(1, coins, 0.5f, (coin) => {
                        coinText.text = coin.ToString();
                    });

                    gameObject.Play(action, () => {
                        // Stop sound
                        SoundManager.Instance.StopSound(SoundID.Coin);
                    });
                }
            }
        }

        // Show touch and overlay
        SetShowTouchAndOverlay(true);

        Invoke("CheckShowAds", 1.2f);
        Invoke("OnReady", 2f);

        if (callback != null)
        {
            callback();
        }
    }