示例#1
0
 private void PlaceSelectedBlock(Blocks selectedItem)
 {
     _world.PlaceBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY(), selectedItem);
 }
示例#2
0
        public void PlayerInput(GameTime gameTime)
        {
            const float movementSpeed = IRestrictions.MovementSpeed;
            var         keyboardState = Keyboard.GetState();
            var         mouseState    = Mouse.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                _main.Quit();
            }

            if (keyboardState.IsKeyUp(Keys.W) && keyboardState.IsKeyUp(Keys.A) && keyboardState.IsKeyUp(Keys.S) &&
                keyboardState.IsKeyUp(Keys.D))
            {
                Input = "Idle";
            }
            UpdateAnimationFrame(gameTime);
            const float diagonalMovement = 0.707f;

            if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.D))
            {
                Input = "UpRight";
                _player.Move(_cam, movementSpeed * diagonalMovement, -movementSpeed * diagonalMovement);
            }
            else if (keyboardState.IsKeyDown(Keys.W) && keyboardState.IsKeyDown(Keys.A))
            {
                _player.Move(_cam, -movementSpeed * diagonalMovement, -movementSpeed * diagonalMovement);
                Input = "UpLeft";
            }
            else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.D))
            {
                Input = "DownRight";
                _player.Move(_cam, movementSpeed * diagonalMovement, movementSpeed * diagonalMovement);
            }
            else if (keyboardState.IsKeyDown(Keys.S) && keyboardState.IsKeyDown(Keys.A))
            {
                Input = "DownLeft";
                _player.Move(_cam, -movementSpeed * diagonalMovement, movementSpeed * diagonalMovement);
            }
            else if (keyboardState.IsKeyDown(Keys.W))
            {
                Input = "Up";
                _player.Move(_cam, 0, -movementSpeed);
            }
            else if (keyboardState.IsKeyDown(Keys.A))
            {
                Input = "Left";
                _player.Move(_cam, -movementSpeed, 0);
            }
            else if (keyboardState.IsKeyDown(Keys.S))
            {
                Input = "Down";
                _player.Move(_cam, 0, movementSpeed);
            }
            else if (keyboardState.IsKeyDown(Keys.D))
            {
                Input = "Right";
                _player.Move(_cam, movementSpeed, 0);
            }
            if (keyboardState.IsKeyDown(Keys.Q))
            {
                _cam.ZoomIn(1f);
            }
            if (keyboardState.IsKeyDown(Keys.E))
            {
                _cam.ZoomOut(1f);
            }
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                _world.RemoveBlock(PlayerMouse.GetSelectedX(), PlayerMouse.GetSelectedY());
            }
            if (mouseState.RightButton == ButtonState.Pressed)
            {
                PlaceSelectedBlock(Inventory.GetSelectedItem());
            }
        }