Esempio n. 1
0
    public override State Update(FSMAgent agent)
    {
        //Handle Following Pacman
        Vector3 pacmanLocation = PacmanInfo.Instance.transform.position;
        Vector3 pacmanFacing   = PacmanInfo.Instance.Facing;

        if (agent.CloseEnough(pacmanLocation))
        {
            ScoreHandler.Instance.KillPacman();
        }

        //If timer complete, go to Scatter State
        if (agent.TimerComplete())
        {
            return(new ScatterState(new Vector3(-ObstacleHandler.Instance.Width, ObstacleHandler.Instance.Height), this));
        }

        //If Pacman ate a power pellet, go to Frightened State
        if (PelletHandler.Instance.JustEatenPowerPellet)
        {
            return(new FrightenedState(this));
        }
        //If we didn't return follow Pacman
        //Debug.Log(pacmanFacing);
        Vector3   targetLocation = pacmanLocation + pacmanFacing * 0.8f;
        GraphNode g = HW3NavigationHandler.Instance.NodeHandler.ClosestNode(targetLocation);
        Vector3   realtargetPosition = g.Location;

        agent.SetTarget(realtargetPosition);

        //Stay in this state
        return(this);
    }
    public override State Update(FSMAgent agent)
    {
        //Handle Following Pacman
        Vector3 pacmanLocation = PacmanInfo.Instance.transform.position;

        if (agent.CloseEnough(pacmanLocation))
        {
            ScoreHandler.Instance.KillPacman();
        }

        //If timer complete, go to Scatter State
        if (agent.TimerComplete())
        {
            return(new ScatterState(new Vector3(-ObstacleHandler.Instance.Width, -ObstacleHandler.Instance.Height), new CustomHuntState()));
        }

        //If Pacman ate a power pellet, go to Frightened State
        if (PelletHandler.Instance.JustEatenPowerPellet)
        {
            return(new FrightenedState(this));
        }

        if (!ObstacleHandler.Instance.AnyIntersect(pacmanLocation, agent.GetPosition()))
        {
            return(new CustomExcitedChaseState());
        }
        //If we didn't return follow Pacman
        agent.SetTarget(pacmanLocation);

        //Stay in this state
        return(this);
    }
    public override State Update(FSMAgent agent)
    {
        //Handle Following Pacman
        Vector3 pacmanLocation = PacmanInfo.Instance.transform.position;

        if (agent.CloseEnough(pacmanLocation))
        {
            ScoreHandler.Instance.KillPacman();
        }

        //If timer complete, go to Scatter State
        //Unfortunately this ghost is too good to lose sight of you most of the time, but if you want you can add this to make it harder
        //if (agent.TimerComplete() && ObstacleHandler.Instance.AnyIntersect(pacmanLocation,agent.GetPosition()))
        if (agent.TimerComplete())
        {
            return(new CustomTiredChaseState());
        }

        //If Pacman ate a power pellet, go to Frightened State
        if (PelletHandler.Instance.JustEatenPowerPellet)
        {
            return(new FrightenedState(new CustomChaseState()));
        }

        //If we didn't return follow Pacman
        agent.SetTarget(pacmanLocation);

        //Stay in this state
        return(this);
    }
    public override State Update(FSMAgent agent)
    {
        //Check and see if we've been eaten, if so become eyes
        Vector3 pacmanLocation = PacmanInfo.Instance.transform.position;

        if (agent.CloseEnough(pacmanLocation))
        {
            return(new EyesState(returnState));
        }

        //Check and see if our timer completed, if so return to returnState
        if (agent.TimerComplete())
        {
            return(returnState);
        }

        //Handle random movement
        if (randomTimer < RANDOM_TIMER_MAX)
        {
            randomTimer += Time.deltaTime;
        }
        else
        {
            randomTimer = 0;
            agent.SetTarget(new Vector3(Random.RandomRange(-1 * ObstacleHandler.Instance.Width, ObstacleHandler.Instance.Width), Random.RandomRange(-1 * ObstacleHandler.Instance.Height, ObstacleHandler.Instance.Height)));
        }
        //Stay in this state
        return(this);
    }
