当前位置: 首页>>代码示例>>C#>>正文


C# InputState.IsKeyPressed方法代码示例

本文整理汇总了C#中GameStateManagement.InputState.IsKeyPressed方法的典型用法代码示例。如果您正苦于以下问题:C# InputState.IsKeyPressed方法的具体用法?C# InputState.IsKeyPressed怎么用?C# InputState.IsKeyPressed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameStateManagement.InputState的用法示例。


在下文中一共展示了InputState.IsKeyPressed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleInput

        public override void HandleInput(AxiosGameScreen gameScreen, InputState input, GameTime gameTime)
        {
            base.HandleInput(gameScreen, input, gameTime);
            //if (gameScreen.Console != null && gameScreen.Console.Active)
            //    return;
            PlayerIndex p;
            Animate = false;

            if (input.IsKeyPressed(Keys.A, PlayerIndex.One, out p))
            {
                Move(Direction.Left);
            }

            if (input.IsKeyPressed(Keys.W, PlayerIndex.One, out p) && !jumping)
            {
                Move(Direction.Up);
                jumping = true;
            }
            //else if (input.IsKeyPressed(Keys.S, PlayerIndex.One, out p))
            //{
            //    Move(Direction.Down);
            //}
            if (input.IsKeyPressed(Keys.D, PlayerIndex.One, out p))
            {
                Move(Direction.Right);
            }
            else
            {
                //BodyPart.LinearVelocity = Vector2.Zero;
            }
        }
开发者ID:nadams810,项目名称:axiosplatformer,代码行数:31,代码来源:Player.cs

示例2: OnInput

        public override void OnInput(InputState input)
        {
            Keys[] pressedKeys = input.NewPressedKeys().ToArray();
            for (int i = pressedKeys.Length - 1; i >= 0; i--)
            {
                Keys pressedKey = pressedKeys[i];
                int pressedKeyNum = (int)pressedKey;

                if (pressedKey >= Keys.A && pressedKey <= Keys.Z)
                {
                    Value += (char)((input.IsKeyPressed(Keys.LeftShift) || input.IsKeyPressed(Keys.RightShift)) ? pressedKeyNum : pressedKeyNum + 32);
                }
                else if (pressedKey == Keys.Space) Value += " ";
                else if (pressedKey == Keys.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1);

                //if (input.Mapping.Chars().ContainsKey(pressedKey)) Value += input.IsKeyPress(input.Mapping.Shift) ? input.Mapping.Chars()[pressedKey] : (char)(input.Mapping.Chars()[pressedKey] + 32);
                //else if (input.Mapping.Numbers().ContainsKey(pressedKey)) Value += input.Mapping.Numbers()[pressedKey].ToString();
                //else if (pressedKey == input.Mapping.Hyphen || pressedKey == Key.Minus) Value += input.IsKeyPress(Key.ShiftLeft) ? "_" : "-";
                //else if (pressedKey == input.Mapping.Point) Value += input.IsKeyPress(Key.ShiftLeft) ? ":" : ".";
                //else if (pressedKey == input.Mapping.Comma) Value += input.IsKeyPress(Key.ShiftLeft) ? ";" : ",";
                //else if (pressedKey == input.Mapping.Space) Value += " ";
                //else if (pressedKey == input.Mapping.Back && Value.Length > 0) Value = Value.Substring(0, Value.Length - 1);
            }
            base.OnInput(input);
        }
开发者ID:Xellss,项目名称:RougyMon,代码行数:25,代码来源:TextMenuEntry.cs

示例3: HandlePlayerInput

        private void HandlePlayerInput(GameTime gameTime, InputState input, PlayerIndex playerIndex)
        {
            Ship ship, enemyShip;
            if (playerIndex == ControllingPlayer)
            {
                ship = shipOne;
                enemyShip = shipTwo;
            }
            else
            {
                ship = shipTwo;
                enemyShip = shipOne;
            }

            PlayerIndex dummy;

            #if XBOX360
            if (input.IsButtonPressed(Buttons.A, playerIndex, out dummy) || input.IsKeyPressed(Keys.F, playerIndex, out dummy))
            {
                ship.FireBullet(ScreenManager, enemyShip);
            }

            if (input.IsButtonPressed(Buttons.B, playerIndex, out dummy) || input.IsKeyPressed(Keys.G, playerIndex, out dummy))
            {
                ship.FireMissile(ScreenManager, enemyShip);
            }
            #else

            #endif
        }
