Example #1
0
    private void AttemptBreeding(object[] args)
    {
        KinematicBody otherBody = (KinematicBody)args[0];

        if (otherBody.GetName() == targetName)
        {
            ((Entity)otherBody.GetNode("Entity")).SendMessage("acceptBreed");
            SetState(BreedState.GoingForBreed);
        }
        else
        {
            if (!active || state == BreedState.ApproachingTarget)
            {
                if (component.Satiated < satiatedThreshold)
                {
                    return;
                }
                int n = BaseComponent.random.Next(0, 100);
                if (n < component.Breedability)
                {
                    ((Entity)otherBody.GetNode("Entity")).SendMessage("acceptBreed");
                    target     = otherBody;
                    targetName = otherBody.GetName();
                    active     = true;

                    SetState(BreedState.GoingForBreed);
                }
            }
        }
    }
Example #2
0
    public override void Ready()
    {
        watchList = new List <String>();

        body = (KinematicBody)parent.GetParent();

        parent.RegisterListener("jump", Jump);
        parent.RegisterListener("setDirection", SetDirection);
        parent.RegisterListener("setSpeed", SetSpeed);
        parent.RegisterListener("watchFor", WatchFor);

        //for detection objects in a range

        //TODO: Generate this area in code. Could not figure out how to generate areas in code or get the shapes from existing areas,
        //but it is possible. As a result, currently the area must be set in the animal scene file, and the range cannot be changed through code.
        area = (Area)body.GetNode("Area");

        area.Connect("body_entered", this, nameof(ObjectInRange));
        area.Connect("body_exited", this, nameof(ObjectOutOfRange));
    }