Esempio n. 5
0
    public override State Update(FSMAgent agent)
    {
        //Handle Following Pacman
        Vector3  pacmanLocation = PacmanInfo.Instance.transform.position;
        Vector3  pacmanFacing = PacmanInfo.Instance.Facing;
        Vector3  location, realLocation;
        FSMAgent ghost = GhostManager.Instance.GetClosestGhost(pacmanLocation);

        if (agent.CloseEnough(pacmanLocation))
        {
            ScoreHandler.Instance.KillPacman();
        }

        //If timer complete, go to Scatter State
        if (agent.TimerComplete())
        {
            return(new CustomChaseState());
        }

        //If Pacman ate a power pellet, go to Frightened State
        if (PelletHandler.Instance.JustEatenPowerPellet)
        {
            return(new FrightenedState(this));
        }

        if (!ObstacleHandler.Instance.AnyIntersect(pacmanLocation, agent.GetPosition()))
        {
            return(new CustomExcitedChaseState());
        }

        //If we didn't return follow Pacman
        if (ghost is CustomGhost)
        {
            agent.SetTarget(pacmanLocation);
        }
        else
        {
            if (pacmanFacing.x != 0)
            {
                location = ghost.GetPosition() + Vector3.up * 2 * (pacmanLocation.y - ghost.GetPosition().y);
            }
            else
            {
                location = ghost.GetPosition() + Vector3.right * 2 * (pacmanLocation.x - ghost.GetPosition().x);
            }
            GraphNode g = HW3NavigationHandler.Instance.NodeHandler.ClosestNode(location);
            realLocation = g.Location;
            agent.SetTarget(realLocation);
        }
        //Stay in this state
        return(this);
    }
Esempio n. 6
0
    public override State Update(FSMAgent agent)
    {
        //Determine if we've killed Pacman
        Vector3 pacmanLocation = PacmanInfo.Instance.transform.position;

        if (agent.CloseEnough(pacmanLocation))
        {
            ScoreHandler.Instance.KillPacman();
        }

        //If we're done scattering set up return state
        if (agent.TimerComplete())
        {
            return(returnState);
        }

        //Handle Pacman eating power pellet and transitioning to Frightened State
        if (PelletHandler.Instance.JustEatenPowerPellet)
        {
            return(new FrightenedState(this));
        }

        //Handle scatter state movement logic
        if (currHeading == EDGE)
        {
            if (agent.CloseEnough(realScatterPosition))
            {
                currHeading = INNER1;

                agent.SetTarget(realInnerPosition);
            }
        }
        else if (currHeading == INNER1)
        {
            if (agent.CloseEnough(realInnerPosition))
            {
                currHeading = EDGE;

                agent.SetTarget(realScatterPosition);
            }
        }

        //Stay in state
        return(this);
    }
    public override State Update(FSMAgent agent)
    {
        //Check if you killed pacman
        Vector3 pacmanLocation = PacmanInfo.Instance.transform.position;

        if (agent.CloseEnough(pacmanLocation))
        {
            ScoreHandler.Instance.KillPacman();
        }

        //Check if timer completes and should transition to scatter state
        if (agent.TimerComplete())
        {
            return(new ScatterState(new Vector3(ObstacleHandler.Instance.Width, -1 * ObstacleHandler.Instance.Height), this));
        }

        //Check if Pacman ate a power pellet and we should become frightened
        if (PelletHandler.Instance.JustEatenPowerPellet)
        {
            return(new FrightenedState(this));
        }

        //Handle movement logic
        pacmanLocation += PacmanInfo.Instance.Facing * 0.4f;

        if (blinky != null)
        {
            Vector3 relativeVector = pacmanLocation - blinky.GetPosition();
            pacmanLocation = blinky.GetPosition() + relativeVector * 2;
        }

        agent.SetTarget(pacmanLocation);

        //Stay in state
        return(this);
    }