Example #1
0
    private void Reproduce(EventArgs args)
    {
        ReproduceArgs newAnimal = (ReproduceArgs)args;

        var animalGO = Instantiate(animal, newAnimal.startingPosition, Quaternion.identity);

        animalGO.GetComponent <Animal>().Init(newAnimal.minSpeed, newAnimal.maxSpeed, newAnimal.minSize, newAnimal.maxSize, newAnimal.minAttack, newAnimal.maxAttack, newAnimal.minVision, newAnimal.maxVision, newAnimal.directionBias, newAnimal.wealthBonus);
    }
Example #2
0
    private void Reproduce()
    {
        this.offspring++;

        float   x           = this.transform.position.x;
        float   z           = this.transform.position.z;
        float   unit        = Constants.worldScale / 2;
        float   clamp       = 4 * Constants.worldScale;
        Vector3 newPosition = Random.value >= 0.5f ?
                              new Vector3(
            Constants.GetClampedRandomFloat(x - unit, x - unit / 2, clamp),
            2,
            Constants.GetClampedRandomFloat(z - unit, z - unit / 2, clamp)
            )
                        :
                              new Vector3(
            Constants.GetClampedRandomFloat(x + unit / 2, x + unit, clamp),
            2,
            Constants.GetClampedRandomFloat(z + unit / 2, z + unit, clamp)
            );

        float minSpeed  = this.body.speed - 4 < 0 ? 1 : this.body.speed - 4;
        float maxSpeed  = this.body.speed + 5;
        float minSize   = this.body.size - 2 <= 0 ? 1 : this.body.size - 2;
        float maxSize   = this.body.size + 3;
        float minAttack = this.body.attack - 4 < 0 ? 1 : this.body.attack - 4;
        float maxAttack = this.body.attack + 5;
        float minVision = this.body.Brain.vision - 14 <= 0 ? 1 : this.body.Brain.vision - 14;
        float maxVision = this.body.Brain.vision + 15;

        Dictionary <Vector2, float> directionBias = this.body.Brain.DirectionBias;

        ReproduceArgs newAnimal = new ReproduceArgs(newPosition, minSpeed, maxSpeed, minSize, maxSize, minAttack, maxAttack, minVision, maxVision, directionBias, this.offspring + 1);

        EventManager.Broadcast(EVENT.Reproduce, newAnimal);
    }