Exemplo n.º 1
0
    void PieceClicked_F(Vector2 pApData)

    {
        int Sq;

        //      GD.Print(pApData);
        Sq = (int)GameEngine.Call("InputSelected", pApData[0], pApData[1]);
        //  EmitSignal("MovePlayerTo", pApData[0], pApData[1], Sq);
    }
Exemplo n.º 2
0
    protected override void Control(float delta)
    {
        if (PathEnd != Vector2.Zero && PathEndDistance > PathDistanceDeadband)
        {
            // update the path mover script
            pathMover.Call("update_acceleration", delta);
            Velocity = (Vector2)(pathMover.Get("velocity"));
            float angularVelocity = (float)(pathMover.Get("angular_velocity"));
            Rotation += angularVelocity * delta;
        }
        else
        {
            Path     = new Vector2[] { };
            Velocity = Vector2.Zero;
        }

        if (State == States.Idle)
        {
            if (Hopper.HasBalls)
            {
                machine.Fire(Triggers.Score);
            }
            else
            {
                machine.Fire(Triggers.PickupBalls);
            }
        }
        else if (State == States.DrivingToPickup)
        {
            // we ran out of room, go score
            if (!Hopper.HasRoom)
            {
                machine.Fire(Triggers.Score);
            }
        }
        else if (State == States.Shoot && !Hopper.HasBalls)
        {
            machine.Fire(Triggers.PickupBalls);
        }
        else if (State == States.Pickup && Hopper.HasBalls)
        {
            machine.Fire(Triggers.Score);
        }
    }
Exemplo n.º 3
0
    public override void _Ready()
    {
        base._Ready();

        BallSensor        = GetNode <Area2D>("BallSensor");
        ScorePickupSensor = GetNode <Area2D>("ScorePickupSensor");
        ScorePickupSensor.Connect("area_entered", this, nameof(OnScorePickupSensorAreaEntered));
        BallSensor.Connect("body_entered", this, nameof(OnBallSensorBodyEntered));
        BallSensor.Connect("body_exited", this, nameof(OnBallSensorBodyExited));

        pathMover = GetNode <Node2D>("PathMover");
        pathMover.Call("setup");

        // Our AI robot is either idle, trying to score, or trying to pickup balls
        machine = new StateMachine <States, Triggers>(() => State, (s) => State = s);

        machine.Configure(States.Idle)
        .Permit(Triggers.Score, States.DrivingToScore)
        .Permit(Triggers.PickupBalls, States.DrivingToPickup)
        .OnEntry(() => OnIdle());

        machine.Configure(States.DrivingToScore)
        .Permit(Triggers.Idle, States.Idle)
        .Permit(Triggers.Shoot, States.Shoot)
        .OnEntry(() => OnDrivingToScore())
        .OnExit(() => StopDriving());

        machine.Configure(States.DrivingToPickup)
        .Permit(Triggers.Idle, States.Idle)
        .Permit(Triggers.Pickup, States.Pickup)
        .Permit(Triggers.Score, States.DrivingToScore)
        .OnEntry(() => OnDrivingToPickup())
        .OnExit(() => StopDriving());

        machine.Configure(States.Shoot)
        .Permit(Triggers.Idle, States.Idle)
        .Permit(Triggers.PickupBalls, States.DrivingToPickup)
        .OnEntry(() => OnShoot())
        .OnExit(() => OnStopShooting());

        machine.Configure(States.Pickup)
        .Permit(Triggers.Idle, States.Idle)
        .Permit(Triggers.Score, States.DrivingToScore)
        .OnEntry(() => OnPickupBalls())
        .OnExit(() => OnStopPickupBalls());

        machine.OnTransitioned(t =>
        {
            GD.Print($"OnTransitioned: {t.Source} -> {t.Destination} via {t.Trigger}({string.Join(", ", t.Parameters)})");
            PublishChangeStateEvent();
        });
    }
Exemplo n.º 4
0
    // Function that is called when the selected object is changed
    // Connected to the "ObjectList" option button through the editor
    // NOTE: BECAUSE OF THE WAY GODOT UPDATES COLLISION SHAPES, WHEN THE OBJECT IS FIRST CHANGED, A PHYSICS FRAME IS REQUIRED FOR THE COLLISION SHAPES TO UPDATE WHETHER THEY ARE ENABLED/DISABLED
    // TO SOLVE THIS ISSUE, THIS FUNCTION WAS SPLIT IN TWO, THE FISRT PART CHANGING THE OBJECTS, AND THE SECOND PART DISPLAYING THE OBJECT AFTER A PHYSICS FRAME
    public void _on_ObjectList_item_selected(int index)
    {
        // FIRST PART OF FUNCTION

        // Hide the previously selected object and disable its collision
        objectBody.Visible = false;
        objectBody.GetChild <CollisionShape>(1).Disabled = true;

        // If the auxiliary view object (Object 8) is selected, enable the auxiliary view option from the dropdown list, and enable the auxiliary view
        // Otherwise, if the auxiliary object WAS selected before, disable the auxiliary view and the auxiliary view option from the dropdown list, and reset the auxiliary view displays so they are blank
        if (index == AUX_OBJECT)
        {
            viewList.SetItemDisabled((int)Views.AUX_VIEW, false);
            isAuxEnabled = true;
        }
        else if (currentObjectIndex == AUX_OBJECT)
        {
            isAuxEnabled = false;

            if (selectedView == (int)Views.AUX_VIEW)
            {
                viewList.Select((int)Views.ALL_VIEWS);
                selectedView = (int)Views.ALL_VIEWS;
            }

            viewList.SetItemDisabled((int)Views.AUX_VIEW, true);

            auxiliaryViewPlane.Call("Reset");
            auxiliaryViewRoot.Call("Reset");
            auxiliaryViewRoot.Update();
        }

        // Set the current object's index
        currentObjectIndex = index;

        // Reassign the selected static body to the new object
        objectBody = GetNode <StaticBody>(objects[currentObjectIndex]);

        // Show the new object and enable its collision
        objectBody.Visible = true;
        objectBody.GetChild <CollisionShape>(1).Disabled = false;

        // Rotate the object so that it, and its collision object, can be updated in the next physics frame
        objectBody.RotationDegrees = new Vector3((float)ObjectXDegSlider.Value, (float)ObjectYDegSlider.Value, (float)ObjectZDegSlider.Value);

        // Set hasFramePassed to false to check when a physics frame passes, for the second part of the function
        hasFramePassed = false;
    }