예제 #1
0
    // Update is called once per frame
    void Update()
    {
        Vector2 player_pos = FindObjectOfType <BabyCowScript>().transform.position;

        if (cur_state == CowState.Idle)
        {
            Vector2 pos = transform.position;
            transform.position = new Vector3(pos.x, pos.y - speed * Time.deltaTime, -3);
            if (Vector2.Distance(player_pos, gameObject.transform.position) < flock_range)
            {
                cur_state = CowState.Following;
                FindObjectOfType <BabyCowScript>().AddScore(1);
            }
        }

        if (cur_state == CowState.Following)
        {
            if (Vector2.Distance(player_pos, gameObject.transform.position) < flock_range)
            {
                gameObject.transform.rotation = Quaternion.RotateTowards(rgbd.transform.rotation,
                                                                         Quaternion.Euler(0, 0, master_angle), rot_rate);
                rgbd.transform.Translate(Vector3.up * master_speed);
            }
            else
            {
                float rot_val = 180 * Mathf.Atan((player_pos.y - rgbd.transform.position.y) /
                                                 (player_pos.x - rgbd.transform.position.x)) / Mathf.PI;
                rot_val = player_pos.x - rgbd.transform.position.x < 0 ? rot_val + 90 : rot_val - 90;
                gameObject.transform.rotation =
                    Quaternion.RotateTowards(rgbd.transform.rotation, Quaternion.Euler(0, 0, rot_val), 5.0f);
                rgbd.transform.Translate(Vector3.up * master_speed);
            }
        }
    }
예제 #2
0
 void resetCowStates(CowState cstate)
 {
     for (int i = 0; i < m_catched_array.Count; i++)
     {
         Cow lCow = (Cow)m_catched_array [i];
         lCow.setCowState(cstate);
     }
 }
예제 #3
0
 void UpdateIdleEating()
 {
     if (Time.time - m_timeStateEatingStart >= m_timeInEatingAnim)
     {
         CowState[] futurState = new CowState[2] {
             CowState.IdleStatic,
             CowState.IdleWalking
         };
         int rand = UnityEngine.Random.Range(0, 2);
         setCowState(futurState[rand]);
     }
 }
예제 #4
0
    public void handleCowCrashed(int id, float speedCrashed, CowState state)
    {
        //Debug.Log ("COW CRASH ");
        if (Time.time - m_timeStarted <= 1.0f)
        {
            return;
        }

        Cow cow = getCowByID(id);

        if (cow.getIsUFOCatched() && state != CowState.Dead && !cow.m_pointAlreadyGive)
        {
            if (onNewUFOCow != null)
            {
                onNewUFOCow();
            }
        }
        else
        {
            //Debug.Log("CRASHED OK");

            int numbAffraid = 0;
            //Debug.Log ("Cow Reference: " + cow.name);
            for (int i = 0; i < m_listCow.Count; i++)
            {
                //Debug.Log ("m_listCow[" + i + "]  : " + m_listCow[i]);
                if (m_listCow [i].getId() != id && m_listCow[i].getCowState() != CowState.Dead && !m_listCow[i].getIsUFOCatched())
                {
                    if (Vector3.Distance(m_listCow [i].transform.localPosition, cow.transform.localPosition) <= m_areaWhereCowBeAffraid)
                    {
                        numbAffraid++;
                        m_listCow [i].setCowState(CowState.Affraid);
                    }
                }
            }
            //Debug.Log("TOTO  " + numbAffraid);
            if (numbAffraid >= 2)
            {
                //Debug.Log("PLAY MULTIPLE SOUND");
                PlayerManager.m_instance.addNoise(m_multipleAffraidCowNoise);
                AudioManager.Play("cow/Multiple_CowMoo_Court");
            }
            else
            {
                //Debug.Log("PLAY SOUND");
                PlayerManager.m_instance.addNoise(m_affraidCowNoise);
                AudioManager.Play("cow/Cow_Moo");
            }
        }
    }
