Exemplo n.º 1
0
    void OnMouseUp()
    {
        // When mouse released, act based on accumulated drag
        is_drag = false;
        double drag_time = Time.time - drag_start_time;

        Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);

        Debug.Log("Dragged for " + drag_time);

        // A short drag is registered as a click, causing cat to approach user
        if (drag_time < 0.1)
        {
            Camera.main.transform.LookAt(cat_transform);             // main camera will follow cat
            agent.destination         = in_front_of_user_position;   // cat approaches user
            current_state             = CatStates.User_Interaction;
            time_of_last_state_change = Time.time;

            Debug.Log("Cat clicked on");
        }
        // For longer drags, count as petting
        else if (current_state != CatStates.Sleeping && current_state != CatStates.Eating)
        {
            if (current_state != CatStates.Happy)
            {
                current_state = CatStates.Happy;
                Debug.Log("Cat State: Happy");
                happy_time = 0F;
                time_of_last_state_change = Time.time;
                heart_icon.GetComponent <Renderer>().enabled = true;
            }
            happy_time += (float)(drag_time * cat_personality.joyfullness);
        }
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        hunger_slider       = GameObject.Find("HungerSlider").GetComponent <Slider> ();
        sleep_slider        = GameObject.Find("SleepSlider").GetComponent <Slider> ();
        hunger_slider_fill  = GameObject.Find("Hunger Slider Fill").GetComponent <Image> ();
        sleep_slider_fill   = GameObject.Find("Sleep Slider Fill").GetComponent <Image> ();
        high_stat_bar_color = new Color32(10, 200, 55, 255);
        low_stat_bar_color  = new Color32(226, 214, 29, 255);

        heart_icon  = GameObject.Find("catsim_heart_icon").GetComponent <SpriteRenderer> ();
        hungry_icon = GameObject.Find("catsim_hungry_icon").GetComponent <SpriteRenderer> ();
        sleep_icon  = GameObject.Find("catsim_sleep_icon").GetComponent <SpriteRenderer> ();

        heart_icon.GetComponent <Renderer>().enabled  = false;
        hungry_icon.GetComponent <Renderer>().enabled = false;
        sleep_icon.GetComponent <Renderer>().enabled  = false;

        can_eat = false;

        current_state = CatStates.Wandering;
        agent         = GetComponent <NavMeshAgent>();
        cat_transform = GetComponent <Transform>();
        cat_toy       = GameObject.Find("Cat Toy");
        food_bowl     = GameObject.Find("Food Bowl");
        kibble        = GameObject.Find("Cat Food");

        time_of_last_state_change = Time.time;

        in_front_of_user_position     = new Vector3(0F, 0.5F, -3F);
        default_camera_focus_position = new Vector3(0F, 0F, 0F);
        default_camera_rotation       = new Vector3(7F, 0, 0);
        default_camera_position       = new Vector3(0, 3.5F, -9F);
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (_coolDownToBreakItem > 0)
        {
            _coolDownToBreakItem -= Time.deltaTime;
        }

        switch (_catState)
        {
        case CatStates.WALKING_AROUND:
            // choose point
            // walk to point
            if (_coolDownToBreakItem <= 0 && _listOfItems.Count > 0)
            {
                _itemToBreak       = ChooseItem();
                _agent.destination = _itemToBreak.transform.position;
                _agent.SearchPath();
                StartCoroutine(GoingToBreakItem());
                _catState = CatStates.GOING_TO_BREAK;
            }
            break;

        case CatStates.GOING_TO_BREAK:
            break;

        default:
            break;
        }

        _anim.SetFloat("Horizontal", _agent.velocity.x);
        _anim.SetFloat("Vertical", _agent.velocity.y);
        _anim.SetFloat("Speed", _agent.velocity.sqrMagnitude);
    }
