public void Init(PlantGenetics _genes)
 {
     dir            = Random.Range(0, 2) == 0;
     genes          = _genes;
     rb             = GetComponent <Rigidbody2D>();
     rb.constraints = RigidbodyConstraints2D.FreezeRotation;
     rb.AddForce(Vector2.up * 5, ForceMode2D.Impulse);
     started = true;
 }
Beispiel #2
0
 public PlantGenetics(PlantGenetics female, PlantGenetics male, float mutationRate = 0.1f)
 {
     height          = GetChance() ? Random.Range(2, 15) : (female.height + male.height) / 2;
     branchCount     = GetChance() ? Random.Range(5, 30) : (female.branchCount + male.branchCount) / 2;
     leafCount       = GetChance() ? Random.Range(1, 7) : (female.leafCount + male.leafCount) / 2;
     rootCount       = GetChance() ? Random.Range(3, 15) : (female.rootCount + male.rootCount) / 2;
     rootConnections = MixAndMutateRootConnections(female.rootConnections, male.rootConnections, rootCount);
     rootRotations   = MixAndMutateArrays(female.rootRotations, male.rootRotations, rootCount, 0f, 90f);
     branchLenght    = MixAndMutateArrays(female.branchLenght, male.branchLenght, branchCount, 1, 6);
     branchRotations = MixAndMutateArrays(female.branchRotations, male.branchRotations, branchCount, -67f, 67f);
     branchHeight    = MixAndMutateArrays(female.branchHeight, male.branchHeight, branchCount, 0f, 1f);
     leafRotations   = MixAndMutateArrays(female.leafRotations, male.leafRotations, leafCount, 0f, 90f);
     colors          = MixAndMutateArrays(female.colors, male.colors, 6);
 }
Beispiel #3
0
 void DetachGrowthling()
 {
     if (growthlingSize < 1f)
     {
         growthling.transform.parent = null;
         growthling.GetComponent <Seedling>().Init();
         partner    = null;
         growthling = null;
     }
     if (partner != null)
     {
         PlantGenetics newGenes = new PlantGenetics(genes, partner);
         growthling.transform.parent = null;
         growthling.GetComponent <Seedling>().Init(newGenes);
         partner    = null;
         growthling = null;
     }
 }
Beispiel #4
0
 public void InitializePlant(PlantGenetics _genes)
 {
     genes = _genes;
     transform.GetComponent <SpriteRenderer>().color = genes.colors[4].GetGradientColor(Random.Range(0f, 1f));
     Build();
 }