예제 #5
0
 public void Update()
 {
     if (!inited)
     {
         _navAgent.enabled = true;
         if (_navAgent.isOnNavMesh)
         {
             inited = true;
             state  = GetNextState();
             InitCurrentState();
         }
         else
         {
             _navAgent.enabled = false;
         }
     }
     else
     {
         if (_gameData.pause)
         {
             _navAgent.enabled = false;
         }
         else
         {
             _navAgent.enabled = true;
             if (state == CowState.RUN_TO_PLAYER)
             {
                 _navAgent.SetDestination(_player.GetPosition());
             }
             else if (CheckCowDetectPlayer())
             {
                 state = CowState.RUN_TO_PLAYER;
                 InitCurrentState();
                 return;
             }
             if (CurrentStateIsFinished())
             {
                 state = GetNextState();
                 InitCurrentState();
             }
         }
     }
 }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="farmId"></param>
        /// <param name="date"></param>
        /// <param name="state"></param>
        /// <returns>int?</returns>
        public int?ApiV1CowsCountGet(Guid?farmId, DateTime?date, CowState state)
        {
            var path = "/api/v1/cows/count";

            path = path.Replace("{format}", "json");

            var    queryParams  = new Dictionary <String, String>();
            var    headerParams = new Dictionary <String, String>();
            var    formParams   = new Dictionary <String, String>();
            var    fileParams   = new Dictionary <String, FileParameter>();
            String postBody     = null;

            if (farmId != null)
            {
                queryParams.Add("FarmId", ApiClient.ParameterToString(farmId));                  // query parameter
            }
            if (date != null)
            {
                queryParams.Add("Date", ApiClient.ParameterToString(date));    // query parameter
            }
            if (state != null)
            {
                queryParams.Add("State", ApiClient.ParameterToString(state));     // query parameter
            }
            // authentication setting, if any
            String[] authSettings = new String[] {  };

            // make the HTTP request
            IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

            if (((int)response.StatusCode) >= 400)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ApiV1CowsCountGet: " + response.Content, response.Content);
            }
            else if (((int)response.StatusCode) == 0)
            {
                throw new ApiException((int)response.StatusCode, "Error calling ApiV1CowsCountGet: " + response.ErrorMessage, response.ErrorMessage);
            }

            return((int?)ApiClient.Deserialize(response.Content, typeof(int?), response.Headers));
        }
예제 #7
0
    //La vache ne peut se déplacer qu'entre [-9;4] en X
    void UpdateIdleWalking()
    {
        //Debug.Log ("DISTANCE : " + Vector2.Distance(this.transform.localPosition,m_targetDestination));

        float _oldZ = this.transform.position.z;

        Vector2 newPos2D = Vector2.Lerp(
            this.transform.position, m_targetDestination, Time.deltaTime * m_cowSpeed / Vector2.Distance(this.transform.localPosition, m_targetDestination
                                                                                                         ));

        this.transform.position = new Vector3(newPos2D.x, newPos2D.y, _oldZ);


        if (Time.time - m_timeStateWalkingStart >= m_timeInWalkingAnim || Vector2.Distance(this.transform.localPosition, m_targetDestination) <= float.Epsilon)
        {
            CowState[] futurState = new CowState[2] {
                CowState.IdleStatic,
                CowState.IdleEating
            };
            int rand = UnityEngine.Random.Range(0, 2);
            setCowState(futurState[rand]);
        }
    }
예제 #8
0
        public void BeTippedOver()
        {
            if (Moo != null)
            {
                // Cow states by random ganerator
                var state = new CowState();
                switch (new Random().Next() % 3)
                {
                    case 0:
                        state = CowState.Awake;
                        break;
                    case 1:
                        state = CowState.Sleeping;
                        break;
                    case 2:
                        state = CowState.Dead;
                        break;
                    default: break;
                }

                Moo(this, new CowTippedEventArgs(state));
            }
        }
예제 #9
0
 public CowTippedEventArgs(CowState state)
 {
     State = state;
 }
예제 #10
0
 public CowTippedEventArgs(CowState currentState)
 {
     CurrentCowState = currentState;
 }
