Ejemplo n.º 1
0
    /// <summary>
    /// Generates a percept for the given instance of time that is meant to represent
    /// all data relevant to the agent for making a desicion.
    /// </summary>
    /// <returns>The percept at this instance.</returns>
    Percept getPerceptAtThisInstance()
    {
        // Make a new Percept
        Percept newPercept = new Percept();

        // Formula for distance of chickens, necessary for team calculations
        //              The distance we are away from our target.
        //              float distanceFromTarget = Vector3.Distance (control.transform.position, target.transform.position);



        // Calculate values for all of percept fields in order of struct definition
        float curHealth = control.getCurrentHealth();
        // Find number of teammates and:
        //              public float[] teamatesHealths;
        //              public float[] teamatesDistancesFromUs;
        //              public float[] teamatesDistancesFromTarget;

        float targetHealth = target.getCurrentHealth();
        //              public int numOfTargetAllies;
        //              public float[] targetsAlliesHealths;
        //              public float[] targetsAlliesDistancesFromTarget;
        //              public float[] targetsAlliesDistancesFromUs;
        ChickenState targetCurrentState = target.getCurrentChickenState();

        // Now assign all values to the struct in order of struct definition
        newPercept.curHealth    = curHealth;
        newPercept.targetHealth = targetHealth;
        newPercept.targetState  = targetCurrentState;

        // Finally return the new Percept instance
        return(newPercept);
    }
Ejemplo n.º 2
0
        /// <summary>
        /// changes the current state of the chicken to its next state as long as it isn't in its oldest state.
        /// </summary>
        public override void GoToFuture()
        {
            switch (state)
            {
            case ChickenState.PastNothing:
                state      = ChickenState.Egg;
                Collidable = true;
                break;

            case ChickenState.Egg:
                Game1.particleManager.AddGenericParticleSystem(new AnimatedTexture(0, 16, 16, Game1.staticTextureManager["SparkParticle"]), position);
                state      = ChickenState.Chick;
                Collidable = true;
                break;

            case ChickenState.Chick:
                Game1.particleManager.AddGenericParticleSystem(new AnimatedTexture(0, 16, 16, Game1.staticTextureManager["FeatherParticle"]), position);
                state      = ChickenState.Chicken;
                Collidable = true;
                break;

            case ChickenState.Chicken:
                state      = ChickenState.Bones;
                Collidable = true;
                break;

            case ChickenState.Bones:
                state      = ChickenState.FutureNothing;
                Collidable = false;
                break;

            case ChickenState.FutureNothing:     //this should never happen
                break;
            }
        }
Ejemplo n.º 3
0
 public void DistractedTo(GameObject obj)
 {
     ChickenState = ChickenState.Lured;
     TimeToUpdateNavmeshDestination = NavmeshUpdateRate;
     _corn = obj.GetComponent <Corn>();
     NavMeshAgent.stoppingDistance = .5f;
 }
Ejemplo n.º 4
0
    void ChangeState(ChickenState newState)
    {
        StopAllCoroutines();
        switch (state)
        {
        case ChickenState.IDLE:
            StartCoroutine("IDLE");
            break;

        case ChickenState.EAT:
            GetComponent <Animator>().SetTrigger("Eat");
            StartCoroutine("EAT");
            break;

        case ChickenState.TURNHEAD:
            GetComponent <Animator>().SetTrigger("TurnHead");
            StartCoroutine("TURNHEAD");
            break;

        case ChickenState.WALK:
            int idWayPoint = Random.Range(0, gameManager.chickenWayPoints.Length);
            destination            = gameManager.chickenWayPoints[idWayPoint].position;
            agent.stoppingDistance = 0;
            agent.destination      = destination;

            StartCoroutine("WALK");

            break;
        }
    }
    /// <summary>
    /// Begins the dash "animation".
    /// Dashing forward will count as an attack.
    /// Will dashing the player has no control.
    /// Dashing has a small "recovery" when the player can still not move
    /// </summary>
    /// <param name="direction">Direction.</param>
    void beginDash(Vector3 direction)
    {
        //if the dash is happening in no direction then we can't dash
        if (direction.x == 0 && direction.z == 0)
        {
            return;
        }

        if (!canDash())
        {
            return;
        }

        if (direction == Vector3.forward)
        {
            transform.FindChild("hitbox").GetComponent <Rigidbody>().isKinematic  = false;
            transform.FindChild("hitbox").GetComponent <SphereCollider>().enabled = true;
        }

        //Mark where we begin so we know when to end
        dashStartTime = Time.time;

        //Change state to dashing
        currentState = ChickenState.Dashing;

        //Set the direction of the dash for the update function
        dashingDirection = direction;

        //give alittle hop
        movementDirection.y = 3;
    }
