Ejemplo n.º 1
0
    /// <summary>
    /// This function updates the location of the target depending no Ghost type and Movement Type - Some of the movement is also coded in the Spook and Kill function
    /// </summary>
    /// <returns></returns>
    Vector2 UpdadeTarget()
    {
        // I inspired my behaviours here: http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior

        if (movementMode == MovementMode.Chase)
        {
            switch (ghostName)
            {
            case GhostName.Blinky:     // he follows pacman
                target = (Vector2)pacmanTransform.position;
                break;

            case GhostName.Pinky:     // he tried to ambush pacman by going 4 tiles in front of him
                target = (Vector2)pacmanTransform.position + 4 * pacmanController.getDirection();

                break;

            case GhostName.Inky:
                Vector2 tempTarget = (Vector2)pacmanController.transform.position + 2 * pacmanController.getDirection();
                target = (Vector2)blinkyTransform.position + (tempTarget - (Vector2)blinkyTransform.position) * -2;
                break;

            case GhostName.Clyde:
                if (Vector2.Distance(transform.position, (Vector2)pacmanTransform.position) > 8)
                {
                    target = (Vector2)pacmanTransform.position;
                }
                else
                {
                    target = scatterNodes[0].transform.position;
                }
                break;
            }
        }

        else if (movementMode == MovementMode.Scatter)
        {
            for (int i = 0; i < scatterNodes.Length; i++)
            {
                if (targetNode == scatterNodes[i])                                           // is it in any of the scatter nodes?
                {
                    target = scatterNodes[(i + 1) % scatterNodes.Length].transform.position; //if so, go to the next one and break the cycle
                    break;
                }
                if (i == scatterNodes.Length - 1) // if we are in the end and the cycle didn't break go to the first point
                {
                    target = scatterNodes[0].transform.position;
                }
            }
        }

        else if (movementMode == MovementMode.Spooked)                                                         //they cant start freightened because they have no target node yet
        {
            target = targetNode.neighbours[Random.Range(0, targetNode.numberOfNeighbours)].transform.position; //goes to a random node neighbour to the current node
        }

        return(target);
    }