예제 #11
0
    public void handleCowCrashed(int id,float speedCrashed,CowState state)
    {
        //Debug.Log ("COW CRASH ");
        if (Time.time - m_timeStarted <= 1.0f) {
            return;
        }

        Cow cow = getCowByID (id);

        if (cow.getIsUFOCatched () && state != CowState.Dead && !cow.m_pointAlreadyGive) {
            if (onNewUFOCow != null) {
                onNewUFOCow ();
            }
        } else {
            //Debug.Log("CRASHED OK");

            int numbAffraid = 0;
            //Debug.Log ("Cow Reference: " + cow.name);
            for (int i = 0; i<m_listCow.Count; i++) {
                //Debug.Log ("m_listCow[" + i + "]  : " + m_listCow[i]);
                if (m_listCow [i].getId () != id && m_listCow[i].getCowState() != CowState.Dead && !m_listCow[i].getIsUFOCatched()) {
                    if (Vector3.Distance (m_listCow [i].transform.localPosition, cow.transform.localPosition) <= m_areaWhereCowBeAffraid) {
                        numbAffraid++;
                        m_listCow [i].setCowState (CowState.Affraid);
                    }
                }
            }
            //Debug.Log("TOTO  " + numbAffraid);
            if(numbAffraid >=2){
                //Debug.Log("PLAY MULTIPLE SOUND");
                PlayerManager.m_instance.addNoise (m_multipleAffraidCowNoise);
                AudioManager.Play ("cow/Multiple_CowMoo_Court");
            }else{
                //Debug.Log("PLAY SOUND");
                PlayerManager.m_instance.addNoise (m_affraidCowNoise);
                AudioManager.Play ("cow/Cow_Moo");
            }
        }
    }
예제 #12
0
    //Getter Setter
    public void setCowState(CowState newState)
    {
        m_cowState = newState;
        StopAllAnim();
        switch (m_cowState)
        {
        case CowState.IdleStatic:
            m_timeStateStaticStart = Time.time;
            //TODO: Lancer animation de static
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.white);
            }
            break;

        case CowState.IdleWalking:
            m_animator.SetBool("isWalking", true);
            if (UnityEngine.Random.Range(0, 3) == 0)
            {
                AudioManager.Play("cow/cow_cloche");
            }
            m_timeStateWalkingStart = Time.time;
            float dest = UnityEngine.Random.Range(m_minWalkArea, m_maxWalkArea);

            m_targetDestination = new Vector2(dest, this.transform.localPosition.y);

            if (this.transform.localPosition.x < m_targetDestination.x)
            {
                this.transform.eulerAngles = new Vector3(0f, 180f, 0f);
            }
            else
            {
                this.transform.eulerAngles = new Vector3(0f, 0f, 0f);
            }

            //[-9;3.6]
            //TODO: Lancer animation de walking
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.red);
            }
            break;

        case CowState.IdleEating:
            m_animator.SetBool("isEating", true);
            m_timeStateEatingStart = Time.time;
            //TODO: Lancer animation de Eating
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.green);
            }
            break;

        case CowState.BeingLiftToShip:
            //TODO: stop all animation and play Being lift anim
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.blue);
            }
            if (onBeingLiftToShipEnter != null)
            {
                onBeingLiftToShipEnter(m_id);
            }
            break;

        case CowState.Flying:
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.white);
            }
            if (onFlyingEnter != null)
            {
                onFlyingEnter(m_id);
            }
            break;

        case CowState.Lifted:
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.black);
            }
            setIsUFOCatched(true);
            m_timeStateLiftedStart = Time.time;
            if (onLiftedEnter != null)
            {
                onLiftedEnter(m_id);
            }

            break;

        case CowState.Crashed:
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.red);
            }
            //Debug.Log ("SPEED AU CALCUL : " + m_flyingSpeed);
            //Avec les distances liées à la maquette, position possible de la cow en [-4.5;1]
            //La vitesse à l'arrivée est comprise entre [0;10]
            //Si la cow est lachée à Pos, elle aura à l'arrivée la vitesse Vit :
            //Pos -> Vit
            //-		-> 0
            //-3.75		-> 5
            //-1.75		-> 5.7
            //-0.3125	-> 9
            //1			-> 10
            //Debug.Log("TOTO "+m_flyingSpeed);
            if (m_flyingSpeed <= m_cowAffraidIfSpeedOver)
            {
                setCowState(CowState.IdleStatic);
                if (m_isUFOCatched)
                {
                    //this.GetComponent<Rigidbody2D>().isKinematic = true;
                    //this.GetComponent<BoxCollider2D>().enabled = false;
                }
            }
            else if (m_flyingSpeed <= m_cowDieIfSpeedOver)
            {
                if (m_isUFOCatched)
                {
                    setCowState(CowState.IdleStatic);
                    //this.GetComponent<Rigidbody2D>().isKinematic = true;
                    //this.GetComponent<BoxCollider2D>().enabled = false;
                }
                else
                {
                    setCowState(CowState.Affraid);
                }
            }
            else
            {
                setCowState(CowState.Dead);
            }
            if (onCrashedEnter != null)
            {
                onCrashedEnter(m_id, m_flyingSpeed, m_cowState);
                if (m_isUFOCatched)
                {
                    m_pointAlreadyGive = true;
                }
            }

            break;

        case CowState.Affraid:
            m_timeStateAffraidStart = Time.time;
            if (isDebug)
            {
                GetComponent <SpriteRenderer>().material.SetColor("_Color", Color.yellow);
            }
            m_localPosAffraidStart = this.transform.localPosition;
            break;

        case CowState.Dead:

            m_animator.SetBool("isDead", true);
            Vector3 vect = this.transform.localPosition;
            vect.y = m_startLocalPosition.y - 0.4f;
            this.transform.localPosition = vect;
            if (isDebug)
            {
                GetComponent <SpriteRenderer> ().material.SetColor("_Color", Color.black);
            }
            m_DeadAnim.SetActive(true);


            this.GetComponent <Rigidbody2D> ().isKinematic = true;
            this.GetComponent <BoxCollider2D> ().enabled   = false;
            if (onDeadEnter != null)
            {
                onDeadEnter(m_id);
            }
            Light[] lights = gameObject.GetComponentsInChildren <Light> ();
            for (int i = 0; i < lights.Length; i++)
            {
                lights [i].enabled = false;
                lights [i].gameObject.SetActive(false);
            }
            lights = null;
            break;
        }
    }
