Пример #1
0
        private void ProcessJump(FullInputData data, vec2 flatDirection)
        {
            // If this is true, it's assumed that the jump bind must have been populated. Note that this behavior (jump
            // limiting) applies to multiple kinds of jumps (including regular jumps, breaking ascends, wall jumps, and
            // maybe more).
            if ((player.State & PlayerStates.Jumping) > 0)
            {
                if (data.Query(jumpBindUsed, InputStates.ReleasedThisFrame) &&
                    player.ControllingBody.LinearVelocity.Y > playerData.JumpLimit)
                {
                    player.LimitJump();
                    jumpBindUsed = null;
                }

                return;
            }

            // This also accounts for jump being unlocked.
            if (player.JumpsRemaining == 0)
            {
                return;
            }

            if (data.Query(controls.Jump, InputStates.PressedThisFrame, out var bind))
            {
                player.Jump(flatDirection);
                jumpBindUsed = bind;
            }
        }
Пример #2
0
        private vec2 ComputeFlatDirection(FullInputData data)
        {
            bool forward = data.Query(controls.RunForward, InputStates.Held);
            bool back    = data.Query(controls.RunBack, InputStates.Held);
            bool left    = data.Query(controls.RunLeft, InputStates.Held);
            bool right   = data.Query(controls.RunRight, InputStates.Held);

            // "Flat" direction means the direction the player would run on flat ground. The actual movement direction
            // depends on the current surface.
            vec2 flatDirection = vec2.Zero;

            if (forward ^ back)
            {
                flatDirection.y = forward ? 1 : -1;
            }

            if (left ^ right)
            {
                flatDirection.x = left ? 1 : -1;
            }

            // This normalizes the velocity when moving diagonally using a keyboard.
            if ((forward ^ back) && (left ^ right))
            {
                flatDirection *= SqrtTwo;
            }

            return(Utilities.Rotate(flatDirection, FollowView.Yaw));
        }
Пример #3
0
        private void ProcessLadder(FullInputData data)
        {
            // Ladder climbing uses the same controls as running forward and back. Also note that directions remain the
            // same even if the camera is tilted down.
            bool up   = data.Query(controls.RunForward, InputStates.Held);
            bool down = data.Query(controls.RunBack, InputStates.Held);

            ladderController.Direction = up ^ down ? (up ? 1 : -1) : 0;
        }
Пример #4
0
        private void ProcessRunning(FullInputData data)
        {
            bool left  = data.Query(controls.RunLeft, InputStates.Held);
            bool right = data.Query(controls.RunRight, InputStates.Held);

            if (left ^ right)
            {
                vec3 p = Position;
                p.x     += 0.03f * (left ? -1 : 1);
                Position = p;
            }
        }
Пример #5
0
 private void ProcessInput(FullInputData data)
 {
     if (data.Query(controls.Inventory, InputStates.PressedThisFrame))
     {
         inventoryScreen.IsVisible = !inventoryScreen.IsVisible;
     }
 }
Пример #6
0
        /*
         * private void ProcessGrab(FullInputData data, float dt)
         * {
         *      // TODO: Player actions (in relation to state) will likely need to be refined. In this case, could other states prevent grabbing?
         *      if (player.State != PlayerStates.Grabbing)
         *      {
         *              if (grabBuffer.Refresh(data, dt, out grabBindUsed))
         *              {
         *                      player.TryGrab();
         *              }
         *
         *              return;
         *      }
         *
         *      // Ladders are special among grabbable objects in that a toggle is always used to attach or detach from the
         *      // ladder (regardless of control settings). I've never played a game where you have to hold a button to
         *      // remain on a ladder.
         *      bool shouldRelease = settings.UseToggleGrab || player.IsOnLadder
         *              ? data.Query(controls.Grab, InputStates.ReleasedThisFrame)
         *              : data.Query(grabBindUsed, InputStates.ReleasedThisFrame);
         *
         *      if (shouldRelease)
         *      {
         *              player.ReleaseGrab();
         *      }
         * }
         */

        private bool ProcessWallJump(FullInputData data)
        {
            if (player.IsWallJumpAvailable && data.Query(controls.Jump, InputStates.PressedThisFrame,
                                                         out var bind))
            {
                player.WallJump();
                jumpBindUsed = bind;

                return(true);
            }

            return(false);
        }
Пример #7
0
        private void ProcessAttack(FullInputData data, float dt)
        {
            var weapon = player.Weapon;

            if (attackBindUsed != null)
            {
                if (data.Query(attackBindUsed, InputStates.ReleasedThisFrame))
                {
                    weapon.ReleasePrimary();
                    attackBindUsed = null;
                }

                return;
            }

            // TODO: Process weapon cooldown as needed.
            if (attackBuffer.Refresh(data, dt, out var bind))
            {
                attackBindUsed = bind;
                activeAttack   = weapon.TriggerPrimary();
            }
        }
Пример #8
0
 private bool ProcessInteraction(FullInputData data)
 {
     return(data.Query(controls.Interact, InputStates.PressedThisFrame) && player.TryInteract());
 }