Ejemplo n.º 6
0
 /// <summary>
 /// Gets or sets <c>AnimatedTexture</c>s of the Chicken, indexed by state
 /// </summary>
 /// <param name="c">The state the chicken is in</param>
 /// <returns>The <c>AnimatedTexture</c> for that state of the chicken</returns>
 public AnimatedTexture this[ChickenState s]
 {
     get
     {
         return(textures[s]);
     }
 }
    /// <summary>
    /// If the chicken is currentely dashing then it leaves the dashing state
    /// and goes back into a free state open to control.
    /// </summary>
    void stopDashing()
    {
        if (currentState != ChickenState.Dashing)
        {
            return;
        }

        dashingDirection = Vector3.zero;
        currentState     = ChickenState.Free;
        transform.FindChild("hitbox").GetComponent <Rigidbody>().isKinematic  = true;
        transform.FindChild("hitbox").GetComponent <SphereCollider>().enabled = false;
    }
    /// <summary>
    /// Used to transition to the dead state.
    /// </summary>
    void enterDeadState()
    {
        currentState = ChickenState.Dead;

        GameState.getInstance().removeCharacter(this);

        timeOfDeath = Time.time;

        SpecialEffectsFactory.createEffect(transform.position, SpecialEffectType.ChickenDeath);

        if (gameObject.GetComponent <PhotonView> () != null)
        {
            ChickenFactory.createNetworkPlayerChicken(new Vector3(0, 1, 0), ChickenTeam.None);
            PhotonNetwork.Destroy(gameObject);
        }
    }
    /// <summary>
    /// Update function called while the chicken is in the taking damage state.
    /// Acts as a stun and animates the chicken indicating damage was taken
    /// </summary>
    void takeDamageUpdate()
    {
        if (currentState != ChickenState.TakingDamage)
        {
            return;
        }

        //amount of time player is unable to move
        float stunTime = .2f;

        if (Time.time - damageStartTime > stunTime)
        {
            transform.FindChild("graphics").GetComponent <MeshRenderer>().material.color = Color.white;
            currentState = ChickenState.Free;
        }
    }
Ejemplo n.º 10
0
        IEnumerator CrtEatCorn()
        {
            while (_corn.Health > 0 || _corn != null)
            {
                _corn.Health -= EatSubstraction;
                yield return(new WaitForSecondsRealtime(EatingSpeed));
            }

            _corn        = null;
            IsEatingCorn = false;
            IsPecking    = false;
            NavMeshAgent.GoToShortestWaypointLocation(Waypoints, ref CurrentWaypointIndex);
            ChickenState = ChickenState.Moving;
            Animator.SetFloat("speed", 1);
            Animator.SetBool("pecking", false);
            NavMeshAgent.stoppingDistance = 0;
            //avmeshUpdateRate = .1f;
        }
