Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        nextGoal = startState;
        currGoal = goals.ZERO;

        physical = this.GetComponent <Rigidbody2D>();
        clicker  = this.GetComponent <Clickable>();
        anim     = GetComponent <Animator>();
        sprite   = GetComponent <SpriteRenderer>();

        if (clicker != null)
        {
            clicker.setClickDownCallback(wasMouseDowned);
            clicker.setClickReleaseCallback(wasMouseUpped);
        }

        if (mousey == null)
        {
            mousey = FindObjectOfType <MouseBehaviour>();
        }

        currentHunger = maxHunger;
        currEmote     = emotes.NEUTRAL;
        maturityTimer = WeightedRandomRange(maturityVariance, maturityTime);
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        lastGoal = currGoal;
        currGoal = nextGoal;

        if (currGoal == goals.WANDER)
        {
            WanderAction();
        }
        else if (currGoal == goals.WAIT)
        {
            WaitAction();
        }
        else if (currGoal == goals.GRABBED)
        {
            GrabbedAction();
        }
        else if (currGoal == goals.HUNTING)
        {
            HuntAction();
        }
        else if (currGoal == goals.DIE)
        {
            DieAction();
        }
        else if (currGoal == goals.SOLD)
        {
            SoldAction();
        }

        Debug.Log($"Is on {Enum.GetName(typeof(goals), currGoal)}");

        if (currentHunger < feelHungryThreshold)
        {
            Debug.Log("Now Hungry");
            currEmote = emotes.HUNGRY;
            anim.SetBool("IsHungry", true);
        }
        else if (currentHunger >= feelHungryThreshold)
        {
            currEmote = emotes.NEUTRAL;
            anim.SetBool("IsHungry", false);
        }

        behaviourTime -= Time.deltaTime;
        currentHunger -= hungerDegredation * Time.deltaTime;
        huntCooldown  -= Time.deltaTime;

        if (maturityTimer > 0)
        {
            maturityTimer -= Time.deltaTime;
        }
        else
        {
            isMature = true;
        }

        if (relaxTimer > 0)
        {
            relaxTimer -= Time.deltaTime;
        }
        else
        {
            currSeenFood = null;
        }

        if (currentHunger <= 0)
        {
            nextGoal = goals.DIE;
        }

        //set maturity bit
        anim.SetBool("isMature", isMature);
        anim.SetFloat("Speed", physical.velocity.magnitude);

        if (Mathf.Abs(physical.velocity.x) > .2)
        {
            isFacingLeft = physical.velocity.x < 0;
            sprite.flipX = !isFacingLeft;
        }
    }