开发者ID:MarcusKhoo,项目名称:FlightOfGlory,代码行数:30,代码来源:GameplayScreen.cs

示例4: HandleInput

        /// <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(GameTime gameTime, InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            var playerIndex = (int) ControllingPlayer.Value;

            var keyboardState = input.CurrentKeyboardStates[playerIndex];

            playerIndex = input.CurrentGamePadStates[playerIndex + 4].IsConnected ? playerIndex + 4 : playerIndex;
            var gamePadState = input.CurrentGamePadStates[playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            var gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[playerIndex];

            PlayerIndex player;
            if (_pauseAction.Evaluate(input, ControllingPlayer, out player) || gamePadDisconnected)
            {
                ScreenManager.AddScreen(new PauseMenuScreen(), ControllingPlayer);
            }
            else
            {
                // Otherwise handle input.
                #region temporary keybord controls

                if (keyboardState.IsKeyDown(Keys.Home))
                    _camera.Pitch += .01f;
                if (keyboardState.IsKeyDown(Keys.End))
                    _camera.Pitch -= .01f;

                if (keyboardState.IsKeyDown(Keys.PageDown))
                    _camera.Translate(new Vector3(0, -.02f, 0));
                if (keyboardState.IsKeyDown(Keys.PageUp))
                    _camera.Translate(new Vector3(0, .02f, 0));

                // temporary camera controls
                if (input.IsKeyPressed(Keys.I, null, out player))
                    _camera.Translate(Vector3.UnitZ*-0.1f);
                if (input.IsKeyPressed(Keys.K, null, out player))
                    _camera.Translate(Vector3.UnitZ*0.1f);
                if (input.IsKeyPressed(Keys.J, null, out player))
                    _camera.Translate(Vector3.UnitX*-0.1f);
                if (input.IsKeyPressed(Keys.L, null, out player))
                    _camera.Translate(Vector3.UnitX*0.1f);

                // player 1 temporary controls)););)
                if (input.IsNewKeyPress(Keys.W, null, out player))
                    _puzzleBoard1.Up();
                if (input.IsNewKeyPress(Keys.S, null, out player))
                    _puzzleBoard1.Down();
                if (input.IsNewKeyPress(Keys.A, null, out player))
                    _puzzleBoard1.Left();
                if (input.IsNewKeyPress(Keys.D, null, out player))
                    _puzzleBoard1.Right();

                if (input.IsNewKeyPress(Keys.Q, null, out player))
                    _puzzleBoard1.Select();
                if (input.IsNewKeyPress(Keys.E, null, out player))
                    _puzzleBoard1.Accept();
                if (input.IsNewKeyPress(Keys.R, null, out player))
                    _puzzleBoard1.Randomize();

                // player 2 temporary controls
                if (input.IsNewKeyPress(Keys.Up, null, out player))
                    _puzzleBoard2.Up();
                if (input.IsNewKeyPress(Keys.Down, null, out player))
                    _puzzleBoard2.Down();
                if (input.IsNewKeyPress(Keys.Left, null, out player))
                    _puzzleBoard2.Left();
                if (input.IsNewKeyPress(Keys.Right, null, out player))
                    _puzzleBoard2.Right();
                if (input.IsNewKeyPress(Keys.RightControl, null, out player))
                    _puzzleBoard2.Select();
                if (input.IsNewKeyPress(Keys.Enter, null, out player))
                    _puzzleBoard2.Accept();
                if (input.IsNewKeyPress(Keys.Back, null, out player))
                    _puzzleBoard2.Randomize();

                if (keyboardState.IsKeyDown(Keys.Z))
                    _camera.Yaw += .01f;
                if (keyboardState.IsKeyDown(Keys.X))
                    _camera.Yaw -= .01f;

                // DEBUG, remove ASAP
                if (input.IsNewKeyPress(Keys.D1, null, out player))
                {
                    SpawnUnit("menele_ranged", _player1, Vector3.Zero);
                }
                if (input.IsNewKeyPress(Keys.D2, null, out player))
                {
                    SpawnUnit("menel_ram", _player1, Vector3.Zero);
//.........这里部分代码省略.........
开发者ID:szyszart,项目名称:Junkyard,代码行数:101,代码来源:GameplayScreen.cs


注:本文中的GameStateManagement.InputState.IsKeyPressed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。