Ejemplo n.º 11
0
        IEnumerator GoToNextWaypoint()
        {
            IsPecking = (Random.Range(0f, 1f) > .3f) ? true : false;
            Animator.SetBool("pecking", IsPecking);
            Animator.SetFloat("speed", 0);

            ChickenState = ChickenState.Idle;
            float randomIdleTime = Random.Range(MinMaxWaitBeforeMovingToNextWaypoint.x, MinMaxWaitBeforeMovingToNextWaypoint.y);

            yield return(new WaitForSecondsRealtime(randomIdleTime));

            CurrentWaypointIndex = (CurrentWaypointIndex + 1) % Waypoints.transform.childCount;
            InstantTurn(Waypoints.GetChild(CurrentWaypointIndex));
            NavMeshAgent.SetDestination(Waypoints.GetChild(CurrentWaypointIndex).transform.position);
            IsPecking    = false;
            ChickenState = ChickenState.Moving;
            Animator.SetBool("pecking", false);
            Animator.SetFloat("speed", 1);
        }
    public void takeDamage(float damageAmount)
    {
        if (currentState == ChickenState.Dead)
        {
            return;
        }

        SpecialEffectsFactory.createEffect(transform.position, SpecialEffectType.TakeDamage);

        // added check to see if player is dead
        if (health <= 0)
        {
            enterDeadState();
            return;
        }

        currentState    = ChickenState.TakingDamage;
        damageStartTime = Time.time;
        transform.FindChild("graphics").GetComponent <MeshRenderer>().material.color = Color.red;
        health -= damageAmount;
        print("health hit");
    }
    /// <summary>
    /// Used to transition to the dead state.
    /// </summary>
    void enterDeadState()
    {
        currentState = ChickenState.Dead;
        GameState.getInstance ().removeCharacter (this);
        timeOfDeath = Time.time;

        SpecialEffectsFactory.createEffect (transform.position, SpecialEffectType.ChickenDeath);

        if (gameObject.GetComponent<PhotonView> () != null) {
            GameObject.Find("Scripts").GetComponent<MatchmakingBehavior>().spawnLocalPlayer();
            PhotonNetwork.Destroy(gameObject);
        }
    }
    /// <summary>
    /// Used to transition to the dead state.
    /// </summary>
    void enterDeadState()
    {
        currentState = ChickenState.Dead;

        GameState.getInstance ().removeCharacter (this);

        timeOfDeath = Time.time;

        SpecialEffectsFactory.createEffect (transform.position, SpecialEffectType.ChickenDeath);

        if (gameObject.GetComponent<PhotonView> () != null) {

            ChickenFactory.createNetworkPlayerChicken(new Vector3(0,1,0),ChickenTeam.None);
            PhotonNetwork.Destroy(gameObject);

        }
    }
    /// <summary>
    /// Update function called while the chicken is in the taking damage state.
    /// Acts as a stun and animates the chicken indicating damage was taken
    /// </summary>
    void takeDamageUpdate()
    {
        if (currentState != ChickenState.TakingDamage) {
            return;
        }

        //amount of time player is unable to move
        float stunTime = .2f;

        if (Time.time - damageStartTime > stunTime) {
            transform.FindChild("graphics").GetComponent<MeshRenderer>().material.color = Color.white;
            currentState = ChickenState.Free;
        }
    }
    /// <summary>
    /// If the chicken is currentely dashing then it leaves the dashing state
    /// and goes back into a free state open to control.
    /// </summary>
    void stopDashing()
    {
        if (currentState != ChickenState.Dashing) {
            return;
        }

        dashingDirection = Vector3.zero;
        currentState = ChickenState.Free;
        transform.FindChild("hitbox").GetComponent<Rigidbody>().isKinematic = true;
        transform.FindChild("hitbox").GetComponent<SphereCollider>().enabled = false;
    }
 public void takeDamage(float damageAmount)
 {
     currentState = ChickenState.takingDamage;
     damageStartTime = Time.time;
     transform.FindChild("graphics").GetComponent<MeshRenderer>().material.color = Color.red;
     health -= damageAmount;
     print ("health hit");
 }
Ejemplo n.º 18
0
 public void SetState(ChickenState newState)
 {
     state = newState;
 }
    public void takeDamage(float damageAmount)
    {
        if (currentState == ChickenState.Dead) {
            return;
        }

        SpecialEffectsFactory.createEffect (transform.position, SpecialEffectType.TakeDamage);

        // added check to see if player is dead
        if (health <= 0) {
            enterDeadState();
            return;
        }

        currentState = ChickenState.TakingDamage;
        damageStartTime = Time.time;
        transform.FindChild("graphics").GetComponent<MeshRenderer>().material.color = Color.red;
        health -= damageAmount;
        print ("health hit");
    }
    /// <summary>
    /// Begins the dash "animation".
    /// Dashing forward will count as an attack.
    /// Will dashing the player has no control.
    /// Dashing has a small "recovery" when the player can still not move
    /// </summary>
    /// <param name="direction">Direction.</param>
    void beginDash(Vector3 direction)
    {
        //if the dash is happening in no direction then we can't dash
        if (direction.x == 0 && direction.z == 0) {
            return;
        }

        if (!canDash ()) {
            return;
        }

        if (direction == Vector3.forward) {
            transform.FindChild("hitbox").GetComponent<Rigidbody>().isKinematic = false;
            transform.FindChild("hitbox").GetComponent<SphereCollider>().enabled = true;
        }

        //Mark where we begin so we know when to end
        dashStartTime = Time.time;

        //Change state to dashing
        currentState = ChickenState.Dashing;

        //Set the direction of the dash for the update function
        dashingDirection = direction;

        //give alittle hop
        movementDirection.y = 3;
    }
Ejemplo n.º 21
0
 /// <summary>
 /// Creates a chicken at given position and at given state. Collidable by default, (if we find a need for uncollidable chickens we'll need an extra parameter here).
 /// </summary>
 /// <param name="position">The starting position of the chicken.</param>
 /// <param name="state">The starting state of the chicken</param>
 public Chicken(Rectangle position, ChickenState state, double scale, Level level) : base(position, true, scale, level)
 {
     this.state = state;
     textures   = LoadTextures <ChickenState>(2);
 }