Esempio n. 1
0
    // Start is called before the first frame update
    void Start()
    {
        startScript  = GameObject.Find("StartManager").GetComponent <StartLogic>();
        blobNumber   = startScript.blobs;
        initialSpeed = (float)startScript.initialSpeed;
        initialRange = startScript.range;

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

            BlobLogic blobScript = currentObject.GetComponent <BlobLogic>();
            blobScript.speed = initialSpeed;
            blobScript.range = (int)initialRange;

            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();

        initialSpeedText.text = "Initial Speed: " + initialSpeed.ToString();

        initialRangeText.text = "Initial Detection Range: " + initialRange.ToString();


        averageSpeed = initialSpeed;

        averageRange = initialRange;
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        minSpeed = averageSpeed;
        maxSpeed = averageSpeed;

        minRange = averageRange;
        maxRange = averageRange;

        blobCount = 0;
        GameObject[] blobs = GameObject.FindGameObjectsWithTag("Blob");
        foreach (GameObject blob in blobs)
        {
            blobCount += 1;
            BlobLogic blobscript = blob.GetComponent <BlobLogic>();
            totalSpeed += blobscript.speed;
            totalRange += blobscript.range;

            if (blobscript.speed < minSpeed)
            {
                minSpeed = blobscript.speed;
            }
            else if (blobscript.speed > maxSpeed)
            {
                maxSpeed = blobscript.speed;
            }

            if ((float)blobscript.range < (float)minRange)
            {
                minRange = (float)blobscript.range;
            }
            else if ((float)blobscript.range > (float)maxRange)
            {
                maxRange = (float)blobscript.range;
            }


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


        averageSpeed   = totalSpeed / blobCount;
        totalSpeed     = 0;
        speedText.text = "Average Speed: " + averageSpeed.ToString();

        minSpeedText.text = "Minimum Speed: " + minSpeed.ToString();
        maxSpeedText.text = "Maximum Speed: " + maxSpeed.ToString();


        averageRange   = (float)totalRange / (float)blobCount;
        totalRange     = 0;
        rangeText.text = "Average Detection Range: " + averageRange.ToString();

        minRangeText.text = "Minimum Detection Range: " + minRange.ToString();
        maxRangeText.text = "Maximum Detection Range: " + maxRange.ToString();
    }
Esempio n. 3
0
 public void OnTriggerStay(Collider collider)
 {
     if (collider.transform.tag == "BlobChild")
     {
         BlobLogic blobScript = collider.transform.parent.GetComponent <BlobLogic>();
         blobScript.FoodDetected(transform.position);
     }
 }
Esempio n. 4
0
 public void EndDay(bool isTrue)
 {
     GameObject[] blobs = GameObject.FindGameObjectsWithTag("Blob");
     foreach (GameObject blob in blobs)
     {
         BlobLogic blobscript = blob.GetComponent <BlobLogic>();
         if (isTrue == true)
         {
             blobscript.EndDay(true);
         }
         else
         {
             blobscript.EndDay(false);
         }
     }
 }
Esempio n. 5
0
    public void Replicate(float parentSpeed, int parentRange)
    {
        int   ran      = Random.Range(0, 101);
        float newSpeed = parentSpeed;

        if (ran <= mutationChance)
        {
            ran       = Random.Range(-5, 6);
            newSpeed += ran;
            if (newSpeed <= 0)
            {
                newSpeed = 1;
            }
        }

        ran = Random.Range(0, 101);
        int newRange = parentRange;

        if (ran <= mutationChance)
        {
            ran       = Random.Range(-3, 4);
            newRange += ran;
            if (newRange <= 0)
            {
                newRange = 1;
            }
        }


        GameObject clone = Instantiate(gameObject);

        clone.transform.position = transform.position;

        BlobLogic blobScript = clone.GetComponent <BlobLogic>();

        blobScript.speed = newSpeed;
        blobScript.range = newRange;
    }
Esempio n. 6
0
 public static void Load(BlobLogic ext)
 {
     b = ext; // load blob locally
 }