I'm working on a game concept where players can earn money steadily over time (e.g. $50 per second). However, I don't want the money to increase in jumps of $50 every second; instead, I want it to smoothly increase.
setInterval(increaseMoney, 1000);
function increaseMoney() {
money = money + moneyPerSecond;
}
My current approach involves dividing the earning rate into two categories: one earns $1 every 1/moneyPerSecond seconds (where moneyPerSecond < 1000), and the other category earns y dollars every 0.001 seconds.
However, there are two challenges: I initially avoided floats to maintain precision, but now I realize that using integers may cause imprecision issues. Edit: It's okay to use floats! I could also enhance precision by increasing the time interval between updates, even though this might make the increments less smooth.
My questions:
- Am I on the right path with this approach?
- How can I implement the solution effectively to minimize imprecision?
Requirements: Floats are acceptable, and accuracy is crucial for the implementation.