• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Input.KeyboardState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Xna.Framework.Input.KeyboardState的典型用法代码示例。如果您正苦于以下问题:C# KeyboardState类的具体用法?C# KeyboardState怎么用?C# KeyboardState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



KeyboardState类属于Microsoft.Xna.Framework.Input命名空间,在下文中一共展示了KeyboardState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Update

        public override void Update()
        {
            // Bounding Box
            rectangle = new Rectangle
            (
                (int)Position.X,
                (int)Position.Y,
                (int)Size.X,
                (int)Size.Y
            );

            KeyboardState keyboardState = Keyboard.GetState();
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                Position += movingVector;
                body.ApplyLinearImpulse(movingImpulse);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                Position -= movingVector;
                body.ApplyLinearImpulse(-movingImpulse);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) && !prevKeyboardState.IsKeyDown(Keys.W))
            {
                if ((DateTime.Now - previousJump).TotalSeconds >= jumpInterval)
                {
                    jumpEffect.Play();
                    body.ApplyLinearImpulse(jumpingImpulse);
                    previousJump = DateTime.Now;
                }
            }

            prevKeyboardState = keyboardState;
        }
开发者ID:rolandKulcsar,项目名称:Crate-Game,代码行数:34,代码来源:Player.cs


示例2: move

        public override void move(ArrayList colidables)
        {
            KeyboardState newKeyBoardState = Keyboard.GetState();
            if (newKeyBoardState.IsKeyDown(Keys.Up))
            {
                if (checkCollision(colidables, 0, +velocity) == true)
                    y -= velocity;
            }
            else if (newKeyBoardState.IsKeyDown(Keys.Down))
            {
                if (checkCollision(colidables, 0, -velocity) == true)
                    y += velocity;
            }
            else if (newKeyBoardState.IsKeyDown(Keys.Left))
            {
                if (checkCollision(colidables, velocity, 0) == true)
                     x -= velocity;
            }
            else if (newKeyBoardState.IsKeyDown(Keys.Right))
            {
                if (checkCollision(colidables, -velocity, 0) == true)
                    x += velocity;
            }

            oldKeyBoardState = newKeyBoardState;
            hitBox = new Rectangle(x, y, width, height);
        }
开发者ID:idickson0,项目名称:Toggle,代码行数:27,代码来源:Player.cs


示例3: Update

        public int Update(GameTime gameTime)
        {
            KeyboardState keyState;
            keyState = Keyboard.GetState(PlayerIndex.One);

            if (keyState.IsKeyDown(Keys.Up) && !prevKeyState.IsKeyDown(Keys.Up))
            {
                if (selected > 0)
                {
                    selected--;
                }
            }

            if (keyState.IsKeyDown(Keys.Down) && !prevKeyState.IsKeyDown(Keys.Down))
            {
                if (selected < buttonList.Count - 1)
                {
                    selected++;
                }
            }

            if (keyState.IsKeyDown(Keys.Enter))
            {
                return selected;
            }

            prevKeyState = keyState;
            return -1;
        }
开发者ID:vaskosound,项目名称:JustCoyote,代码行数:29,代码来源:Menu.cs


示例4: Console

 private Console()
 {
     booleanValues = new Dictionary<string, bool>();
     floatValues = new Dictionary<string, float>();
     integerValues = new Dictionary<string, int>();
     integerValues.Add("consoleHeight", 512);
     integerValues.Add("consoleWidth", 768);
     integerValues.Add("consolePositionX", 64);
     integerValues.Add("consolePositionY", 64);
     integerValues.Add("consoleBorderWidth", 16);
     integerValues.Add("consoleAlpha", 220);
     booleanValues.Add("consoleActive", false);
     commandHistory = new ConsoleHistory(120);
     messageHistory = new ConsoleHistory(120);
     lines = new List<String>();
     currentCommand = "";
     lastState = new KeyboardState();
     booleanValues.Add("texInfo", false);
     booleanValues.Add("meshCountInfo", false);
     booleanValues.Add("showPosition", false);
     booleanValues.Add("occluderInfo", false);
     booleanValues.Add("drawshadowtex", false);
     booleanValues.Add("glow", true);
     floatValues.Add("hdrpower", 4.0f);
 }
