Example #1
0
    private Herbifoo FindNearestHerbifoo()
    {
        Herbifoo closest = null;
        float    d       = -1;

        foreach (Herbifoo h in PopulationHandler.herbifoos)
        {
            float dist = Vector3.Distance(cachedTransform.position, h.cachedTransform.position);

            if (InRange(dist) && !ScaredOfPoison(h.vividness))
            {
                if (closest == null)
                {
                    closest = h;
                    d       = dist;
                }
                else if (dist < d)
                {
                    closest = h;
                    d       = dist;
                }
            }
        }
        return(closest);
    }
Example #2
0
    /*
     * Novel Behaviors
     */

    private new void FixedUpdate()
    {
        base.FixedUpdate();

        if (onGround && CanEatFooTarget)
        {
            TryToEatTarget();
        }
        else if (onGround && jumpWait <= 0)
        {
            //Sex and Food
            if (!IsChild && sexNeed > foodNeed)
            {
                HaveChild();
            }

            //find Herbifoo to eat
            fooTarget = FindNearestHerbifoo();

            if (fooTarget != null)
            {
                PointDirToTarget();
            }

            //Stay in bounds
            PadDir();


            body.transform.forward = dir;
            Jump();

            UpdateNeeds();
        }
    }
Example #3
0
    protected override void HaveChild()
    {
        sexNeed = 0;

        Herbifoo child = Instantiate(this);

        child.Initialize(DNA.Mutate(dna), generation);

        PopulationHandler.herbifoos.Add(child);
    }
Example #4
0
    void Awake()
    {
        for (int i = 0; i < Settings.NUM_ENVIRON_OBJS; i++)
        {
            Vector3    pos = new Vector3(Random.Range(-Settings.ENVIRONMENT_RANGE, Settings.ENVIRONMENT_RANGE), 0, Random.Range(-Settings.ENVIRONMENT_RANGE, Settings.ENVIRONMENT_RANGE));
            Quaternion rot = Quaternion.Euler(0, Random.Range(0, 360), 0);
            switch (Random.Range(0, 3))
            {
            case 0:
                Instantiate(treePrefab, pos, rot);
                break;

            default:
                Instantiate(grassPrefab, pos, rot);
                break;
            }
        }

        for (int i = 0; i < Settings.NUM_HERBIFOOS; i++)
        {
            Herbifoo herbifoo = Instantiate(herbifooPrefab);
            herbifoo.Initialize(DNA.Mutate(Settings.HERB_PRESET_1));

            PopulationHandler.herbifoos.Add(herbifoo);
        }

        for (int i = 0; i < Settings.NUM_NOMS; i++)
        {
            Nom nom = Instantiate(nomPrefab);

            PopulationHandler.noms.Add(nom);
        }

        for (int i = 0; i < Settings.NUM_CARNIFOOS; i++)
        {
            Carnifoo carnifoo = Instantiate(carnifooPrefab);
            carnifoo.Initialize(Settings.CARN_PRESET_1);

            PopulationHandler.carnifoos.Add(carnifoo);
        }
    }