예제 #13
0
        public Cow()
        {
            int index = new Random().Next(0, 3);

            this.State = (CowState)index;
        }
예제 #14
0
 // Start is called before the first frame update
 void Start()
 {
     cur_state = CowState.Idle;
     rgbd      = gameObject.GetComponent <Rigidbody2D>();
     rot_rate  = Random.Range(8f, 12f);
 }
예제 #15
0
 public CowEventsArgs(CowState currentState)
 {
     CurrentState = currentState;
 }
예제 #16
0
 public void SetState(CowState newState)
 {
     state = newState;
 }
예제 #17
0
    //La vache ne peut se déplacer qu'entre [-9;4] en X
    void UpdateIdleWalking()
    {
        //Debug.Log ("DISTANCE : " + Vector2.Distance(this.transform.localPosition,m_targetDestination));

        float _oldZ = this.transform.position.z;

        Vector2 newPos2D = Vector2.Lerp(
                this.transform.position, m_targetDestination, Time.deltaTime* m_cowSpeed/Vector2.Distance(this.transform.localPosition,m_targetDestination
                ));
        this.transform.position = new Vector3(newPos2D.x, newPos2D.y, _oldZ);

        if (Time.time - m_timeStateWalkingStart >= m_timeInWalkingAnim || Vector2.Distance(this.transform.localPosition,m_targetDestination) <= float.Epsilon ) {
            CowState[] futurState = new CowState[2]{
                CowState.IdleStatic,
                CowState.IdleEating
            };
            int rand = UnityEngine.Random.Range(0,2);
            setCowState(futurState[rand]);
        }
    }
예제 #18
0
 void UpdateIdleStatic()
 {
     if (Time.time - m_timeStateStaticStart >= m_timeInStaticAnim) {
         CowState[] futurState = new CowState[2]{
             CowState.IdleWalking,
             CowState.IdleEating
         };
         int rand = UnityEngine.Random.Range(0,2);
         setCowState(futurState[rand]);
     }
 }
