private bool UpdateJump(InputState inputState) { if ((mCurrentState == State.Ground || mCurrentState == State.Platform || mCurrentState == State.Portal) && Velocity.Y == 0) { if (inputState.IsJumping(null)) { mCurrentState = State.Air; Velocity.Y = -DEFAULT_SPEED; return true; } } return false; }
//UNDER CONSTRUCTION private bool UpdateJump(InputState inputState, GameTime theGameTime) { //start jump if ((mCurrentState == State.Ground || mCurrentState == State.Platform) && Velocity.Y == 0) { if (inputState.IsNewJump(null)) { mCurrentState = State.Air; Velocity.Y = -DEFAULT_JUMP; stillJumping = true; jumpTimer = TimeSpan.Zero; animator.PlayAnimation(jumpAnimation); return true; } } //walljumping if (mCurrentState == State.Air) { if (wallJumpRight) //walljump from left wall to right direction is available to player { if (inputState.IsNewJump(null)) { Velocity.X = DEFAULT_SPEED * MOVE_RIGHT * 2f; //Velocity.Y = -DEFAULT_JUMP / 2; Velocity.Y = -DEFAULT_JUMP; stillJumping = true; stillWallJumpingRight = true; jumpTimer = TimeSpan.Zero; wallJumpTimer = TimeSpan.Zero; animator.ResetAnimation(); return true; } } else if (wallJumpLeft) //walljump from right wall to left direction is available to player { if (inputState.IsNewJump(null)) { Velocity.X = DEFAULT_SPEED * MOVE_LEFT * 2f; //Velocity.Y = -DEFAULT_JUMP / 2; Velocity.Y = -DEFAULT_JUMP; stillJumping = true; stillWallJumpingLeft = true; jumpTimer = TimeSpan.Zero; wallJumpTimer = TimeSpan.Zero; animator.ResetAnimation(); return true; } } if (stillWallJumpingRight) { wallJumpTimer += theGameTime.ElapsedGameTime; if (wallJumpTimer < TimeSpan.FromMilliseconds(JUMP_HEIGHT_MAX / 2)) { Velocity.X = DEFAULT_SPEED * MOVE_RIGHT * 2f; //Velocity.Y = -DEFAULT_JUMP/2; Velocity.Y = -DEFAULT_JUMP; } else { stillWallJumpingRight = false; stillJumping = false; } } else if (stillWallJumpingLeft) { wallJumpTimer += theGameTime.ElapsedGameTime; if (wallJumpTimer < TimeSpan.FromMilliseconds(JUMP_HEIGHT_MAX / 2)) { Velocity.X = DEFAULT_SPEED * MOVE_LEFT * 2f; //Velocity.Y = -DEFAULT_JUMP/2; Velocity.Y = -DEFAULT_JUMP; } else { stillWallJumpingLeft = false; stillJumping = false; } } } else { stillWallJumpingRight = false; stillWallJumpingLeft = false; stillJumping = false; } //variable height jump if (stillJumping && !stillWallJumpingRight && !stillWallJumpingLeft) { if (inputState.IsJumping(null)) { mCurrentState = State.Air; //Velocity.Y = -DEFAULT_JUMP; Velocity.Y = -DEFAULT_JUMP; jumpTimer += theGameTime.ElapsedGameTime; if (jumpTimer > TimeSpan.FromMilliseconds(JUMP_HEIGHT_MAX)) { stillJumping = false; jumpTimer = TimeSpan.Zero; } } else //player let go of jump key early for a shorter jump { stillJumping = false; } } wallJumpLeft = false; wallJumpRight = false; return false; }