开发者ID:slicedpan,项目名称:demo,代码行数:25,代码来源:Console.cs


示例5: Update

 public void Update()
 {
     previousMouseState = currentMouseState;
     previousKeyboardState = currentKeyboardState;
     currentMouseState = Mouse.GetState();
     currentKeyboardState = Keyboard.GetState();
 }
开发者ID:TheHappyCow,项目名称:TickTick,代码行数:7,代码来源:InputHelper.cs


示例6: Input

 public Input(MouseState cms, MouseState pms, KeyboardState cks, KeyboardState pks)
 {
     Pms = pms;
     Pks = pks;
     Cms = cms;
     Cks = cks;
 }
开发者ID:JaapSuter,项目名称:Pentacorn,代码行数:7,代码来源:Input.cs


示例7: HandleKeyboardInput

 public override void HandleKeyboardInput(KeyboardState oldKeyboardState)
 {
     KeyboardState currentKeyboardState = Keyboard.GetState();
     if (currentKeyboardState.IsKeyDown(Keys.Escape)
         && oldKeyboardState.IsKeyUp(Keys.Escape))
         videoPlayer.Stop();
 }
开发者ID:verngutz,项目名称:MoodSwing,代码行数:7,代码来源:MSIntroScreen.cs


示例8: kill

 public void kill(KeyboardState kb, MouseState ms)
 {
     stateTimer = 0.0f;
     state = State.EXIT;
     this.update(kb, ms);
     this.init();
 }
开发者ID:rhyok,项目名称:huewgj2013,代码行数:7,代码来源:AMinigame.cs


示例9: accessObject

        public void accessObject(LLESprite playerCharacter, KeyboardState keyboardState, KeyboardState prevKeyboardState)
        {
            mPlayerCharacter = playerCharacter;

            if (playerCharacter != null && (playerCharacter.getDirection() == LLESprite.DIRECTION_UP || playerCharacter.getDirection() == LLESprite.DIRECTION_LEFT_UP || playerCharacter.getDirection() == LLESprite.DIRECTION_RIGHT_UP)

                && keyboardState.IsKeyDown(Keys.Z) == true && prevKeyboardState.IsKeyDown(Keys.Z) == false)
            {
                for (int i = 0; i < mapObjects.Count; i++)
                {
                    if (mapObjects[i] != null && mapObjects[i].getSprite() != null)
                    {
                        LLESprite target = mapObjects[i].getSprite();

                        if (playerCharacter.isCollidingMap(new Vector4(target.getX(), target.getY(), target.getHeight(), target.getWidth()), new Vector2(cameraX, cameraY), false, true, 4) == true)
                        {
                            scriptProcessor.extractObjectVariables(mapObjects[i]);

                            attack = false;

                            break;
                        }
                    }
                }
            }
        }
开发者ID:caiodantas,项目名称:LemonLiteEngine,代码行数:26,代码来源:LLEMapFrontLayer.cs


示例10: Check

 public void Check(KeyboardState last, KeyboardState curr)
 {
     if (last == null)
         return;
     if (!matchMods(curr))
         return;
     switch (KeyEvent)
     {
         case KeyEvent.Released:
             if (!(keyDown(Key, last) && keyUp(Key, curr)))
                 return;
             break;
         case KeyEvent.Pressed:
             if (!(keyUp(Key, last) && keyDown(Key, curr)))
                 return;
             break;
         case KeyEvent.Down:
             if (!(keyDown(Key, curr)))
                 return;
             break;
         case KeyEvent.Up:
             if (!(keyUp(Key, curr)))
                 return;
             break;
         default:
             return;
     }
     // we made it through! Do something freakin' awesome
     CallDelegate();
 }
