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


C# InputState.IsNewKeyPress方法代码示例

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


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

示例1: Evaluate

        public bool Evaluate(InputState state)
        {
            foreach (Keys key in keys)
            {
                if (isNewPressOnly)
                {
                    if (state.IsNewKeyPress(key))
                    {
                        return true;
                    }
                }
                else
                {
                    if (state.IsKeyPressed(key))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:Grahamcraker,项目名称:Project_Greenhorn,代码行数:22,代码来源:InputAction.cs

示例2: HandleInput

        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public void HandleInput(InputState input)
        {
            Vector2 mouseFocus = new Vector2(-1, -1);

            // Check NumPad and Number Keys for manual number entering
            String keyString;
            Keys key = new Keys();
            int keyboardInt = -1;
            for (int i = 0; i < 10; i++)
            {
                keyString = "D" + i.ToString();
                key = (Keys)Enum.Parse(typeof(Keys), keyString);
                if (input.IsNewKeyPress(key))
                    keyboardInt = i;
                keyString = "NumPad" + i.ToString();
                key = (Keys)Enum.Parse(typeof(Keys), keyString);
                if (input.IsNewKeyPress(key))
                    keyboardInt = i;
            }

            if (keyboardInt != -1)
                AddToAnswer(keyboardInt.ToString());

            if ( input.IsMouseChanged() ||input.IsMousePressed())
                mouseFocus = buttonTable.CheckFocus(input);

            if (mouseFocus.X != -1)
            {
                focus = mouseFocus;
                if (input.IsNewMouseReleased())
                    HandleButtonInput();
            }
            else
            {
                buttonTable.SetPressed(focus, false);
                buttonTable.SetFocus(focus, false);
                // Move up?
                if (input.IsMenuUp())
                {
                    focus = new Vector2(focus.X, focus.Y - 1);

                    if (focus.Y < 1)
                        focus.Y = buttonTable.Rows;
                }

                // Move down?
                if (input.IsMenuDown())
                {
                    focus = new Vector2(focus.X, focus.Y + 1);

                    if (focus.Y > buttonTable.Rows)
                        focus.Y = 1;
                }

                // Move left?
                if (input.IsMenuLeft())
                {
                    focus = new Vector2(focus.X - 1, focus.Y);

                    if (focus.X < 1)
                        focus.X = buttonTable.Cols;
                }

                // Move right?
                if (input.IsMenuRight())
                {
                    focus = new Vector2(focus.X + 1, focus.Y);

                    if (focus.X > buttonTable.Cols)
                        focus.X = 1;
                }
                buttonTable.SetFocus(focus, true);
            }

            // Check if the button is being pressed or if the user
            // is asking to exit the screen.

            if (input.IsMenuSelect())
            {
                HandleButtonInput();
                buttonTable.SetPressed(focus, true);
            }
            else if (input.IsMenuCancel())
            {
                Exiting = true;
            }
        }
开发者ID:Ben-Cortina,项目名称:Times-Table,代码行数:91,代码来源:Test.cs

示例3: HandleInput

        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            if (input.IsNewKeyPress(Keys.Escape, ControllingPlayer, out playerIndex))
            {
                var bgScreen = new BackgroundScreen();
                var mmScreen = new MainMenuScreen();
                LoadingScreen.Load(ScreenManager, true, ControllingPlayer, bgScreen, mmScreen);
            }

            if (input.IsNewKeyPress(Keys.Left, ControllingPlayer, out playerIndex))
            {
                if (Players[(int)playerIndex].Body.Blocks.First().Direction != SnakeDirection.Right)
                    Players[(int)playerIndex].Direction = SnakeDirection.Left;
            }

            if (input.IsNewKeyPress(Keys.Up, ControllingPlayer, out playerIndex))
            {
                if (Players[(int)playerIndex].Body.Blocks.First().Direction != SnakeDirection.Down)
                    Players[(int)playerIndex].Direction = SnakeDirection.Up;
            }

            if (input.IsNewKeyPress(Keys.Right, ControllingPlayer, out playerIndex))
            {
                if (Players[(int)playerIndex].Body.Blocks.First().Direction != SnakeDirection.Left)
                    Players[(int)playerIndex].Direction = SnakeDirection.Right;
            }

            if (input.IsNewKeyPress(Keys.Down, ControllingPlayer, out playerIndex))
            {
                if (Players[(int)playerIndex].Body.Blocks.First().Direction != SnakeDirection.Up)
                    Players[(int)playerIndex].Direction = SnakeDirection.Down;
            }
        }
开发者ID:Layoric,项目名称:RonaldTheSnake,代码行数:35,代码来源:SnakeWorld.cs

示例4: HandleInput

        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;
            if (_createProfile)
            {
                if (input.IsNewKeyPress(Keys.Escape, ControllingPlayer, out playerIndex))
                {
                    _createProfile = false;
                    return;
                }
                if (input.IsNewKeyPress(Keys.Enter, ControllingPlayer, out playerIndex))
                {
                    if (_saveable)
                    {
                        if (_pl.Profiles.Any(player => player.Name == _newProfileName))
                        {
                            return;
                        }
                        if (_pl.Profiles != null)
                        {
                            _pl.Profiles.Add(new Profile(_newProfileName));
                            MenuEntries.Clear();
                            FillMenuItems();
                            PlayerListStorage.Save();
                            _createProfile = false;
                            _newProfileName = "";
                            _input = "";
                        }
                    }
                    return;
                }

                var i = (int)playerIndex;
                var selected = false;
                var pressed = "";
                foreach (var key in input.CurrentKeyboardStates[i].GetPressedKeys())
                {
                    if (input.LastKeyboardStates[i].IsKeyUp(key) && !selected)
                    {
                        var keyNum = (int)key;
                        if (key == Keys.Back && _input.Length > 0)
                        {
                            _input = _input.Substring(0, _input.Length - 1);
                            return;
                        }
                        if (_input.Length > 9)
                        {
                            return;
                        }
                        if (keyNum >= (int)Keys.A && keyNum <= (int)Keys.Z)
                        {
                            selected = true;
                            pressed = key.ToString();
                        }
                        else if (keyNum >= (int)Keys.D0 && keyNum <= (int)Keys.D9)
                        {
                            selected = true;
                            pressed = key.ToString().Substring(1, 1);
                        }
                    }
                    if ((key == Keys.RightShift || key == Keys.LeftShift))
                    {
                        _shift = true;
                    }
                    else
                    {
                        _shift = false;
                    }
                }

                if (!string.IsNullOrEmpty(pressed))
                {
                    if (!_shift)
                    {
                        _input += pressed.ToLower();
                    }
                    else
                    {
                        _input += pressed.ToUpper();
                    }
                }

                if (_input.Length > 4)
                {
                    _saveable = true;
                }

            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                return;
            }
            else
            {
                base.HandleInput(input);
            }
        }
开发者ID:CTU-FEE-Y39PHA-43-2010,项目名称:BombermanAdventure,代码行数:97,代码来源:ProfileScreen.cs

示例5: 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(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

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

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            PlayerIndex player;
            if (input.IsPauseGame(ControllingPlayer))
            {
                PauseBackgroundScreen pauseBG = new PauseBackgroundScreen();
                ScreenManager.AddScreen(pauseBG, ControllingPlayer);
                ScreenManager.AddScreen(new PauseMenuScreen(pauseBG), ControllingPlayer);

            }

            if(IsActive)
            {
                if (input.MouseDragging)
                {
                    gameCamera.Target -= input.MouseDelta;
                    //gameCamera.cl
                }

                if (input.DragGesture.HasValue)
                {
                    gameCamera.Target -= input.DragGesture.Value.Delta;
                }

                if (input.IsNewKeyPress(Keys.Space, null, out player)) gameHero.Position = gameHero.SpawnPoint;

                if (!gameButtonManager.HandleInput(input))
                {
                    if (input.TapPosition.HasValue)
                    {
                        Vector2 tapPos = input.TapPosition.Value;

                        tapPos += gameCamera.Position;

                        Point tilePos = new Point((int)tapPos.X / 64, (int)tapPos.Y / 64);

                        var t = gameMap.Layers.Where(l => l.Name == "FG").First();
                        TileLayer tileLayer = t as TileLayer;

                        bool found = false;

                        int type = gameButtonManager.SelectedButton;

                        if (gameButtonManager.Buttons[gameButtonManager.SelectedButton].CurrentCoolDown <= 0)
                        {

                            if (type != 4)
                            {
                                if (tilePos.X >= tileLayer.Tiles.GetLowerBound(0) || tilePos.X <= tileLayer.Tiles.GetUpperBound(0) &&
                                    tilePos.Y >= tileLayer.Tiles.GetLowerBound(1) || tilePos.Y <= tileLayer.Tiles.GetUpperBound(1))
                                {
                                    if (tileLayer.Tiles[tilePos.X, tilePos.Y] != null)
                                    {
                                        while (!found)
                                        {
                                            if (tilePos.X >= tileLayer.Tiles.GetLowerBound(0) || tilePos.X <= tileLayer.Tiles.GetUpperBound(0) &&
                                                tilePos.Y >= tileLayer.Tiles.GetLowerBound(1) || tilePos.Y <= tileLayer.Tiles.GetUpperBound(1))
                                            {
                                                if (tileLayer.Tiles[tilePos.X, tilePos.Y] != null)
                                                {
                                                    if (tilePos.Y - 1 >= tileLayer.Tiles.GetLowerBound(1))
                                                    {
                                                        if (tileLayer.Tiles[tilePos.X, tilePos.Y - 1] == null)
                                                        {
                                                            gameMinionManager.Add(new Vector2((tilePos.X * 64) + 32, (tilePos.Y * 64) - 32), type);
                                                            gameButtonManager.Buttons[gameButtonManager.SelectedButton].CurrentCoolDown = gameButtonManager.Buttons[gameButtonManager.SelectedButton].CoolDown;
                                                            found = true;
                                                        }
                                                        else tilePos.Y -= 1;
                                                    }
                                                    else found = true;
                                                }
                                                else found = true;

                                            }
                                            else found = true;
                                        }
                                    }
                                    else
                                    {
                                        while (!found)
                                        {
                                            if (tilePos.X >= tileLayer.Tiles.GetLowerBound(0) || tilePos.X <= tileLayer.Tiles.GetUpperBound(0) &&
                                                tilePos.Y >= tileLayer.Tiles.GetLowerBound(1) || tilePos.Y <= tileLayer.Tiles.GetUpperBound(1))
                                            {
                                                if (tileLayer.Tiles[tilePos.X, tilePos.Y] == null)
                                                {
//.........这里部分代码省略.........
开发者ID:GarethIW,项目名称:HeroBash,代码行数:101,代码来源:GameplayScreen.cs

示例6: HandleResource

        public override void HandleResource(InputState input, ResourceBuilding resourceBuilding)
        {
            Control control = Controls.Selection;
            if ((control != null && control.Name.Contains("Unload")) ||
                ((input.IsNewKeyPress(Keys.F, null)) ||
                    (input.IsNewKeyPress(Keys.C, null))))
            {
                _parachuteBox.HandleInput(Position);

                IsWithinTargetRange = false;
                if (_parachuteBox.Bounds.Intersects(resourceBuilding.Bounds)) {

                    /*Color[] buildingTextureData = new Color[resourceBuilding.Texture.Width * resourceBuilding.Texture.Height];
                    resourceBuilding.Texture.GetData(buildingTextureData);

                    if (IntersectPixels(_parachuteBox.Bounds,
                                        _parachuteBox.TextureData,
                                        resourceBuilding.Bounds,
                                        buildingTextureData)) */{
                        IsWithinTargetRange = true;
                    }
                }
            }

            base.HandleResource(input, resourceBuilding);
        }
开发者ID:Righteous-Noodle,项目名称:Eva-Frontier,代码行数:26,代码来源:UAV.cs

示例7: HandleResource

        public virtual void HandleResource(InputState input, ResourceBuilding resourceBuilding)
        {
            Control control = Controls.Selection;
            if ((control != null && control.Name == "LoadFood") ||
                (input.CurrentKeyboardStates[1].IsKeyDown(Keys.LeftControl) &&
                    input.IsNewKeyPress(Keys.F, null)))
            {
                LoadResource("Food", resourceBuilding);
                _sfxLoading.Play();
            }
            else if ((control != null && control.Name == "LoadMedicine") ||
                (input.CurrentKeyboardStates[1].IsKeyDown(Keys.LeftControl) &&
                   input.IsNewKeyPress(Keys.C, null)))
            {
                LoadResource("Medicine", resourceBuilding);
                _sfxLoading.Play();
            }
            else if ((control != null && control.Name == "UnloadFood") ||
                (input.IsNewKeyPress(Keys.F, null)))
            {
                UnloadResource("Food", resourceBuilding);
                _sfxUnloading.Play();
            }
            else if ((control != null && control.Name == "UnloadMedicine") ||
                (input.IsNewKeyPress(Keys.C, null)))
            {
                UnloadResource("Medicine", resourceBuilding);
                _sfxUnloading.Play();
            }

            if (control != null) control.IsSelected = false;
        }
开发者ID:Righteous-Noodle,项目名称:Eva-Frontier,代码行数:32,代码来源:Unit.cs


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