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;
}