如何使用C#和XNA进行双跳?

时间:2018-06-01 13:48:29

标签: c# xna

这是我目前单跳的代码,来自用户的输入设置跳转为true并且单跳转没有错误,但是我不能为我的游戏产生第二次空中跳跃。我不得不这样做,没有学校的统一,所以它只适用于矩形。

if (jumping) //only run when jump has been initiated by space or A
{
    rect.Y = centreY - (int)(Math.Sin(angle) * range); //move player up to a maximum of range's value

    angle += speedY; //gradually reduce player's y by reducing angle's value

    newCentreY = rect.Y;

    if (angle > Math.PI) //reset player to not jumping when angle is greater than 3.14
    {
        angle = 0;
        jumping = false;
    }
}

这是跳转的输入处理程序:

if (userControl.Buttons.A == ButtonState.Pressed || keystate.IsKeyDown(Keys.Space)) //jump when A or space is pressed 
{ 
    jumping = true; 
} 
Jump(userControl, keystate); //jump method

1 个答案:

答案 0 :(得分:0)

我认为您应该让angle 0继续跳跃。

if (doubleJumping)
{
    angle = 0;
    doubleJumping = false;
}
if (jumping) //only run when jump has been initiated by space or A
{
    rect.Y = centreY - (int)(Math.Sin(angle) * range); //move player up to a maximum of range's value

    angle += speedY; //gradually reduce player's y by reducing angle's value

    newCentreY = rect.Y;

    if (angle > Math.PI) //reset player to not jumping when angle is greater than 3.14
    {
        angle = 0;
        jumping = false;
    }
 }