public void Replicate(int parentRes)
    {
        int ran    = Random.Range(0, 101);
        int newRes = parentRes;

        if (ran <= mutationChance)
        {
            ran     = Random.Range(-10, 11);
            newRes += ran;
            if (newRes <= 0)
            {
                newRes = 0;
            }
            else if (newRes >= 100)
            {
                newRes = 100;
            }
        }

        GameObject clone = Instantiate(gameObject);

        clone.transform.position = transform.position;

        BacteriaLogic bacteriaScript = clone.GetComponent <BacteriaLogic>();

        bacteriaScript.speed      = speed;
        bacteriaScript.range      = range;
        bacteriaScript.resistance = newRes;
    }
    public void EndDay(bool isTrue)
    {
        GameObject[] blobs = GameObject.FindGameObjectsWithTag("Blob");
        foreach (GameObject blob in blobs)
        {
            BacteriaLogic blobscript = blob.GetComponent <BacteriaLogic>();

            if (isTrue == true)
            {
                //early days
                blobscript.EndDay(true, courseOn);
            }
            else
            {
                //later
                //Debug.Log("before");
                blobscript.EndDay(false, courseOn);
                //Debug.Log("ended");
            }

            //Debug.Log(blobscript.enabled);
        }
        if (courseOn == true)
        {
            Debug.Log("wave");
            daysLeft -= 1;
            Debug.Log(daysLeft);
        }
    }
Example #3
0
 public void OnTriggerStay(Collider collider)
 {
     if (collider.transform.tag == "BlobChild")
     {
         BacteriaLogic blobScript = collider.transform.parent.GetComponent <BacteriaLogic>();
         blobScript.FoodDetected(transform.position);
     }
 }
    // Start is called before the first frame update
    void Start()
    {
        courseOn         = false;
        currentDestroyed = false;

        for (int i = 1; i <= blobNumber; i++)
        {
            currentObject = Instantiate(blobPrefab);

            BacteriaLogic blobScript = currentObject.GetComponent <BacteriaLogic>();
            blobScript.speed = speed;
            blobScript.range = (int)range;
            int rand = Random.Range((int)minResistance, (int)maxResistance);
            blobScript.resistance = rand;

            int ran = Random.Range(0, 2);
            if (ran == 0)
            {
                ran = Random.Range(0, 2);
                if (ran == 0)
                {
                    x = 45;
                    z = Random.Range(45, -46);
                }
                else
                {
                    x = -45;
                    z = Random.Range(45, -46);
                }
            }
            else
            {
                ran = Random.Range(0, 2);
                if (ran == 0)
                {
                    z = 45;
                    x = Random.Range(45, -46);
                }
                else
                {
                    z = -45;
                    x = Random.Range(45, -46);
                }
            }

            currentObject.transform.position = new Vector3(x, 2.5f, z);
        }

        originalBlobText.text = "Original Count: " + blobNumber.ToString();
        speedText.text        = "Speed: " + speed.ToString();
        rangeText.text        = "Range: " + range.ToString();
    }
    // Update is called once per frame
    void Update()
    {
        minResistance = 101;
        maxResistance = 0;

        blobCount = 0;
        GameObject[] blobs = GameObject.FindGameObjectsWithTag("Blob");
        foreach (GameObject blob in blobs)
        {
            blobCount += 1;
            BacteriaLogic blobscript = blob.GetComponent <BacteriaLogic>();
            totalResistance += blobscript.resistance;


            if (blobscript.resistance < minResistance)
            {
                minResistance = blobscript.resistance;
            }
            else if (blobscript.resistance > maxResistance)
            {
                maxResistance = blobscript.resistance;
            }

            if (dayScript.isDay == false)
            {
                blobscript.detectedFood = false;
            }
        }
        blobText.text     = blobCount.ToString() + " Blobs";
        averageResistance = totalResistance / blobCount;

        totalResistance = 0;
        resText.text    = "Resistance: " + averageResistance.ToString();
        minResText.text = "Min Resistance: " + minResistance.ToString();
        maxResText.text = "Max Resistance: " + maxResistance.ToString();

        if (daysLeft <= 0)
        {
            courseOn = false;
        }
    }