开发者ID:colbybhearn,项目名称:3DPhysics,代码行数:30,代码来源:KeyBinding.cs


示例11: Update

        public static void Update(MouseState mouse, KeyboardState keyboard)
        {
            MouseMoving(mouse);
            MouseClicking(mouse);

            DevInput(mouse, keyboard);
        }
开发者ID:Ascendzor,项目名称:Viper,代码行数:7,代码来源:Input.cs


示例12: Update

    public void Update(KeyboardState k)
    {
        PressedFire = IsPressed(k, Fire, FireKey);
        PressedBlock = IsPressed(k, Block, BlockKey);
        PressedSpecial = IsPressed(k, Special, SpecialKey);
        PressedUse = IsPressed(k, Use, UseKey);

        PressedUp = IsPressed(k, Up, UseKey);
        PressedLeft = IsPressed(k, Left, LeftKey);
        PressedRight = IsPressed(k, Right, RightKey);
        PressedDown = IsPressed(k, Down, DownKey);

        PressedInventoryR = IsPressed(k, InventoryR, InventoryRKey);
        PressedInventoryL = IsPressed(k, InventoryL, InventoryLKey);
        PressedStart = IsPressed(k, Start, StartKey);

        Fire = IsHeld(k, Fire, FireKey);
        Block = IsHeld(k, Block, BlockKey);
        Special = IsHeld(k, Special, SpecialKey);
        Use = IsHeld(k, Use, UseKey);

        Up = IsHeld(k, Up, UpKey);
        Left = IsHeld(k, Left, LeftKey);
        Right = IsHeld(k, Right, RightKey);
        Down = IsHeld(k, Down, DownKey);

        InventoryR = IsHeld(k, InventoryR, InventoryRKey);
        InventoryL = IsHeld(k, InventoryL, InventoryLKey);
        Start = IsHeld(k, Start, StartKey);
    }
开发者ID:WJLiddy,项目名称:CastleSpire,代码行数:30,代码来源:KeyboardInput.cs


示例13: Update

        public void Update(Player player, KeyboardState keyboard, MouseState mouse, Engine engine)
        {
            // Rortational Origin
            Rectangle originRect = new Rectangle((int)position.X, (int)position.Y,
                (int)texture.Width, (int)texture.Height);
            origin = new Vector2(originRect.Width / 2, originRect.Height / 2);

            int viewDistance = 200;

            double distance = Math.Sqrt(Math.Pow(player.position.X - position.X, 2) +
                Math.Pow(player.position.Y - position.Y, 2));

            if (distance < viewDistance)
            {
                float deltaX = player.position.X - position.X;
                float deltaY = player.position.Y - position.Y;
                float radians = (float)Math.Atan2(deltaY, deltaX);
                setRotation(radians);

                float zombieSpeed = 1.5f;
                float dx = (float) Math.Cos(rotation) * zombieSpeed;
                float dy = (float) Math.Sin(rotation) * zombieSpeed;
                position.X += dx;
                position.Y += dy;
            }
        }
开发者ID:nfsz,项目名称:Zombie,代码行数:26,代码来源:Zombie.cs


示例14: Update

        public void Update(KeyboardState keyboard, MouseState mouse, Engine engine)
        {
            // Rortational Origin
            Rectangle originRect = new Rectangle((int) position.X, (int) position.Y,
                (int) texture.Width, (int) texture.Height);
            origin = new Vector2(originRect.Width / 2, originRect.Height / 2);

            int playerSpeed = 2;

            if (keyboard.IsKeyDown(Keys.A))
                position.X -= playerSpeed;

            if (keyboard.IsKeyDown(Keys.D))
                position.X += playerSpeed;

            if (keyboard.IsKeyDown(Keys.W))
                position.Y -= playerSpeed;

            if (keyboard.IsKeyDown(Keys.S))
                position.Y += playerSpeed;

            float deltaY = mouse.Y - position.Y;
            float deltaX = mouse.X - position.X;
            float radians = (float) Math.Atan2(deltaY, deltaX);
            setRotation(radians);
        }
