Beispiel #1
0
        private void ProcessKeyboard(gxtKeyboard kb, float dt)
        {
            if (kb.GetState(Keys.F2) == gxtControlState.FIRST_PRESSED)
            {
                if (playerActor.ClipMode == asgClipMode.NORMAL)
                    playerActor.ClipMode = asgClipMode.NOCLIP;
                else
                    playerActor.ClipMode = asgClipMode.NORMAL;
                gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "F2 First Pressed!");
            }

            float dX = 0.0f, dY = 0.0f;
            if (kb.IsDown(Keys.D))
                dX = 1.0f;
            if (kb.IsDown(Keys.A))
                dX -= 1.0f;
            if (kb.IsDown(Keys.W))
                dY = -1.0f;
            if (kb.IsDown(Keys.S))
                dY = 1.0f;

            // process jump
            if (playerActor.OnGround)
            {
                bool jumpRequested = kb.GetState(Keys.Space) == gxtControlState.FIRST_PRESSED;
                if (jumpRequested)
                {
                    playerActor.Body.ApplyImpulseAtLocalPoint(new Vector2(0.0f, -20.0f), Vector2.Zero);
                }
            }

            if (playerActor.ClipMode == asgClipMode.NORMAL)
            {
                if ((gxtMath.Abs(dX) < float.Epsilon))
                {

                }
                else
                {
                    Vector2 surfaceRight = gxtMath.RightPerp(playerActor.SurfaceNormal);
                    Vector2 inputVec = new Vector2(dX, 0.0f);
                    Vector2 proj = surfaceRight * Vector2.Dot(surfaceRight, inputVec);
                    // apply friction here

                    // todo: make it slower to walk up certain things then down them
                    // also, consider using velocity and zeroing it after every frame
                    // the straight translation technique has a lot of flaws
                    playerActor.Translate(proj * playerActor.MoveSpeed * dt);
                    //playerActor
                }
            }
            else
            {
                playerActor.Translate(new Vector2(dX, dY) * playerActor.MoveSpeed * dt);
            }
        }
 public gxtKeyboardCharacterProcessor(bool initEnabled, gxtKeyboard keyboard)
     : base(initEnabled, true, gxtProcess.INPUT_TYPE)
 {
     this.keyboard = keyboard;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            if (!Enabled || OnCharacterEntered == null)
                return;

            if (keyboard == null)
            {
                keyboard = gxtKeyboardManager.Singleton.GetKeyboard();
                if (keyboard == null)
                    return;
            }

            // alot faster to process the down keys then all of them
            downKeys = keyboard.GetPressedKeys();

            if (downKeys.Length == 0)
                return;

            shift = keyboard.IsDown(Keys.LeftShift) || keyboard.IsDown(Keys.RightShift);

            // space
            if (keyboard.GetState(Keys.Space) == gxtControlState.FIRST_PRESSED)
                OnCharacterEntered(' ');

            ProcessKey(Keys.OemPeriod, '.', '>');        // period, gt
            ProcessKey(Keys.OemComma, ',', '<');         // comma, lt
            ProcessKey(Keys.OemQuotes, '\'', '\"');       // quotes
            ProcessKey(Keys.OemMinus, '-', '_');         // minus, underscore
            ProcessKey(Keys.OemPlus, '=', '+');          // equals, plus
            ProcessKey(Keys.OemSemicolon, ';', ':');     // semicolon, colon
            ProcessKey(Keys.OemQuestion, '/', '?');      // slash, question
            ProcessKey(Keys.OemPipe, '\\', '|');         // backslash, pipe
            ProcessKey(Keys.OemOpenBrackets, '[', '{');  // open brackets
            ProcessKey(Keys.OemCloseBrackets, ']', '}'); // close brackets

            // all alphabetical keys
            // all the digits
            // and shift digit special characters (e.g. !, @, and #)
            for (int i = 0; i < downKeys.Length; ++i)
            {
                Keys testKey = downKeys[i];
                if (keyboard.GetState(testKey) == gxtControlState.FIRST_PRESSED)
                {
                    string keyString = testKey.ToString();
                    if (keyString.Length == 1)
                    {
                        char c = keyString[0];
                        if (char.IsLetter(c))
                        {
                            if (!shift)
                                OnCharacterEntered(char.ToLower(c));
                            else
                                OnCharacterEntered(c);
                        }
                    }
                    else
                    {
                        char digit;
                        if (IsDigit(testKey, shift, out digit))
                        {
                            OnCharacterEntered(digit);
                        }
                    }
                }
            }
        }
Beispiel #4
0
 private void ProcessKeyboard(gxtKeyboard kb, float dt)
 {
     float dX = 0.0f, dY = 0.0f;
     if (kb.IsDown(Keys.Left))
         dX = -1.0f;
     if (kb.IsDown(Keys.Right))
         dX = 1.0f;
     if (kb.IsDown(Keys.Up))
         dY = -1.0f;
     if (kb.IsDown(Keys.Down))
         dY = 1.0f;
     Camera.TranslateLocal(dX * cameraSpeed, dY * cameraSpeed);
     // use + and - for zoom
     // use { and } for rotation
 }