Exemplo n.º 4
0
    void OnMouseUp()
    {
        // When mouse released, act based on accumulated drag
        is_drag = false;
        double drag_time = Time.time - drag_start_time;

        Debug.Log("Dragged for " + drag_time);

        // A short drag is registered as a click, causing cat to approach user
        if (drag_time < 0.1)
        {
            Vector3 new_position = new Vector3(0, 0, 0);
            agent.destination = new_position;
            Debug.Log("Cat clicked on");

            // For longer drags, count as petting
        }
        else if (current_state != CatStates.Sleeping && current_state != CatStates.Eating)
        {
            if (current_state != CatStates.Happy)
            {
                current_state = CatStates.Happy;
                Debug.Log("Cat State: Happy");
                happy_time = 0F;
                time_of_last_state_change = Time.time;
                heart_icon.GetComponent <Renderer>().enabled = true;
            }
            happy_time += (float)(drag_time * cat_personality.joyfullness);
        }
    }
Exemplo n.º 5
0
    float floor_size_modifier = 2.5F;  // The floor is 5 by 5 units wide, so the random position can be anywhere between (-2.5, -2.5, 0) and (2.5, 2.5, 0)

    // Start is called before the first frame update
    void Start()
    {
        current_state             = CatStates.Wander;
        agent                     = GetComponent <NavMeshAgent>();
        time_of_last_state_change = Time.time;

        //Debug.Log("Cat's Starting Position: " + GetComponent<Transform>().position);
    }
Exemplo n.º 6
0
    IEnumerator GoingToBreakItem()
    {
        float _cooldown = 2f;

        while (_agent.remainingDistance >= _agent.radius || _cooldown > 0)
        {
            _cooldown -= .5f;
            yield return(new WaitForSeconds(.5f));
        }
        _anim.SetTrigger("Hit");
        _coolDownToBreakItem = timeToBreakItemInSeconds;
        _catState            = CatStates.WALKING_AROUND;
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        if (current_state == CatStates.Idle)
        {
            // Cat does nothing; waits for player input or new state change
            //Debug.Log("Cat's Current Position: " + GetComponent<Transform>().position);

            if ((Time.time - time_of_last_state_change) > change_state_delay)
            {
                current_state             = CatStates.Wander;
                time_of_last_state_change = Time.time;
            }
        }
        if (current_state == CatStates.Wander)
        {
            Vector3 random_position = new Vector3(Random.value * floor_size_modifier, Random.value * floor_size_modifier, Random.value * floor_size_modifier);             // Random.value eturns a random number between 0.0 [inclusive] and 1.0 [inclusive].
            Debug.Log("Cat's Target Position: " + GetComponent <Transform>().position);
            agent.destination = random_position;

            current_state = CatStates.Idle;
        }
    }
Exemplo n.º 8
0
 public void ClearEnemies()
 {
     try{
         if (isCharged)
         {
             if (animator.GetInteger("cat_int") != 2)
             {
                 animator.SetInteger("cat_int", 2);
                 clearingTimer = Time.time + clearingTime;
             }
             clearEnemiesEvent(1);
             if (Time.time > clearingTimer)
             {
                 currentState = CatStates.stationary;
                 isCharged = false;
                 chargeTimer = chargeTime + Time.time;
             }
         }
     }
     catch
     {
     }
 }
Exemplo n.º 9
0
    // Start is called before the first frame update
    void Start()
    {
        hunger_slider       = GameObject.Find("HungerSlider").GetComponent <Slider> ();
        sleep_slider        = GameObject.Find("SleepSlider").GetComponent <Slider> ();
        hunger_slider_fill  = GameObject.Find("Hunger Slider Fill").GetComponent <Image> ();
        sleep_slider_fill   = GameObject.Find("Sleep Slider Fill").GetComponent <Image> ();
        high_stat_bar_color = new Color32(10, 200, 55, 255);
        low_stat_bar_color  = new Color32(226, 214, 29, 255);

        heart_icon  = GameObject.Find("catsim_heart_icon").GetComponent <SpriteRenderer> ();
        hungry_icon = GameObject.Find("catsim_hungry_icon").GetComponent <SpriteRenderer> ();
        sleep_icon  = GameObject.Find("catsim_sleep_icon").GetComponent <SpriteRenderer> ();

        heart_icon.GetComponent <Renderer>().enabled  = false;
        hungry_icon.GetComponent <Renderer>().enabled = false;
        sleep_icon.GetComponent <Renderer>().enabled  = false;

        //hungry_icon.renderer.enabled = false;
        //sleep_icon.renderer.enabled = false;

        current_state             = CatStates.Wandering;
        agent                     = GetComponent <NavMeshAgent>();
        time_of_last_state_change = Time.time;
    }
Exemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        int seed1 = (int)(Time.time);
        Random.seed = seed1;
        int roll = Random.Range(0,2);

        currentState = CatStates.stationary;//(CatStates)roll;
        chargeTimer = Time.time + chargeTime;
        isCharged = false;
        animator = gameObject.GetComponent<Animator>();
    }
Exemplo n.º 11
0
 public void CatButton()
 {
     currentState = CatStates.clearing;
 }
Exemplo n.º 12
0
    // Update is called once per frame
    void Update()
    {
        float f = chargeTimer - Time.time;
        //print("time til charge = " + f);
        if( f >= 7f && f < 15f )
        {
            currentState = CatStates.stationary;
        }

        if (f >= 0 && f < 6f)
        {
            currentState = CatStates.pacing;
        }

        if (Time.time > chargeTimer)
        {
            isCharged = true;
            if(currentState != CatStates.clearing)
            {
                currentState = CatStates.stretch;
            }
        }

        switch (currentState)
        {
            case CatStates.stationary:
                stationary();
                break;

            case CatStates.stretch:
                stretch();
                break;

            case CatStates.pacing:
                pacing();
                break;

            case CatStates.clearing:
                ClearEnemies();
                break;
        }
    }
Exemplo n.º 13
0
    // Update is called once per frame
    void Update()
    {
        delta_time          = Time.time - time_of_last_update;
        time_of_last_update = Time.time;

        // Update Sliders
        hunger_slider.value = (float)cat_stats.hunger;
        sleep_slider.value  = (float)cat_stats.energy;

        // IDLE STATE
        if (current_state == CatStates.Idle)
        {
            // Cat does nothing; waits for player input or new state change


            if (Time.time - time_of_last_state_change > change_state_delay)
            {
                // Choose a new state
                if (Random.value >= 0.75)
                {
                    current_state = CatStates.Wandering;
                }
                else
                {
                    current_state = CatStates.Playing;
                    Debug.Log("Cat State: Playing");
                }

                time_of_last_state_change = Time.time;
            }
        }

        // WANDERING STATE
        if (current_state == CatStates.Wandering)
        {
            Debug.Log("Cat State: Wandering");

            Vector3 random_position = new Vector3(Random.value * floor_size_modifier, Random.value * floor_size_modifier, Random.value * floor_size_modifier);             // Random.value eturns a random number between 0.0 [inclusive] and 1.0 [inclusive].
            Debug.Log("Cat State: Wandering");
            agent.destination = random_position;

            current_state             = CatStates.Idle;
            time_of_last_state_change = Time.time;
            Debug.Log("Cat State: Idle");
        }

        // PLAYING STATE
        if (current_state == CatStates.Playing)
        {
            agent.speed = 7F;

            if (Time.time - time_toy_last_chased >= chase_toy_time_delay)
            {
                time_toy_last_chased = Time.time;

                Vector3 go_here = cat_toy.GetComponent <Transform>().position;
                agent.destination = go_here;
            }

            // Focus on toy for 10 seconds before wandering off
            if (Time.time - time_of_last_state_change >= 10F)
            {
                current_state = CatStates.Wandering;
                agent.speed   = 3.5F;
                Debug.Log("Cat State: Wandering");
                time_of_last_state_change = Time.time;
            }
        }

        if (current_state == CatStates.User_Interaction)
        {
            Camera.main.transform.LookAt(cat_transform);             // main camera will follow cat

            // Focus on user for 10 seconds before wandering off
            if (Time.time - time_of_last_state_change >= 10F)
            {
                current_state = CatStates.Wandering;
                Debug.Log("Cat Loses Focus");
                time_of_last_state_change = Time.time;
                //Camera.main.GetComponent<Transform>().LookAt(default_camera_focus_position);
                Camera.main.GetComponent <Transform>().localEulerAngles = default_camera_rotation;
            }
        }

        // Happy state (after petting)
        if (current_state == CatStates.Happy)
        {
            Camera.main.transform.LookAt(cat_transform);             // main camera will follow cat

            // Focus on user for x seconds before wandering off
            if (Time.time - time_of_last_state_change >= 7F)
            {
                current_state = CatStates.Wandering;
                Debug.Log("Cat Loses Focus");
                time_of_last_state_change = Time.time;
                //Camera.main.GetComponent<Transform>().LookAt(default_camera_focus_position);
                Camera.main.GetComponent <Transform>().localEulerAngles = default_camera_rotation;
            }

            if (Time.time - time_of_last_state_change > happy_time)
            {
                heart_icon.GetComponent <Renderer>().enabled = false;
            }
        }

        // EATING STATE
        if (current_state == CatStates.Eating)
        {
            // If there is no food in the bowl...
            if (kibble.activeSelf == false)
            {
                current_state             = CatStates.Wandering;
                time_of_last_state_change = Time.time;
            }

            if ((can_eat == true) && (kibble.activeSelf == true))
            {
                cat_stats.hunger += cat_personality.hunger_gain_rate * delta_time;

                // If hunger stat is getting high, change stat bar color
                if (cat_stats.hunger >= (full_hunger * 0.5))
                {
                    hunger_slider_fill.color = high_stat_bar_color;
                }
            }

            // If cat is not hungry, it will stop eating
            if (cat_stats.hunger >= full_hunger)
            {
                hungry_icon.GetComponent <Renderer>().enabled = false;
                current_state             = CatStates.Wandering;
                time_of_last_state_change = Time.time;

                // Deactivate cat food
                kibble.SetActive(false);

                Debug.Log("Cat State: Wandering");
            }
        }
        // IF NOT EATING (and not currently focusing on user)
        else if (current_state != CatStates.Happy)
        {
            cat_stats.hunger -= cat_personality.hunger_decay_rate * delta_time;

            // If hunger stat is getting low, change stat bar color
            if (cat_stats.hunger <= (full_hunger * 0.5))
            {
                hunger_slider_fill.color = low_stat_bar_color;
            }

            // If cat is hungry, it will try to eat
            if ((current_state != CatStates.Sleeping) && (cat_stats.hunger <= hunger_threshold))
            {
                // If there is food in the bowl, the cat will eat
                if (kibble.activeSelf == true)
                {
                    hungry_icon.GetComponent <Renderer>().enabled = true;
                    current_state             = CatStates.Eating;
                    time_of_last_state_change = Time.time;

                    agent.destination = food_bowl.GetComponent <Transform>().position;

                    Debug.Log("Cat State: Eating");
                }
            }
        }

        // SLEEPING STATE
        if (current_state == CatStates.Sleeping)
        {
            cat_stats.energy += cat_personality.energy_gain_rate * delta_time;

            // If sleep stat is getting full, change stat bar color
            if (cat_stats.energy >= (full_energy * 0.5))
            {
                sleep_slider_fill.color = high_stat_bar_color;
            }

            // If cat is rested, it will wake up
            if (cat_stats.energy >= full_energy)
            {
                sleep_icon.GetComponent <Renderer>().enabled = false;
                current_state             = CatStates.Idle;
                time_of_last_state_change = Time.time;

                Debug.Log("Cat State: Idle (Awake)");
            }
        }
        // IF NOT SLEEPING and not focusing on user
        else if (current_state != CatStates.Happy)
        {
            cat_stats.energy -= cat_personality.energy_decay_rate * delta_time;

            // If sleep stat is getting low, change stat bar color
            if (cat_stats.energy <= (full_energy * 0.5))
            {
                sleep_slider_fill.color = low_stat_bar_color;
            }

            // If cat is tired, it will go to sleep
            if (cat_stats.energy <= sleep_threshold)
            {
                sleep_icon.GetComponent <Renderer>().enabled = true;
                current_state             = CatStates.Sleeping;
                time_of_last_state_change = Time.time;

                Debug.Log("Cat State: Sleeping");
            }
        }
    }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        delta_time          = Time.time - time_of_last_update;
        time_of_last_update = Time.time;

        // Update Sliders
        hunger_slider.value = (float)cat_stats.hunger;
        sleep_slider.value  = (float)cat_stats.energy;

        // IDLE STATE
        if (current_state == CatStates.Idle)
        {
            // Cat does nothing; waits for player input or new state change

            if (Time.time - time_of_last_state_change > change_state_delay)
            {
                current_state             = CatStates.Wandering;
                time_of_last_state_change = Time.time;
            }
        }

        // WANDERING STATE
        if (current_state == CatStates.Wandering)
        {
            Vector3 random_position = new Vector3(Random.value * floor_size_modifier, Random.value * floor_size_modifier, Random.value * floor_size_modifier);             // Random.value eturns a random number between 0.0 [inclusive] and 1.0 [inclusive].
            Debug.Log("Cat State: Wandering");
            agent.destination = random_position;

            current_state             = CatStates.Idle;
            time_of_last_state_change = Time.time;
            Debug.Log("Cat State: Idle");
        }

        // Happy state (after petting)
        if (current_state == CatStates.Happy)
        {
            if (Time.time - time_of_last_state_change > happy_time)
            {
                current_state = CatStates.Idle;
                heart_icon.GetComponent <Renderer>().enabled = false;
            }
        }

        // EATING STATE
        if (current_state == CatStates.Eating)
        {
            cat_stats.hunger += cat_personality.hunger_gain_rate * delta_time;

            // If hunger stat is getting high, change stat bar color
            if (cat_stats.hunger >= (full_hunger * 0.5))
            {
                hunger_slider_fill.color = high_stat_bar_color;
            }

            // If cat is not hungry, it will stop eating
            if (cat_stats.hunger >= full_hunger)
            {
                hungry_icon.GetComponent <Renderer>().enabled = false;
                current_state             = CatStates.Idle;
                time_of_last_state_change = Time.time;

                Debug.Log("Cat State: Idle");
            }
        }
        // IF NOT EATING
        else
        {
            cat_stats.hunger -= cat_personality.hunger_decay_rate * delta_time;

            // If hunger stat is getting low, change stat bar color
            if (cat_stats.hunger <= (full_hunger * 0.5))
            {
                hunger_slider_fill.color = low_stat_bar_color;
            }

            // If cat is hungry, it will eat
            if (current_state != CatStates.Sleeping && cat_stats.hunger <= hunger_threshold)
            {
                hungry_icon.GetComponent <Renderer>().enabled = true;
                current_state             = CatStates.Eating;
                time_of_last_state_change = Time.time;

                Debug.Log("Cat State: Eating");
            }
        }

        // SLEEPING STATE
        if (current_state == CatStates.Sleeping)
        {
            cat_stats.energy += cat_personality.energy_gain_rate * delta_time;

            // If sleep stat is getting full, change stat bar color
            if (cat_stats.energy >= (full_energy * 0.5))
            {
                sleep_slider_fill.color = high_stat_bar_color;
            }

            // If cat is rested, it will wake up
            if (cat_stats.energy >= full_energy)
            {
                sleep_icon.GetComponent <Renderer>().enabled = false;
                current_state             = CatStates.Idle;
                time_of_last_state_change = Time.time;

                Debug.Log("Cat State: Idle (Awake)");
            }
        }
        // IF NOT SLEEPING
        else
        {
            cat_stats.energy -= cat_personality.energy_decay_rate * delta_time;

            // If sleep stat is getting low, change stat bar color
            if (cat_stats.energy <= (full_energy * 0.5))
            {
                sleep_slider_fill.color = low_stat_bar_color;
            }

            // If cat is tired, it will go to sleep
            if (cat_stats.energy <= sleep_threshold)
            {
                sleep_icon.GetComponent <Renderer>().enabled = true;
                current_state             = CatStates.Sleeping;
                time_of_last_state_change = Time.time;

                Debug.Log("Cat State: Sleeping");
            }
        }
    }