开发者ID:nfsz,项目名称:Zombie,代码行数:26,代码来源:Player.cs


示例15: UpdateKeyboard

        public void UpdateKeyboard(KeyboardState keyboardState)
        {
            float moveX = 0f;
            float moveY = 0f;
            float oldX = scene.paddlePos.X;
            float oldY = scene.paddlePos.Y;

            if (keyboardState.IsKeyDown(Keys.Down) || keyboardState.IsKeyDown(Keys.S))      //down
            {
                moveY = -1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.W))      //up
            {
                moveY = 1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Left) || keyboardState.IsKeyDown(Keys.A))      //left
            {
                moveX = -1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Right) || keyboardState.IsKeyDown(Keys.D))      //right
            {
                moveX = 1 * moveSensitivity;
            }

            if (keyboardState.IsKeyDown(Keys.Space))        //respawn the ball if you press 
            {
                scene.TriggerBallSpawn();
            }
            
            scene.paddlePos = CheckBounds(new Vector3 (oldX + moveX, oldY + moveY, 2400f));
        }
开发者ID:sketchydtail,项目名称:brickles3k,代码行数:34,代码来源:Player.cs


示例16: InputManager

 public InputManager(GameManager gameManager)
 {
     _lastKeyboardState = Keyboard.GetState();
     _gameManager = gameManager;
     HasTouchCapabilities = TouchPanel.GetCapabilities().IsConnected;
     TouchPanel.EnabledGestures = GestureType.Tap;
 }
开发者ID:nakioman,项目名称:furryrun,代码行数:7,代码来源:InputManager.cs


示例17: InputController

        public InputController()
        {
            m_DragArgs = new DragArgs();

            m_LastMouseState = Mouse.GetState();
            m_LastKeyboardState = Keyboard.GetState();
        }
开发者ID:acid1789,项目名称:Happiness,代码行数:7,代码来源:InputController.cs


示例18: Update

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            currentstate = Keyboard.GetState();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            // TODO: Add your update logic here
            else
            {
                if (currentstate.IsKeyDown(Keys.A) && !oldstate.IsKeyDown(Keys.A))
                {
                    sounds[0].Play();
                    //var sd = soundEffects[0].CreateInstance();
                    //sd.IsLooped = false;
                    //sd.Play();
                    //sd.Dispose();
                }
                if (currentstate.IsKeyDown(Keys.R) && !oldstate.IsKeyDown(Keys.R)) { rd.BMS파일분석(); }
                if (currentstate.IsKeyDown(Keys.Y) && !oldstate.IsKeyDown(Keys.Y)) { rd.노트시간계산();sdmgr.시간들 = rd.시간들; }
                if (currentstate.IsKeyDown(Keys.S) && !oldstate.IsKeyDown(Keys.S))
                {
                    sdmgr.Play();
                    //var sd = soundEffects[1].CreateInstance();
                    //sd.Play();
                }

                oldstate = currentstate;
            }
            

            base.Update(gameTime);
        }
开发者ID:ProjectEli,项目名称:BMS_Eli,代码行数:38,代码来源:GameMgr.cs


示例19: Initialize

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            oldstate = Keyboard.GetState();

            base.Initialize();
        }
开发者ID:ProjectEli,项目名称:BMS_Eli,代码行数:13,代码来源:GameMgr.cs


示例20: GUI

 public GUI()
 {
     this.lastKbState = Keyboard.GetState();
     this.KeysDown = new List<KeyRepeat>();
     foreach (Keys k in this.lastKbState.GetPressedKeys())
         this.KeysDown.Add(new KeyRepeat(k));
 }
开发者ID:gconfs-conferences,项目名称:bdsp-2012,代码行数:7,代码来源:GUI.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Input.MouseState类代码示例发布时间:2022-05-26
下一篇:
C# Input.GamePadState类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap