예제 #1
0
 void lookForFood()
 {
     //first see if we are carrying any food
     foreach (Item item in inventory.getItems())
     {
         if (item is Food)
         {
             behavior = BEHAVIORTYPE.EATING;
             break;
         }
     }
     //if no food is found in the invetory then see if we are standing near it
     if (behavior == BEHAVIORTYPE.LOOKINGFORFOOD)
     {
         List <GameObject> stuffInReach = WorldController.stuffInRadius(transform.position, reach);
         foreach (GameObject inReachThing in stuffInReach)
         {
             if (inReachThing.GetComponent <Plant>() != null)
             {
                 if (inReachThing.GetComponent <Plant>().getPlantType() == preferredFood)
                 {
                     behavior = BEHAVIORTYPE.HARVESTING;
                     break;
                 }
             }
         }
     }
     //if no food plant is near then look for it in sight radius
 }
예제 #2
0
    public override void FixedUpdate()
    {
        base.FixedUpdate();
        consumeMetabolism();
        checkHunger();

        //do stuff based on the current behavior
        switch (behavior)
        {
        case BEHAVIORTYPE.IDLE:
            if (status == STATUS.HUNGRY)
            {
                behavior = BEHAVIORTYPE.LOOKINGFORFOOD;
            }
            break;

        case BEHAVIORTYPE.LOOKINGFORFOOD:
            lookForFood();
            break;

        case BEHAVIORTYPE.EATING:
            biteFood();
            break;

        case BEHAVIORTYPE.HARVESTING:
            harvestFood();
            break;
        }
    }
예제 #3
0
    void biteFood()
    {
        Food tempFood = null;

        foreach (Item item in inventory.getItems())
        {
            if (item is Food)
            {
                tempFood = (Food)item;
                break;
            }
        }
        //last bite can be too big, fix later
        if (tempFood != null)
        {
            tempFood.beEaten(biteValue);
            metabolism += biteValue;
            if (tempFood.isGone())
            {
                inventory.retrieveItem(tempFood);
            }
        }

        behavior = BEHAVIORTYPE.IDLE;
    }
예제 #4
0
    void harvestFood()
    {
        List <GameObject> stuffInReach = WorldController.stuffInRadius(transform.position, reach);

        foreach (GameObject inReachThing in stuffInReach)
        {
            if (inReachThing.GetComponent <Plant>() != null)
            {
                if (inReachThing.GetComponent <Plant>().getPlantType() == preferredFood)
                {
                    inventory.putItem(inReachThing.GetComponent <Plant>().harvestFood());
                    break;
                }
            }
        }
        behavior = BEHAVIORTYPE.IDLE;
    }
예제 #5
0
 public void setBehavior(BEHAVIORTYPE inBehavior)
 {
     behavior = inBehavior;
 }