예제 #19
0
    //Getter Setter
    public void setCowState(CowState newState)
    {
        m_cowState = newState;
        StopAllAnim ();
        switch (m_cowState) {
            case CowState.IdleStatic:
                m_timeStateStaticStart = Time.time;
                //TODO: Lancer animation de static
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.white);
                }
            break;
            case CowState.IdleWalking:
                m_animator.SetBool ("isWalking", true);
                if(UnityEngine.Random.Range(0,3) ==0) {
                    AudioManager.Play("cow/cow_cloche");
                }
                m_timeStateWalkingStart = Time.time;
                float dest = UnityEngine.Random.Range (m_minWalkArea,m_maxWalkArea);

                m_targetDestination = new Vector2(dest,this.transform.localPosition.y);

                if(this.transform.localPosition.x < m_targetDestination.x){
                    this.transform.eulerAngles = new Vector3(0f,180f,0f);
                }else{
                this.transform.eulerAngles = new Vector3(0f,0f,0f);
            }

                //[-9;3.6]
                //TODO: Lancer animation de walking
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.red);
                }
                break;
            case CowState.IdleEating:
                m_animator.SetBool ("isEating", true);
                m_timeStateEatingStart = Time.time;
                //TODO: Lancer animation de Eating
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.green);
                }
            break;
            case CowState.BeingLiftToShip:
                //TODO: stop all animation and play Being lift anim
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.blue);
                }
                if(onBeingLiftToShipEnter != null){
                    onBeingLiftToShipEnter(m_id);
                }
            break;
            case CowState.Flying:
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.white);
                }
                if(onFlyingEnter != null){
                    onFlyingEnter(m_id);
                }
                break;
            case CowState.Lifted:
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.black);
                }
                setIsUFOCatched(true);
                m_timeStateLiftedStart = Time.time;
                if(onLiftedEnter != null){
                    onLiftedEnter(m_id);
                }

                break;

            case CowState.Crashed:
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.red);
                }
                //Debug.Log ("SPEED AU CALCUL : " + m_flyingSpeed);
                //Avec les distances liées à la maquette, position possible de la cow en [-4.5;1]
                //La vitesse à l'arrivée est comprise entre [0;10]
                //Si la cow est lachée à Pos, elle aura à l'arrivée la vitesse Vit :
                //Pos -> Vit
                //-		-> 0
                //-3.75		-> 5
                //-1.75		-> 5.7
                //-0.3125	-> 9
                //1			-> 10
                //Debug.Log("TOTO "+m_flyingSpeed);
                if(m_flyingSpeed <= m_cowAffraidIfSpeedOver){
                    setCowState(CowState.IdleStatic);
                    if(m_isUFOCatched){
                        //this.GetComponent<Rigidbody2D>().isKinematic = true;
                        //this.GetComponent<BoxCollider2D>().enabled = false;
                    }

                }else if(m_flyingSpeed <= m_cowDieIfSpeedOver){
                    if(m_isUFOCatched){
                        setCowState(CowState.IdleStatic);
                        //this.GetComponent<Rigidbody2D>().isKinematic = true;
                        //this.GetComponent<BoxCollider2D>().enabled = false;
                    }else{
                        setCowState(CowState.Affraid);
                    }
                }else{
                    setCowState(CowState.Dead);
                }
                if(onCrashedEnter != null){
                   		onCrashedEnter(m_id,m_flyingSpeed,m_cowState);
                    if(m_isUFOCatched){
                        m_pointAlreadyGive = true;
                    }
                }

            break;

            case CowState.Affraid:
                m_timeStateAffraidStart = Time.time;
                if(isDebug){
                    GetComponent<SpriteRenderer>().material.SetColor("_Color", Color.yellow);
                }
                m_localPosAffraidStart = this.transform.localPosition;
                break;

        case CowState.Dead:

            m_animator.SetBool ("isDead", true);
            Vector3 vect = this.transform.localPosition;
            vect.y = m_startLocalPosition.y - 0.4f;
            this.transform.localPosition = vect;
            if (isDebug) {
                GetComponent<SpriteRenderer> ().material.SetColor ("_Color", Color.black);
            }
            m_DeadAnim.SetActive (true);

            this.GetComponent<Rigidbody2D> ().isKinematic = true;
            this.GetComponent<BoxCollider2D> ().enabled = false;
            if (onDeadEnter != null) {
                onDeadEnter (m_id);
            }
            Light[] lights = gameObject.GetComponentsInChildren<Light> ();
            for (int i = 0; i < lights.Length; i++) {
                lights [i].enabled = false;
                lights [i].gameObject.SetActive (false);
            }
            lights = null;
            break;
        }
    }
 public CowTippedEventArgs(CowState currState)
 {
     currCowState = currState;
 }
 public CowTippedEventArgs(CowState currentCowState)
 {
     this.CurrentCowState = currentCowState;
 }
예제 #22
0
 void resetCowStates(CowState cstate)
 {
     for (int i = 0; i <m_catched_array.Count; i++) {
         Cow lCow = (Cow)m_catched_array [i];
         lCow.setCowState(cstate);
     }
 }