Platformer.Player.DoJump C# (CSharp) Method

DoJump() private method

Calculates the Y velocity accounting for jumping and animates accordingly.
During the accent of a jump, the Y velocity is completely overridden by a power curve. During the decent, gravity takes over. The jump velocity is controlled by the jumpTime field which measures time into the accent of the current jump.
private DoJump ( float velocityY, GameTime gameTime ) : float
velocityY float /// The player's current velocity along the Y axis. ///
gameTime Microsoft.Xna.Framework.GameTime
return float
        private float DoJump(float velocityY, GameTime gameTime)
        {
            // If the player wants to jump
            if (isJumping)
            {
                // Begin or continue a jump
                if ((!wasJumping && IsOnGround) || jumpTime > 0.0f)
                {
                    if (jumpTime == 0.0f)
                        jumpSound.Play();

                    jumpTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (isRight || velocity.X > 0)
                    {
                        sprite.PlayAnimation(jumpRightAnimation);
                    }
                    else
                    {
                        sprite.PlayAnimation(jumpLeftAnimation);
                    }
                }

                // If we are in the ascent of the jump
                if (0.0f < jumpTime && jumpTime <= MaxJumpTime)
                {
                    // Fully override the vertical velocity with a power curve that gives players more control over the top of the jump
                    velocityY = JumpLaunchVelocity * (1.0f - (float)Math.Pow(jumpTime / MaxJumpTime, JumpControlPower));
                }
                else
                {
                    // Reached the apex of the jump
                    jumpTime = 0.0f;
                }
            }
            else
            {
                // Continues not jumping or cancels a jump in progress
                jumpTime = 0.0f;
            }
            wasJumping = isJumping;

            return velocityY;
        }