I am using a library called raylib but that should not be a problem to you because the code I am trying to write should make the ball jump up and after reaching a certain height the ball should come down, just like gravity works. The thing is my code is just shooting the ball upwards, the ball is just teleporting to the top and then coming down just normal. Now I want the ball to go up just like it is coming down.
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.
{
while(MyBall.y >= 200) // Here is the problem. while the ball's y coordinate is greater than or equal to 200, that is while the ball is above 200, subtract 5 from its y coordinate. But this code just teleports the ball instead of making it seem like a jump.
{
MyBall.y -= 5;
}
}
if(IsKeyDown(KEY_LEFT) && MyBall.x >= 13) MyBall.x -= 5; //This code is just to move the vall horizontally
if(IsKeyDown(KEY_RIGHT) && MyBall.x <= SCREENWIDTH-13) MyBall.x += 5; //This also moves the ball horizontally.