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; } }
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)); }
private void ProcessInput(FullInputData data, float dt) { var flatDirection = ComputeFlatDirection(data); // Flat direction is on multiple controllers regardless of player state (so that if the player changes // state mid-step, movement still continues correctly). aerialController.FlatDirection = flatDirection; groundController.FlatDirection = flatDirection; platformController.FlatDirection = flatDirection; wallController.FlatDirection = flatDirection; // TODO: Make sure the call order is correct among all of these actions. activeAttack?.Update(dt); // The player can only interact while grounded. Interaction also takes priority over other actions on the // current frame. if ((player.State & PlayerStates.OnGround) > 0 && ProcessInteraction(data)) { return; } ProcessLadder(data); // The jump button is used for multiple skills (including regular jumps, wall jump, and ascend). The order // in which these functions are called enforces the priority of those skills (ascend first, then wall jump, // then regular jumps). if (!(ProcessAscend(data, dt) || ProcessWallJump(data))) { ProcessJump(data, flatDirection); } //ProcessAttack(data, dt); }
private void ProcessInput(FullInputData data) { if (data.Query(controls.Inventory, InputStates.PressedThisFrame)) { inventoryScreen.IsVisible = !inventoryScreen.IsVisible; } }
public void ProcessInput(FullInputData data) { var mouseData = data.GetData(InputTypes.Mouse); if (mouseData != null) { itemSet.ProcessMouse((MouseData)mouseData); } }
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; }
public InputFlowTypes ProcessInput(FullInputData data) { // TODO: Consider adding an X in the upper-right corner to exit using the mouse. if (data.TryGetData(out KeyboardData keyboard)) { ProcessKeyboard(keyboard); } return(IsDrawEnabled ? InputFlowTypes.BlockingUnpaused : InputFlowTypes.Passthrough); }
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; } }
/* * 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); }
public void Update(float dt) { var mouseData = GetMouseData(); var keyboardData = GetKeyboardData(); FullInputData fullData = new FullInputData(); fullData.Add(InputTypes.Mouse, mouseData); fullData.Add(InputTypes.Keyboard, keyboardData); MessageSystem.Send(CoreMessageTypes.Keyboard, keyboardData, dt); MessageSystem.Send(CoreMessageTypes.Mouse, mouseData, dt); MessageSystem.Send(CoreMessageTypes.Input, fullData, dt); }
private bool ProcessAscend(FullInputData data, float dt) { // There are two ascend-based actions the player can take: 1) starting an ascend (by holding the relevant // button and pressing jump), or 2) breaking out of an ongoing ascend (by pressing jump mid-ascend). if (!player.IsUnlocked(PlayerSkills.Ascend) || !ascendBuffer.Refresh(data, dt)) { return(false); } if ((player.State & PlayerStates.Ascending) == 0) { return(player.TryAscend()); } player.BreakAscend(); return(true); }
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(); } }
private void ProcessInput(FullInputData data) { ProcessRunning(data); }
private bool ProcessInteraction(FullInputData data) { return(data.Query(controls.Interact, InputStates.PressedThisFrame) && player.TryInteract()); }
private void ProcessInput(FullInputData data) { ProcessMouse((MouseData)data.GetData(InputTypes.Mouse)); }