Esempio n. 1
0
        public void Move(KeyboardState keyboardState, KeyboardState previousState)
        {
            ICommand cmd = null;

            if (keyboardState.IsKeyDown(Keys.W) && !previousState.IsKeyDown(Keys.W))
            {
                cmd = new MoveForward(this);
            }
            if (keyboardState.IsKeyDown(Keys.S) && !previousState.IsKeyDown(Keys.S))
            {
                cmd = new MoveBackward(this);
            }
            if (keyboardState.IsKeyDown(Keys.A) && !previousState.IsKeyDown(Keys.A))
            {
                cmd = new MoveLeft(this);
            }
            if (keyboardState.IsKeyDown(Keys.D) && !previousState.IsKeyDown(Keys.D))
            {
                cmd = new MoveRight(this);
            }

            if (cmd != null)
            {
                MoveMemory.SaveState(SaveMemento());
                cmd.Execute();
                Notify();
            }
        }
Esempio n. 2
0
        private static void BindKeys()
        {
            buttonW = new MoveForward();
            buttonS = new MoveBackward();
            buttonA = new MoveLeft();
            buttonD = new MoveRight();

            //buttonZ = new MoveForward();
        }
Esempio n. 3
0
 public InputHandler(Player player, TileMapFacade tileMapFacade)
 {
     this._player  = player;
     this._tilemap = tileMapFacade;
     //Bind keys with commands
     buttonW = new MoveForward();
     buttonS = new MoveBackward();
     buttonA = new MoveLeft();
     buttonD = new MoveRight();
 }
Esempio n. 4
0
 void Start()
 {
     moveforward  = new MoveFoward();
     movebackward = new MoveBackward();
     moveright    = new MoveRight();
     moveleft     = new MoveLeft();
     jump         = new Jump();
     forwardkey   = KeyCode.W;
     backwardkey  = KeyCode.S;
     leftkey      = KeyCode.A;
     rightkey     = KeyCode.D;
     jumpkey      = KeyCode.Space;
 }
Esempio n. 5
0
        public void Test()
        {
            var player = Substitute.For <IPlayer>();

            var moveForwardComment  = new MoveForward(player);
            var moveBackwardComment = new MoveBackward(player);

            var buttonHandler = new ButtonHandler(
                moveForwardComment,
                moveBackwardComment);

            var game = new Game(buttonHandler);

            game.OnButtonPress("up");
            game.OnButtonPress("up");
            game.OnButtonPress("down");

            game.UndoLastMove();
        }
 public void Handle(MoveBackward message)
 {
     _camera.MoveBackwardHorizontally(_settings.CameraMoveSpeedPerSecond * message.InputState.ElapsedTime.TotalSeconds);
 }
    // Method for handling global events in the Unity Editor.
    static void GlobalEventHandler()
    {
        // If a reference to the rig exists.
        if (Rig != null)
        {
            // Set Rig movements based on key combinations.
            Rig.MovingForward  = MoveForward.KeyCombinationDown();
            Rig.MovingBackward = MoveBackward.KeyCombinationDown();
            Rig.MovingLeft     = MoveLeft.KeyCombinationDown();
            Rig.MovingRight    = MoveRight.KeyCombinationDown();
            Rig.RotatingLeft   = RotateLeft.KeyCombinationDown();
            Rig.RotatingRight  = RotateRight.KeyCombinationDown();
            Rig.LookingUp      = LookUp.KeyCombinationDown();
            Rig.LookingDown    = LookDown.KeyCombinationDown();
        }

        // If a reference to the lefthand controller exists.
        if (LeftHandController != null)
        {
            // Presses up on the primary 2D axis for the lefthand controller.
            if (LeftAxisUp.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisUp();
            }

            // Presses down on the primary 2D axis for the lefthand controller.
            if (LeftAxisDown.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisDown();
            }

            // Presses left on the primary 2D axis for the lefthand controller.
            if (LeftAxisLeft.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisLeft();
            }

            // Presses right on the primary 2D axis for the lefthand controller.
            if (LeftAxisRight.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.TouchAxisRight();
            }

            // Touches or untouhces the primary 2D axis for the lefthand controller.
            if (LeftAxisTouch.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.Touch = !LeftHandController.Primary2DAxis.Touch;
            }

            // Clicks or unclicks the primary 2D axis for the lefthand controller.
            if (LeftAxisClick.KeyCombinationClick())
            {
                LeftHandController.Primary2DAxis.Click = !LeftHandController.Primary2DAxis.Click;
            }

            // Clicks or unclicks the trigger button for the lefthand controller.
            if (LeftTriggerButton.KeyCombinationClick())
            {
                LeftHandController.Trigger.Button = !LeftHandController.Trigger.Button;
            }

            // Clicks or unclicks the grip button for the lefthand controller.
            if (LeftGripButton.KeyCombinationClick())
            {
                LeftHandController.Grip.Button = !LeftHandController.Grip.Button;
            }

            // Clicks or unclicks the primary button for the lefthand controller.
            if (LeftPrimaryButton.KeyCombinationClick())
            {
                LeftHandController.PrimaryButton.Button = !LeftHandController.PrimaryButton.Button;
            }
        }

        // If a reference to the righthand controller exists.
        if (RightHandController != null)
        {
            // Presses up on the primary 2D axis for the righthand controller.
            if (RightAxisUp.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisUp();
            }

            // Presses down on the primary 2D axis for the righthand controller.
            if (RightAxisDown.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisDown();
            }

            // Presses left on the primary 2D axis for the righthand controller.
            if (RightAxisLeft.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisLeft();
            }

            // Presses right on the primary 2D axis for the righthand controller.
            if (RightAxisRight.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.TouchAxisRight();
            }

            // Touches or untouhces the primary 2D axis for the righthand controller.
            if (RightAxisTouch.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.Touch = !RightHandController.Primary2DAxis.Touch;
            }

            // Clicks or unclicks the primary 2D axis for the righthand controller.
            if (RightAxisClick.KeyCombinationClick())
            {
                RightHandController.Primary2DAxis.Click = !RightHandController.Primary2DAxis.Click;
            }

            // Clicks or unclicks the trigger button for the righthand controller.
            if (RightTriggerButton.KeyCombinationClick())
            {
                RightHandController.Trigger.Button = !RightHandController.Trigger.Button;
            }

            // Clicks or unclicks the grip button for the righthand controller.
            if (RightGripButton.KeyCombinationClick())
            {
                RightHandController.Grip.Button = !RightHandController.Grip.Button;
            }

            // Clicks or unclicks the primary button for the righthand controller.
            if (RightPrimaryButton.KeyCombinationClick())
            {
                RightHandController.PrimaryButton.Button = !RightHandController.PrimaryButton.Button;
            }
        }
    }