private void UpdateInput(double elapsedTime) { if (_input.Keyboard.IsKeyPressed(Keys.Space)) { _playerCharacter.Fire(); } Vector controlInput = new Vector(); if (_input.Keyboard.IsKeyHeld(Keys.Left)) { controlInput.X = -1; } if (_input.Keyboard.IsKeyHeld(Keys.Right)) { controlInput.X = 1; } if (_input.Keyboard.IsKeyHeld(Keys.Up)) { controlInput.Y = 1; } if (_input.Keyboard.IsKeyHeld(Keys.Down)) { controlInput.Y = -1; } // Get controls and apply to player character if (_input.Controller != null) { double x = _input.Controller.LeftControlStick.X; double y = _input.Controller.LeftControlStick.Y * -1; controlInput = new Vector(x, y, 0); if (_input.Controller.ButtonA.Pressed) { _playerCharacter.Fire(); } } _playerCharacter.Move(controlInput * elapsedTime); }
private void UpdateInput(double elapsedTime) { if (_input.Keyboard.IsKeyPressed(Keys.Space) || _input.Controller.ButtonA.Pressed) { _playerCharacter.Fire(); } // Get controls and apply to player character double _x = _input.Controller.LeftControlStick.X; double _y = _input.Controller.LeftControlStick.Y * -1; Vector controlInput = new Vector(_x, _y, 0); if (Math.Abs(controlInput.Length()) < 0.0001) { // If the input is very small, then the player may not be using // a controller;, they might be using the keyboard. if (_input.Keyboard.IsKeyHeld(Keys.Left)) { controlInput.X = -1; } if (_input.Keyboard.IsKeyHeld(Keys.Right)) { controlInput.X = 1; } if (_input.Keyboard.IsKeyHeld(Keys.Up)) { controlInput.Y = 1; } if (_input.Keyboard.IsKeyHeld(Keys.Down)) { controlInput.Y = -1; } } _playerCharacter.Move(controlInput * elapsedTime); }