Exemple #1
0
    public SearchInFrenzyState(HeliScript helicopter, float deltaTime, PursuitState comingFrom, HelicopterState afterLosing)
    {
        Debug.Log("Searching");
        //Initializing default, independent vals for behavioral variables
        this.helicopter = helicopter;
        this.comingFrom = comingFrom;
        goBackToPursuit = false;
        ifLost          = afterLosing;

        //Interacting with the frenzy controller
        frenzy = GameObject.Find("FrenzyController").GetComponent <FrenzyMode>();

        rootPos    = frenzy.getLastKnownPlayerPosition();
        rootPos.y += helicopter.vertDistanceFromPlayerInChase;

        //Getting the actual player we're chasing down
        player          = GameObject.Find("Player");
        lastSeenToRight = player.transform.position.x > rootPos.x;


        targetPosition          = rootPos + new Vector3(searchDist, 0, 0);
        targetSpotlightRotation = helicopter.getSpotlight().transform.rotation;
        //These two variables are never updated during pursuit state
        currSpeed = helicopter.speed * helicopter.frenzySpeedBonus;
        spotlightRotationSpeed = helicopter.spotlightRotationSpeedChase;

        //Updates to be ready for the first frame
        updateState(deltaTime);
    }
 public void cannotSeePlayer(HeliScript heli)
 {
     if (seePlayer.Contains(heli))
     {
         seePlayer.Remove(heli);
     }
 }
Exemple #3
0
    /**
     * The default constructor for FlipState.
     * This makes the assumption that we can finish this FlipState with
     * the position of the helicopter after the flip as the root, and then
     * begin the movement pattern from there (starting sine wave at t=0).
     * Because of this, this shouldn't be called by IdleState, as it can
     * result in the helicopter repeatedly changing it's anchor height after
     * every flip, over time making the helicopter descend or ascend significantly
     */
    public FlipState(HeliScript helicopter, float deltaTime, HelicopterState toReturnTo)
    {
        //Initializing default, independent vals for behavioral variables
        this.helicopter  = helicopter;
        timeIntoFlip     = 0f;
        haveFlipped      = false;
        flippedThisFrame = false;
        rootPosition     = toReturnTo.getTargetPosition();
        rootPosition.y  -= helicopter.yOffsetMovement.indexedValue();         //since we adjust for bob, remove from root position
        this.toReturnTo  = toReturnTo;
        justSawPlayer    = false;
        initialSpeed     = (helicopter.getMovingRight()) ? helicopter.speed : -helicopter.speed;

        //initalize debug vars
        //currSpeedDebug = new List<float>();
        //targetPositionDebug = new List<float> ();

        //Shortcuts for accessing frequent variables without reaching back into helicopter each time
        lengthOfFlipInSeconds       = helicopter.flipTime;
        halfwayPoint                = lengthOfFlipInSeconds / 2;
        spotlightRotationBeforeFlip = helicopter.getSpotlight().transform.rotation;

        //Only need to calculate new spotlight rotation once, as it is simply the negated spotlight's rotation along the z axis
        targetSpotlightRotation = calculateNewSpotlightRotation();

        //Similarly, only need to calculate spotlight rotation speed once, as it's just the value that is scaled by time
        //to allow the spotlight to rotate smoothly and end exactly on the rotation point at helicopter.flipTime seconds
        spotlightRotationSpeed = calculateSpotlightRotationSpeed(targetSpotlightRotation.eulerAngles.z);
        //Must call this once during the constructor so that we have values initiated for the first frame of it's instantiation
        updateState(deltaTime);
    }
 private void removeSearcher(HeliScript heli)
 {
     searchers.Remove(heli);
     if (searchers.Count <= 0)
     {
         deactivate();
     }
 }
 public void canSeePlayer(HeliScript heli)
 {
     if (!seePlayer.Contains(heli))
     {
         seePlayer.Add(heli);
     }
     if (!searchers.Contains(heli))
     {
         addSearcher(heli);
     }
 }
 public void deactivate()
 {
     active = false;
     time   = 15f;
     frenzyGUI.SetActive(false);
     for (int i = 0; i < searchers.Count; i += 1)
     {
         HeliScript h = (HeliScript)searchers[i];
         h.resetState();
     }
 }
Exemple #7
0
 //Constructor run when creating IdleState
 public IdleState(HeliScript helicopter, float deltaTime)
 {
     this.helicopter         = helicopter;
     flippedThisFrame        = false;
     horizontalSpeed         = helicopter.speed;
     targetSpotlightRotation = helicopter.getSpotlight().transform.rotation;
     spotlightRotationSpeed  = 0f;
     rootPosition            = helicopter.transform.position;
     traversalDistance       = helicopter.idleRoamingDistanceCovered;
     justSawPlayer           = false;
     updateState(deltaTime);
 }
 private void addSearcher(HeliScript heli)
 {
     if (searchers.Count == 0)
     {
         activate();
     }
     searchers.Add(heli);
     if (searchers.Count == 1)
     {
         heatLevel += 1;
     }
     else if (searchers.Count == 2)
     {
         heatLevel += 2;
     }
 }
Exemple #9
0
    //Constructor run when creating IdleState
    public ReturnToStateState(HeliScript helicopter, float deltaTime, HelicopterState toReturnTo)
    {
        this.helicopter         = helicopter;
        nextState               = toReturnTo;
        targetPosition          = nextState.getTargetPosition();
        spotlightRotationSpeed  = nextState.getSpotlightRotationSpeed();
        targetSpotlightRotation = nextState.getTargetSpotlightRotation();
        currSpeed               = helicopter.speed;

        if ((helicopter.getMovingRight() && toReturnTo.getTargetPosition().x < helicopter.transform.position.x) ||
            (!helicopter.getMovingRight() && toReturnTo.getTargetPosition().x > helicopter.transform.position.x))
        {
            //We gotta turn around first
            toDoFirst = new FlipState(helicopter, deltaTime, this);
        }

        updateState(deltaTime);
    }
    //rootState needs to be the staet that the helicopter will return to after the player escapes
    public PursuitState(HeliScript helicopter, float deltaTime, HelicopterState rootState)
    {
        //Initializing default, independent vals for behavioral variables
        this.helicopter     = helicopter;
        this.cameFrom       = rootState;
        heightFromPlayer    = helicopter.vertDistanceFromPlayerInChase;
        timeSincePlayerSeen = 0f;

        //Getting the actual player we're chasing down
        player = GameObject.Find("Player");

        //Interacting with the frenzy controller
        frenzy = GameObject.Find("FrenzyController").GetComponent <FrenzyMode>();
        frenzy.canSeePlayer(this.helicopter);

        //These two variables are never updated during pursuit state
        currSpeed = helicopter.speed * helicopter.frenzySpeedBonus;
        spotlightRotationSpeed = helicopter.spotlightRotationSpeedChase;

        //Updates to be ready for the first frame
        updateState(deltaTime);
    }