It won't get out from while loops like while(MyBall.y >= 200)
until the condition becomes false, so Myball.y
will be 195
after exiting from this loop.
It seems you should introduce a variable to manage status.
Example:
// initialization (before loop)
int MyBall_goingUp = 0;
// inside loop
if (MyBall_goingUp)
{
MyBall.y -= 5;
if (MyBall.y < 200) MyBall_goingUp = 0;
}
else
{
if(MyBall.y < 340) MyBall.y += 5; // This will attract the ball towards ground once it is up in the air or once it's vertical coordinate value is greater than 340
if(IsKeyPressed(KEY_SPACE) && MyBall.y == 340) //This if statement will be activated only when ball is grounded and spacebar is pressed.
{
MyBall_goingUp = 1;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…