Example #1
0
    void Update()
    {
        if (!tweener.TweenExists(transform, out var existingTween) || (Time.time - tween.StartTime) >= tween.Duration)
        {
            previousCellPos = currentCellPos;
            currentCellPos  = targetCellPos;

            if (GhostManager.Instance.HorizontalPortalsTilemap.HasTile(currentCellPos))
            {
                if (Mode == FruitMode.Exit)
                {
                    Destroy(gameObject);
                    return;
                }

                if (transform.position.x < 0)
                {
                    currentCellPos = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMax - 1, currentCellPos.y, 0);
                    targetCellPos  = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMax - 2, currentCellPos.y, 0);
                }
                else
                {
                    currentCellPos = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMin, currentCellPos.y, 0);
                    targetCellPos  = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMin + 1, currentCellPos.y, 0);
                }

                TweenToTargetCell();
            }
            else
            {
                UpdateTargetCell();

                if (targetCellPos != currentCellPos)
                {
                    if (currentCellPos - previousCellPos != targetCellPos - currentCellPos)
                    {
                        TweenToTargetCell();
                    }
                    else
                    {
                        tween.StartCellPos = currentCellPos;
                        tween.EndCellPos   = targetCellPos;
                        tween.UpdateWorldPositions();
                        tween.StartTime = Time.time - (Time.time - tween.StartTime - tween.Duration);
                    }
                }
            }
        }
    }
Example #2
0
    void Update()
    {
        if (LevelManager.Instance.GameSuspended)
        {
            UpdateAnimation(); return;
        }

        //Change the movement speed based on the current mode, faster when running home after being caught, slower when running away
        switch (Behaviour.Mode)
        {
        case GhostMode.Frightened:
        case GhostMode.Exiting:
            timeToTravelGridSize = baseTimeToTravelGridSize * 2f;
            break;

        case GhostMode.RunningHome:
            timeToTravelGridSize = baseTimeToTravelGridSize * 0.75f;
            break;

        default:
            timeToTravelGridSize = baseTimeToTravelGridSize;
            break;
        }

        if (LevelManager.Instance.ScrollingMode)
        {
            timeToTravelGridSize *= 1.5f;
        }

        if (!tweener.TweenExists(transform, out var existingTween) || (Time.time - tween.StartTime) >= tween.Duration)
        {
            PreviousCellPos = CurrentCellPos;
            CurrentCellPos  = TargetCellPos;

            if (GhostManager.Instance.HorizontalPortalsTilemap.HasTile(CurrentCellPos))
            {
                if (transform.position.x < 0)
                {
                    CurrentCellPos = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMax - 1, CurrentCellPos.y, 0);
                    TargetCellPos  = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMax - 2, CurrentCellPos.y, 0);
                }
                else
                {
                    CurrentCellPos = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMin, CurrentCellPos.y, 0);
                    TargetCellPos  = new Vector3Int(GhostManager.Instance.HorizontalPortalsTilemap.cellBounds.xMin + 1, CurrentCellPos.y, 0);
                }

                TweenToTargetCell(1.75f);
            }
            else
            {
                if (!ShouldReverseMovement)
                {
                    TargetCellPos = Behaviour.GetNextTargetCellPos(PreviousCellPos, CurrentCellPos);
                }

                if (TargetCellPos != CurrentCellPos)
                {
                    var durationMultiplier = GhostManager.Instance.GhostSlowersTilemap.HasTile(TargetCellPos) ? 1.75f : 1f;
                    if (CurrentCellPos - PreviousCellPos != TargetCellPos - CurrentCellPos)
                    {
                        TweenToTargetCell(durationMultiplier);
                    }
                    else
                    {
                        tween.StartCellPos = CurrentCellPos;
                        tween.EndCellPos   = TargetCellPos;
                        tween.UpdateWorldPositions();
                        tween.StartTime = Time.time - (Time.time - tween.StartTime - tween.Duration);
                        tween.Duration  = timeToTravelGridSize * durationMultiplier;
                    }
                }

                ShouldReverseMovement = false;
            }
        }
        else if (ShouldReverseMovement)
        {
            existingTween.Reverse();
            (CurrentCellPos, TargetCellPos) = (TargetCellPos, CurrentCellPos);

            ShouldReverseMovement = false;
        }

        UpdateAnimation();
    }
Example #3
0
    void Update()
    {
        if (LevelManager.Instance.GameSuspended)
        {
            return;
        }

        if (!PlayerManager.Instance.Tweener.TweenExists(transform, out var existingTween) || (Time.time - tween.StartTime) >= tween.Duration)
        {
            PreviousCellPos = CurrentCellPos;
            CurrentCellPos  = TargetCellPos;

            if (PlayerManager.Instance.HorizontalPortalsTilemap.HasTile(CurrentCellPos))
            {
                if (transform.position.x < 0)
                {
                    CurrentCellPos = new Vector3Int(PlayerManager.Instance.HorizontalPortalsTilemap.cellBounds.xMax - 1, CurrentCellPos.y, 0);
                    TargetCellPos  = new Vector3Int(PlayerManager.Instance.HorizontalPortalsTilemap.cellBounds.xMax - 2, CurrentCellPos.y, 0);
                }
                else
                {
                    CurrentCellPos = new Vector3Int(PlayerManager.Instance.HorizontalPortalsTilemap.cellBounds.xMin, CurrentCellPos.y, 0);
                    TargetCellPos  = new Vector3Int(PlayerManager.Instance.HorizontalPortalsTilemap.cellBounds.xMin + 1, CurrentCellPos.y, 0);
                }

                TweenToTargetCell();
            }
            else
            {
                var updatedTargetCellPos = GetUpdatedTargetCellAndSprite();

                var playerAudioSource = AudioManager.Instance.PlayerAudioSource;
                if (PlayerManager.Instance.DotsTilemap.HasTile(CurrentCellPos))
                {
                    PlayerManager.Instance.DotsTilemap.SetTile(CurrentCellPos, null);
                    PlayerManager.Instance.Points += 10;
                    PlayerManager.Instance.DotsEaten++;

                    if (!playerAudioSource.isPlaying)
                    {
                        playerAudioSource.clip = AudioManager.Instance.PlayerEatDotClip;
                        playerAudioSource.loop = true;
                        playerAudioSource.Play();
                    }
                }
                else
                {
                    playerAudioSource.loop = false;
                }

                if (updatedTargetCellPos != CurrentCellPos)
                {
                    TargetCellPos = updatedTargetCellPos;

                    if (CurrentCellPos - PreviousCellPos != TargetCellPos - CurrentCellPos)
                    {
                        TweenToTargetCell();
                        ApplyFlipAndRotation();
                    }
                    else
                    {
                        tween.StartCellPos = CurrentCellPos;
                        tween.EndCellPos   = TargetCellPos;
                        tween.UpdateWorldPositions();
                        tween.StartTime = Time.time - (Time.time - tween.StartTime - tween.Duration);
                    }
                }
            }
        }
        else if (IsMovementKeyRetrograde())
        {
            lastMovementKeyApplied = PlayerInputManager.LastMovementKeyPressed;

            existingTween.Reverse();
            (CurrentCellPos, TargetCellPos) = (TargetCellPos, CurrentCellPos);

            ReverseFlipAndRotation();
            ApplyFlipAndRotation();
        }
    }