public void SetAIState(GhostAIState state)
 {
     _ai.SetAIState(state);
     this.AIstate = state;
     _pointGoal   = null;
     _pathList    = null;
 }
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Player") &&
         (aiState == GhostAIState.FRIGHTENED || aiState == GhostAIState.FRIGHTENED_FINISHING))
     {
         aiState          = GhostAIState.EATEN;
         gameObject.layer = 11;
         gameState.score += 200;
     }
 }
    public void Start()
    {
        GameObject ghostBody = transform.Find(Tags.GhostBody).gameObject;

        bodyRenderer       = ghostBody.GetComponent <Renderer>();
        chaseMaterial      = bodyRenderer.materials[0];
        frightenedMaterial = bodyRenderer.materials[1];
        materialIndex      = 0;
        ai        = GetComponent <GhostAI>();
        lastState = GhostAIState.Chase;
    }
 // Start is called before the first frame update
 void Start()
 {
     rb              = gameObject.GetComponent <Rigidbody2D>();
     animator        = gameObject.GetComponent <Animator>();
     targetProvider  = gameObject.GetComponent <TargetProvider>();
     rb.gravityScale = 0.0f;
     rb.constraints  = RigidbodyConstraints2D.FreezeRotation;
     Physics2D.IgnoreLayerCollision(13, 9);
     Physics2D.IgnoreLayerCollision(10, 10);
     Physics2D.IgnoreLayerCollision(10, 11);
     Physics2D.IgnoreLayerCollision(11, 11);
     Physics2D.IgnoreLayerCollision(11, 9);
     Physics2D.IgnoreLayerCollision(10, 13);
     aiState = GhostAIState.SCATTER;
 }
    protected override void setAnimationState()
    {
        GhostWalker ghost = walker as GhostWalker;

        if (ghost.chase())
        {
            if (lastState == GhostAIState.Frightened || lastState == GhostAIState.Dead)
            {
                setMaterial(0);
            }
            lastState = GhostAIState.Chase;
        }
        if (ghost.scatter())
        {
            if (lastState == GhostAIState.Frightened || lastState == GhostAIState.Dead)
            {
                setMaterial(0);
            }
            lastState = GhostAIState.Scatter;
        }
        if (ghost.frightened())
        {
            if (lastState != GhostAIState.Frightened)
            {
                setMaterial(1);
            }
            else
            {
                // 5 flashes
                double t = ai.remainingFrightenedTime;
                if (t <= 1.5)
                {
                    setMaterial((int)(t / 0.15) % 2 == 0 ? 1 : 0);
                }
            }
            lastState = GhostAIState.Frightened;
        }
        if (ghost.dead())
        {
            if (lastState != GhostAIState.Dead)
            {
                bodyRenderer.enabled = false;
                GameObject.FindGameObjectWithTag("Pacman").GetComponent <PacmanSounds> ().ghostEaten();
            }
            lastState = GhostAIState.Dead;
        }
    }
Beispiel #6
0
 public float ghostSpeedMultiplier(GhostAIState ghostState)
 {
     if (ghostState != GhostAIState.Dead)
     {
         if (_currentScene == Tags.Scene01)
         {
             return(ghostState == GhostAIState.Frightened ? .4f : .75f);
         }
         if (_currentScene == Tags.Scene02)
         {
             return(ghostState == GhostAIState.Frightened ? .45f : .85f);
         }
         if (_currentScene == Tags.Scene04 || _currentScene == Tags.Scene05)
         {
             return(ghostState == GhostAIState.Frightened ? .5f : .95f);
         }
     }
     return(1f);
 }
        public Point GetNextMoveGoal(Point ghostPosition, Point playerPosition)
        {
            if (_AIState == GhostAIState.TargetingWithLag && _AIrefreshCount > 9)
            {
                _AIrefreshCount = 0;
                GetNewPath(ghostPosition, playerPosition);
            }
            if (_pathList == null || _pathList.Count == 0)
            {
                GetNewPath(ghostPosition, playerPosition);
            }
            if (_pathList != null && _pathList.Count > 0)
            {
                _AIrefreshCount++;
                if (_pathList.Count == 1 && _AIState == GhostAIState.Fleeing)
                {
                    _AIState = GhostAIState.Random;
                    GetNewPath(ghostPosition, playerPosition);
                }
                return(_pathList.Pop());
            }

            return(ghostPosition);
        }
 public void SetAIState(GhostAIState state)
 {
     _AIState  = state;
     _pathList = null;
 }
Beispiel #9
0
        public void OnAction(Entity entity)
        {
            if ((entity.Mask & MASK) == MASK)
            {
                ComponentMovement movementComponent = (ComponentMovement)entity.FindComponent(ComponentTypes.COMPONENT_MOVEMENT);
                ComponentAIGhost  aiComponent       = (ComponentAIGhost)entity.FindComponent(ComponentTypes.COMPONENT_AI_GHOST);

                string targetID = aiComponent.Target;

                //get the target location
                Entity target = entityManager.FindEntity(targetID);

                if (target != null && target.HasComponent(ComponentTypes.COMPONENT_TRANSFORM))
                {
                    ComponentTransform transformComponent = (ComponentTransform)entity.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);
                    ComponentTransform targetTransform    = (ComponentTransform)target.FindComponent(ComponentTypes.COMPONENT_TRANSFORM);

                    Vector3 ghostPosition  = transformComponent.Position;
                    Vector3 targetPosition = targetTransform.Position;

                    //get direction between entity and target
                    Vector3 direction = targetPosition - ghostPosition;
                    direction.Y = 0;
                    if (direction.Length != 0)
                    {
                        direction.Normalize();
                    }

                    //set direction to max speed of ghost
                    if (movementComponent.HasMaxSpeed)
                    {
                        direction *= movementComponent.MaxSpeed;
                    }

                    //set velocity
                    if (state == GhostAIState.Chasing)
                    {
                        movementComponent.Velocity = direction;
                    }
                    else if (state == GhostAIState.Fleeing)
                    {
                        movementComponent.Velocity = -direction;
                    }
                    else if (state == GhostAIState.Dead)
                    {
                        //stay still for a time
                        TimeSpan timeSinceDeath = DateTime.Now - aiComponent.DeathTime;

                        if (timeSinceDeath.Seconds >= 5)
                        {
                            state = GhostAIState.Chasing;
                        }
                        else
                        {
                            movementComponent.Velocity = new Vector3(0, 0, 0);
                        }
                    }
                }
                else
                {
                    movementComponent.Velocity = new Vector3(0, 0, 0);
                }
            }
        }
Beispiel #10
0
 public SystemGhostAI(EntityManager pEntityManager)
 {
     entityManager = pEntityManager;
     state         = GhostAIState.Chasing;
 }