简体   繁体   English

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

[英]How can I make a double jump using C# and XNA?

This is my current code for a single jump, input from the user sets jump to true and a single jump works with no errors, however I cannot produce a second midair jump for my game. 这是我目前单跳的代码,来自用户的输入设置跳转为true并且单跳转没有错误,但是我不能为我的游戏产生第二次空中跳跃。 I had to do this without unity for school so it is only working with rectangles. 我不得不在没有团结的情况下这样做,所以它只适用于矩形。

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

Here's the input handler for jumps: 这是跳转的输入处理程序:

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

I think you should make your angle to be 0 to continue jumping. 我认为你应该让你的angle0才能继续跳跃。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM