Esempio n. 1
0
    // Update is called once per frame
    // Update is called once per frame
    void Update()
    {
        eatfood life = gameObject.GetComponent <eatfood>();

        if (life.totallife >= 5)
        {
            Target = FindClosestEnemy().transform;
            if (Mathf.Abs(Target.position.x) - Mathf.Abs(transform.position.x) <= 0.05)
            {
                temp = (transform.position + Target.position).normalized;
                Debug.Log("DANGEEEER");
                Debug.Log(transform.position + Target.position);
                transform.position = Vector2.MoveTowards(transform.position, temp, (Speed * Time.deltaTime * 10) / (transform.localScale.x));
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        var     contador = 0;
        eatfood life     = gameObject.GetComponent <eatfood>();

        agendaded = life.Age;
        Target    = FindClosestEnemy().transform;

        if (agendaded > 10 && runbitch == false)
        {
            Targetl = FindClosestlover().transform;
            eatfood lifelov = Targetl.gameObject.GetComponent <eatfood>();
            for (int i = 0; i < 40; i++)
            {
                if (lifelov.geneticcode[i] == life.geneticcode[i])
                {
                    contador += 1;
                }
            }
            if (contador >= 25)
            {
                letsgetiton = true;
            }
            else
            {
                letsgetiton = false;
            }
        }
        if (life.totallife < 5)
        {
            Target             = FindClosestFood().transform;
            transform.position = Vector2.MoveTowards(transform.position, Target.position, (Speed * Time.deltaTime * 10) / (transform.localScale.x));
        }
        else if (life.totallife >= 5 && runbitch == true)
        {
            if (Time.time > nexactiontime)
            {
                nexactiontime += period;
                Target         = FindClosestEnemy().transform;
            }
            transform.position = Vector2.MoveTowards(transform.position, Target.position, (Speed * Time.deltaTime * 10) / (transform.localScale.x));
        }
        else if (life.totallife < 28)
        {
            Target             = FindClosestFood().transform;
            transform.position = Vector2.MoveTowards(transform.position, Target.position, (Speed * Time.deltaTime * 10) / (transform.localScale.x));
        }
        else if (life.totallife > 30 && letsgetiton == true && agendaded > 10 && iscreated == false)
        {
            Targetl = FindClosestlover().transform;
            eatfood lifelov    = Targetl.gameObject.GetComponent <eatfood>();
            var     transform1 = "";
            var     transform2 = "";
            var     siz        = "";
            var     meta       = "";
            var     newgen     = "";
            //Crossover
            for (int i = 0; i < 40; i++)
            {
                if (i % 2 == 1)
                {
                    newgen += life.geneticcode[i];
                }
                else
                {
                    newgen += lifelov.geneticcode[i];
                }
                if (i < 10)
                {
                    transform1 += lifelov.geneticcode[i];
                }
                else if (i >= 10 && i < 20)
                {
                    transform2 += lifelov.geneticcode[i];
                }
                else if (i >= 20 && i < 25)
                {
                    siz += lifelov.geneticcode[i];
                }
                else
                {
                    meta += lifelov.geneticcode[i];
                }
            }

            int   xtrans  = Conva.ToInt32(transform1, 2);
            float xtransf = (float)xtrans / 100;
            int   ytrans  = Conva.ToInt32(transform2, 2);
            float ytransf = (float)ytrans / 100;
            int   sizi    = Conva.ToInt32(siz, 2);
            float sizif   = (float)sizi / 100;
            int   meti    = Conva.ToInt32(meta, 2);
            float metif   = (float)meti / 100;
            transform.position = Vector2.MoveTowards(transform.position, Targetl.position, (Speed * Time.deltaTime * 10) / (transform.localScale.x));
            if (!iscreated && born)
            {
                var child = Instantiate(baby, this.gameObject.transform.position, Quaternion.identity);
                eatfood.gen = newgen;
                Debug.Log("---------------------------------------->" + newgen);
                iscreated      = true;
                born           = false;
                life.totallife = life.totallife - 10;
            }
        }
        else
        {
            if (Time.time > nexactiontime)
            {
                nexactiontime += period;
                Target         = FindClosestAlly().transform;
            }
            transform.position = Vector2.MoveTowards(transform.position, Target.position, (Speed * Time.deltaTime * 10) / (transform.localScale.x));
        }
    }