I am a newbie game developer.
I have one problem. Consider the following case.
I have a simple game with only one object - a ball. A ball can move only up and down from one side to another.
A User is allowed to set the game time and ball iteration count. An iteration is when the ball goes up to the topmost point and goes back to the bottommost point.
It should complete all iterations for the time user has set.
Here is an example.
Consider that a user has set the game time to 60 seconds, and the ball iterations option to 30.
We can find how much time do we have for an iteration 60/30 = 2 seconds. So the ball should complete the iteration for two seconds.
Let's assume we have a known frame rate and it is 30ms (update and drawing). So a single loop iteration takes 2000ms.
Next find iterations per a complete ball movement 2000/30 = 66 iterations. Also let's imagine that a distance from one side to another is 2000px.
So the ball need to complete 4000px per iteration.
Finally we can find out our movement delta 4000px/66 = 60 px . So ball will move 60px per a loop iteration.
But what to do if I don't frame rate, but what is more interesting what to do when the framerate is not static and we need to correlate it every time.
Please suggest an algorithm or an approach to solve this problem.
It seems that there should be a function, that will calculate position of a ball by the time passed from the game start, like sin (because ball is bouncing)