Its not very complicated, all you need is to consider 3 things:
- It'sBall's position (
x
,y
) and velocity (vx
andvy
). - GravityConstant gravity (
g
). - Bounce conditions.
On every game loop you need to apply gravity, like:
vy += g;
Then apply velocity:
x += vx;
y += vy;
Then check these result for collision with players and/or screen edges and ground.
Depending on your game engine, you might need to "correct" these calculations by multiplying them by your current tick time (eg. vy += g * tick_time
), setting proper constant gravity, and setting proper starting/after-bounce velocity (eg. vx
and vy
depending on player's bounce angle - you might have to use sin/cos functions).