private Vector2 HandleJump(Vector2 Vel) { if (Player.Definition.AssignedGamepad >= 0 && DualityApp.Gamepads[Player.Definition.AssignedGamepad].IsAvailable || DualityApp.Keyboard.KeyPressed(Duality.Input.Key.Space)) { if (DualityApp.Gamepads[Player.Definition.AssignedGamepad].ButtonPressed(GamepadButton.A) || DualityApp.Keyboard.KeyPressed(Duality.Input.Key.Space)) { Vel.Y = JumpVelocity * GravityModifier; if (Vel.X < -InitialJumpDirectionVelocityGate) { JumpDirection = JumpDirectionEnum.Left; } else { if (Vel.X > InitialJumpDirectionVelocityGate) { JumpDirection = JumpDirectionEnum.Right; } else { JumpDirection = JumpDirectionEnum.Up; } } JumpAvailable = false; PlayerJumpSounds.PlayRandomSound(); } } return(Vel); }
private Vector2 HandleWallJump(Vector2 Vel, float horizontalAxisValue) { if (collider.OnWall) { if (Player.Definition.AssignedGamepad >= 0 && DualityApp.Gamepads[Player.Definition.AssignedGamepad].IsAvailable || DualityApp.Keyboard.KeyPressed(Duality.Input.Key.Space)) { if (DualityApp.Gamepads[Player.Definition.AssignedGamepad].ButtonPressed(GamepadButton.A) || DualityApp.Keyboard.KeyPressed(Duality.Input.Key.Space)) { //If the player is moving fast enough, and is providing input opposite to the direction of travel... bounce off the wall if (((Vel.X < 0 && horizontalAxisValue > 0.25) || (Vel.X > 0 && horizontalAxisValue < -0.25))) { if (JumpDirection == JumpDirectionEnum.Left) { JumpDirection = JumpDirectionEnum.Right; } else if (JumpDirection == JumpDirectionEnum.Right) { JumpDirection = JumpDirectionEnum.Left; } Vel.X = -(Vel.X * 2) + Vel.X > 0 ? 5 : -5; if (GravityModifier > 0) { Vel.Y = Math.Min(JumpVelocity * GravityModifier, GravityModifier * (Vel.Y + JumpVelocity / 2.0f)); } else { Vel.Y = Math.Max(JumpVelocity * GravityModifier, GravityModifier * (Vel.Y + JumpVelocity / 2.0f)); } if (!AllowConsecutiveWallJumps) { WallJumpAvailable = false; } //regardless, don't let the user do their normal jump if they've walljumped. JumpAvailable = false; if (JumpDirection == JumpDirectionEnum.Up) { if (Vel.X < 0) { JumpDirection = JumpDirectionEnum.Left; } else if (Vel.X > 0) { JumpDirection = JumpDirectionEnum.Right; } } PlayerJumpSounds.PlayRandomSound(); } } } } return(Vel); }