Пример #1
0
        public MainController()
        {
            var directInput = new DirectInput();
            LogicState = new LogicState();

            foreach (var deviceInstance in directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                try
                {
                    gamepad = new Joystick(directInput, deviceInstance.InstanceGuid);
                    gamepad.SetCooperativeLevel(Parent, CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException) { }
            }

            if (gamepad == null)
                return;

            foreach (var deviceObject in gamepad.GetObjects())
            {
                if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                    gamepad.GetObjectPropertiesById((int) deviceObject.ObjectType).SetRange(-1000, 1000);
            }

            gamepad.Acquire();
        }
Пример #2
0
        public MainLogicProcessor()
        {
            VisionData = new VisionData();
            SensorData = new SensorData();
            LogicState = new LogicState();

            stateMachine = new StateMachine<State, Trigger>(State.Idle);

            stateMachine.OnUnhandledTrigger((state, trigger) => { });

            stateMachine.Configure(State.Idle)
                .Permit(Trigger.PoweredUp, State.Starting)
                .OnEntry(() => Commander.SetColors(Colors.Yellow));

            stateMachine.Configure(State.Starting)
                .Permit(Trigger.Finished, State.LookingForBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .OnEntry(() =>
                {
                    stopwatchTime = stopwatch.ElapsedMilliseconds;
                    SoundClipPlayer.PlayIntro();
                    Commander.SetColors(Colors.Cyan);
                });

            stateMachine.Configure(State.LookingForBall)
                .Permit(Trigger.CameraLockedOnBall, State.ClosingInOnBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .OnEntry(
                () =>
                {
                    Commander.SetColors(Colors.Blue);
                    stopwatchTime = stopwatch.ElapsedMilliseconds;
                });

            stateMachine.Configure(State.ClosingInOnBall)
                .Permit(Trigger.CameraLostBall, State.LookingForBall)
                .Permit(Trigger.BallCaught, State.FindingGoal)
                .Permit(Trigger.Timeout, State.LookingForBall)
                .OnEntry(() =>
                {
                    StartTimer(10000, Trigger.Timeout);
                    Commander.SetColors(Colors.Red);
                })
                .OnExit(StopTimer);

            stateMachine.Configure(State.FindingGoal)
                .Permit(Trigger.CoilgunLaunched, State.LookingForBall)
                .Permit(Trigger.BallLost, State.LookingForBall)
                .Permit(Trigger.Timeout, State.LookingForBall)
                .OnEntry(() =>
                {
                    LogicState.FindingGoal = true;
                    StartTimer(5000, LaunchBall);
                    Commander.SetColors(Colors.Magenta);
                })
                .OnExit(
                () =>
                {
                    LogicState.FindingGoal = false;
                    StopTimer();
                });

            stopwatch.Start();
        }