Bricklayer.Client.Entities.Player.DoJump C# (CSharp) Method

DoJump() protected 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.
protected DoJump ( float velocityY, GameTime gameTime ) : float
velocityY float /// The player's current velocity along the Y axis. ///
gameTime Microsoft.Xna.Framework.GameTime
return float
        protected 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)
                        JumpDirection = GravityDirection; //Set the direction this jump started from
                    if (JumpTime == 0 && IsMine)
                    {
                        //Send message we are now jumping
                        PlayerStateMessage msg = new PlayerStateMessage(this);
                        msg.IsJumping = true;
                        Game.NetManager.Send(msg);
                    }
                    JumpTime += (float)gameTime.ElapsedGameTime.TotalSeconds; //Incriment jump timer
                }

                //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 = (JumpDirection == GravityDirection.Up || JumpDirection == GravityDirection.Left ? -1 : 1) * (JumpLaunchVelocity * (1.0f - (float)Math.Pow(JumpTime / MaxJumpTime, JumpControlPower)));
                }
                else
                {
                    if (JumpTime > 0 && IsMine)
                    {
                        //Tell others we are falling now
                        PlayerStateMessage msg = new PlayerStateMessage(this);
                        msg.IsJumping = false;
                        Game.NetManager.Send(msg);
                    }
                    JumpTime = 0.0f;   // Reached the apex of the jump
                    IsJumping = false;
                }
            }
            else
            {
                //Tell others we have landed
                if (JumpTime > 0 && IsMine)
                    Game.NetManager.Send(new PlayerStateMessage(this));
                // Continues not jumping or cancels a jump in progress
                JumpTime = 0.0f;
            }
            WasJumping = IsJumping;

            return velocityY;
        }