Exemple #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);
            }
        }
Exemple #2
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
 }