示例#1
0
 public void Impregnate(GenesData fatherGenesData)
 {
     //SALE EL LOGO DE FOLLANDO///
     ////////////////////////////
     pregnancy = gameObject.AddComponent <Pregnant>();
     pregnancy.StartPregnancy(fatherGenesData);
 }
    public void InstantiateNewAnimal(GenesData childGenes)
    {
        GameObject son = Instantiate(gameObject);

        ecosystem.AddAnimal(son);
        son.GetComponent <Genes>().genesData = childGenes;
        Destroy(son.GetComponent <Pregnant>());
    }
    public void StartPregnancy(GenesData fatherGenes)
    {
        this.fatherGenesData = fatherGenes;

        pregnancyStarted      = true;
        timePregnant          = 0;
        childCount            = Mathf.RoundToInt(motherGenesData.childCountMean);
        gestationPeriodLength = motherGenesData.gestationPeriodLength;
    }
    private void Awake()
    {
        motherGenesData = GetComponent <Genes>().genesData;

        GameObject pregnantSignGO = new GameObject();

        pregnantSignGO.name = "Pregnant Sign";

        BehaviourCommunicator communicator = GetComponentInChildren <BehaviourCommunicator>();

        pregnantSignGO.transform.parent        = communicator.transform;
        pregnantSignGO.transform.localPosition = COMMUNICATION_OFFSET;
        pregnantSignGO.transform.localScale    = new Vector3(COMMUNICATION_SCALE, COMMUNICATION_SCALE, COMMUNICATION_SCALE);

        pregnantIcon              = pregnantSignGO.AddComponent <SpriteRenderer>();
        pregnantIcon.sprite       = GetComponent <VitalFunctions>().PregnantCommunicationSprite;
        pregnantIcon.sortingOrder = communicator.GetComponent <SpriteRenderer>().sortingOrder + 1;

        ecosystem = FindObjectOfType <Ecosystem>();
    }
    public void GiveBirth()
    {
        //Se calculan los genes base de cada hijo
        float meanmaxEnergy             = mean(motherGenesData.maxEnergy, fatherGenesData.maxEnergy);
        float meanmaxHydration          = mean(motherGenesData.maxHydration, fatherGenesData.maxHydration);
        float meanspeed                 = mean(motherGenesData.speed, fatherGenesData.speed);
        float meanchildCountMean        = mean(motherGenesData.childCountMean, fatherGenesData.childCountMean);
        float meanperceptionRadius      = mean(motherGenesData.perceptionRadius, fatherGenesData.perceptionRadius);
        float meangestationPeriodLength = mean(motherGenesData.gestationPeriodLength, fatherGenesData.gestationPeriodLength);

        //Asignación de elementos
        for (int i = 0; i < childCount; i++) //Para cada hijo se calcula el valor base + un random de ese stat
        {
            GenesData childGenesData = new GenesData();
            childGenesData.maxEnergy             = meanmaxEnergy + randomVariation(meanmaxEnergy, childGenesData.variance);
            childGenesData.maxHydration          = meanmaxHydration + randomVariation(meanmaxHydration, childGenesData.variance);
            childGenesData.speed                 = meanspeed + randomVariation(meanspeed, childGenesData.variance);
            childGenesData.childCountMean        = meanchildCountMean + randomVariation(meanchildCountMean, childGenesData.variance);
            childGenesData.perceptionRadius      = meanperceptionRadius + randomVariation(meanperceptionRadius, childGenesData.variance);
            childGenesData.gestationPeriodLength = meangestationPeriodLength + randomVariation(meangestationPeriodLength, childGenesData.variance);

            InstantiateNewAnimal(childGenesData);
        }
    }