Пример #1
0
        /// <summary>
        /// Handle input.
        /// </summary>
        /// <param name="input">The current state of input.</param>
        public override void HandleInput(InputState input)
        {
            // Call the base method.
            base.HandleInput(input);

            // If the player can't be controlled, end here.
            if (!_CanBeControlled) { return; }

            // Left, right, up, down and space.
            if (input.IsKeyDown(Keys.Left) && (_Body.Velocity.X > -_MaxSpeed)) { _Body.AddForce(new Vector3(-_Body.AccelerationValue, 0, 0)); }
            if (input.IsKeyDown(Keys.Right) && (_Body.Velocity.X < _MaxSpeed)) { _Body.AddForce(new Vector3(_Body.AccelerationValue, 0, 0)); }
            if (input.IsKeyDown(Keys.Up) && (_Body.Velocity.Y > -_MaxSpeed)) { _Body.AddForce(new Vector3(0, -_Body.AccelerationValue, 0)); }
            if (input.IsKeyDown(Keys.Down) && (_Body.Velocity.Y < _MaxSpeed)) { _Body.AddForce(new Vector3(0, _Body.AccelerationValue, 0)); }
            if (input.IsKeyDown(Keys.Space) && Math.Abs(_Body.Velocity.Z) < 1) { _Body.AddForce(new Vector3(0, 0, _Body.AccelerationValue)); }
        }
Пример #2
0
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null) { throw new ArgumentNullException("input"); }

            if (input.PauseGame)
            {
                // If they pressed pause, bring up the pause menu screen.
                ScreenManager.AddScreen(new PauseMenuScreen());
            }
            else
            {
                //Let the scene handle input.
                _Scene.HandleInput(input);

                //Move the camera.
                if (input.IsKeyDown(Keys.A)) { _Camera.Move(new Vector2(-1, 0)); }
                else if (input.IsKeyDown(Keys.S)) { _Camera.Move(new Vector2(0, 1)); }
                else if (input.IsKeyDown(Keys.D)) { _Camera.Move(new Vector2(1, 0)); }
                else if (input.IsKeyDown(Keys.W)) { _Camera.Move(new Vector2(0, -1)); }

                //Zoom the camera.
                if (input.IsKeyDown(Keys.Z)) { _Camera.Zoom(.1f); }
                else if (input.IsKeyDown(Keys.X)) { _Camera.Zoom(-.1f); }
            }
        }
Пример #3
0
        /// <summary>
        /// Handle input.
        /// </summary>
        /// <param name="input">The current input state.</param>
        public void HandleInput(InputState input)
        {
            //Rotation.
            if (input.IsKeyDown(Keys.Left)) { _XRotation += _RotationSpeed; }
            if (input.IsKeyDown(Keys.Right)) { _XRotation += -_RotationSpeed; }
            if (input.IsKeyDown(Keys.Down)) { _YRotation += -_RotationSpeed; }
            if (input.IsKeyDown(Keys.Up)) { _YRotation += _RotationSpeed; }

            //Movement.
            if (input.IsKeyDown(Keys.W)) { MoveCamera(new Vector3(0, 0, -1)); }
            if (input.IsKeyDown(Keys.S)) { MoveCamera(new Vector3(0, 0, 1)); }
            if (input.IsKeyDown(Keys.A)) { MoveCamera(new Vector3(-1, 0, 0)); }
            if (input.IsKeyDown(Keys.D)) { MoveCamera(new Vector3(1, 0, 0)); }
            if (input.IsKeyDown(Keys.E)) { MoveCamera(new Vector3(0, 1, 0)); }
            if (input.IsKeyDown(Keys.Q)) { MoveCamera(new Vector3(0, -1, 0)); }

            //Camera speed.
            if (input.IsKeyDown(Keys.Space)) { _MoveSpeed = (_MoveSpeed == 10) ? 250 : 10; }
        }