Exemplo n.º 1
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     currChaseTime  += Time.deltaTime;
     currUpdateTime += Time.deltaTime;
     if (currChaseTime > ghost.ChaseTime && !Game.IsNearLevelEnd())
     {
         animator.SetBool("is_scattering", true);
     }
     else
     {
         var playerCellPos = tilemap.WorldToCell(player.transform.position);
         var ghostCellPos  = tilemap.WorldToCell(ghost.transform.position);
         if (!ghost.HasStopped && pathfinding.GetTileDistance(ghostCellPos, playerCellPos) < fleeDistance && !isFleeing)
         {
             isFleeing      = true;
             currUpdateTime = 0f;
             ghost.MoveTo(ghost.CornerPositions[0].position);
         }
         else if (ghost.HasStopped || currUpdateTime > updateTargetPosTime)
         {
             isFleeing      = false;
             currUpdateTime = 0f;
             ghost.MoveTo(player.transform.position);
         }
     }
 }
Exemplo n.º 2
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     currChaseTime  += Time.deltaTime;
     currUpdateTime += Time.deltaTime;
     if (currChaseTime > ghost.ChaseTime && !Game.IsNearLevelEnd())
     {
         animator.SetBool("is_scattering", true);
     }
     else
     {
         if (ghost.HasStopped || currUpdateTime > updateTargetPosTime)
         {
             currUpdateTime = 0f;
             var playerCellPos = tilemap.WorldToCell(player.transform.position);
             var ghostCellPos  = tilemap.WorldToCell(ghost.transform.position);
             var dir           = playerCellPos - ghostCellPos;
             dir.Clamp(Vector3Int.one * -1, Vector3Int.one);
             if (pathfinding.GetTileDistance(ghostCellPos, playerCellPos) <= 4 && dir != player.MoveDir)
             {
                 ghost.MoveTo(playerCellPos);
             }
             else
             {
                 ghost.MoveTo(pathfinding.GetNearestTileInBounds(playerCellPos, player.MoveDir * 4));
             }
         }
     }
 }
Exemplo n.º 3
0
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            ghost = !ghost?animator.GetComponent <GhostAI>() : ghost;

            currScatterTime = 0.0f;
            currPosIndex    = 0;
            ghost.MoveTo(ghost.CornerPositions[0].position);
        }
Exemplo n.º 4
0
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            ghost = !ghost?animator.GetComponent <GhostAI>() : ghost;

            ghost.MoveTo(Player.instance.transform.position);
            currUpdateTime = 0.0f;
            currChaseTime  = 0.0f;
        }
Exemplo n.º 5
0
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            ghost = !ghost?animator.GetComponent <GhostAI>() : ghost;

            ghost.isRetreating = true;
            ghost.MoveTo(MapInfo.CageExit);
            movingToCageExit = true;
            movingToCagePos  = false;

            ghost.SpriteAnimator.SetBool("is_retreating", true);
        }
Exemplo n.º 6
0
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            player      = !player ? Player.instance : player;
            tilemap     = !tilemap ? MapInfo.CollisionMap : tilemap;
            pathfinding = !pathfinding ? Pathfinding.instance : pathfinding;
            ghost       = !ghost?animator.GetComponent <GhostAI>() : ghost;

            ghost.MoveTo(player.transform.position);
            currUpdateTime = 0.0f;
            currChaseTime  = 0.0f;
        }
Exemplo n.º 7
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     currChaseTime  += Time.deltaTime;
     currUpdateTime += Time.deltaTime;
     if (currChaseTime > ghost.ChaseTime && !Game.IsNearLevelEnd())
     {
         animator.SetBool("is_scattering", true);
     }
     else
     {
         if (ghost.HasStopped || currUpdateTime > updateTargetPosTime)
         {
             currUpdateTime = 0f;
             Vector3Int playerCellPos = tilemap.WorldToCell(player.transform.position);
             Vector3Int ghostCellPos  = tilemap.WorldToCell(ghost.transform.position);
             Vector3Int dir           = playerCellPos - ghostCellPos;
             dir.Clamp(Vector3Int.one * -1, Vector3Int.one);
             if (pathfinding.GetTileDistance(ghostCellPos, playerCellPos) <= 4 && dir != player.MoveDir)
             {
                 ghost.MoveTo(playerCellPos);
             }
             else
             {
                 /*
                  * According to the reference article for Ghost AI:
                  *   To locate Inky (cyan) target:
                  *    1 - Select the position two tiles in front of Pac-Man in his
                  *        current direction of travel.
                  *    2 - Create a vector from Blinky position to this tile, and
                  *        then double the length of the vector.
                  *    3 - The ending position of the vector (starting from Blinky)
                  *        is Inky's target.
                  */
                 Vector3Int redGhostCellPos = tilemap.WorldToCell(GhostsManager.instance.RedGhost.transform.position);
                 Vector3Int vectorEnd       = playerCellPos + player.MoveDir * 2;
                 Vector3Int vec             = (vectorEnd - redGhostCellPos) * 2;
                 ghost.MoveTo(pathfinding.GetNearestTileInBounds(redGhostCellPos, vec));
             }
         }
     }
 }
Exemplo n.º 8
0
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            ghost = !ghost?animator.GetComponent <GhostAI>() : ghost;

            ghost.isFrightened = true;
            currScaredTime     = 0.0f;
            currPosIndex       = 0;
            ghost.MoveTo(ghost.CornerPositions[0].position);
            ghost.CurrentSpeed = ghost.ScaredSpeed;
            ghost.SpriteAnimator.SetBool("is_frightened", true);
            ghost.SpriteAnimator.SetBool("is_flashing", true);
        }
Exemplo n.º 9
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     currChaseTime  += Time.deltaTime;
     currUpdateTime += Time.deltaTime;
     if (currChaseTime > ghost.ChaseTime && !Game.IsNearLevelEnd())
     {
         animator.SetBool("is_scattering", true);
     }
     else
     {
         if (ghost.needsTargetRecalc || ghost.HasStopped || currUpdateTime > updateTargetPosTime)
         {
             ghost.needsTargetRecalc = false;
             currUpdateTime          = 0f;
             ghost.MoveTo(Player.instance.transform.position);
         }
     }
 }
Exemplo n.º 10
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     currScatterTime += Time.deltaTime;
     if (currScatterTime > ghost.ScatterTime)
     {
         animator.SetBool("is_chasing", true);
     }
     else
     {
         if (ghost.HasStopped)
         {
             currPosIndex++;
             if (currPosIndex >= ghost.CornerPositions.Length)
             {
                 currPosIndex = 0;
             }
             ghost.MoveTo(ghost.CornerPositions[currPosIndex].position);
         }
     }
 }
Exemplo n.º 11
0
 override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (currScaredTime > Game.GetGhostScaredTime())
     {
         ghost.isFrightened = false;
         animator.SetBool("is_frightened", false);
     }
     else
     {
         if (ghost.HasStopped)
         {
             currPosIndex++;
             if (currPosIndex >= ghost.CornerPositions.Length)
             {
                 currPosIndex = 0;
             }
             ghost.MoveTo(ghost.CornerPositions[currPosIndex].position);
         }
     }
 }