It is necessary to somehow mark the time when everything is spent to zero and enable the player a temporary mode of "accumulating money over time."
Further, the amount of currency becomes a function of time:
start = XXX; // Π²ΡΠ΅ΠΌΡ ΠΊΠΎΠ³Π΄Π° ΡΠΏΠ°Π»ΠΎ Π΄ΠΎ 0 mode = "earning"; // ΠΈΠ³ΡΠΎΠΊ Π½Π°Ρ
ΠΎΠ΄ΠΈΡΡΡ Π² ΡΠ΅ΠΆΠΈΠΌΠ΅ Π½Π°ΠΊΠΎΠΏΠ»Π΅Π½ΠΈΡ Π·Π° Π²ΡΠ΅ΠΌΡ now = (new Date).getTime(); // Π²ΡΠ΅ΠΌΡ ΡΠ΅ΠΉΡΠ°Ρ money = Math.floor((now - start) / N) * K; if( money > 50) { mode = "game"; // Π±ΠΎΠ»ΡΡΠ΅ Π½Π΅Ρ ΡΠ΅ΠΆΠΈΠΌΠ° Π½Π°ΠΊΠΎΠΏΠ»Π΅Π½ΠΈΡ money = 50; }
Think over the moment when, during the accumulation of money, the player somehow managed to earn a few coins - what to do then?
Let me explain the line money = Math.floor((now - start) / N) * K; . This is a school, linear algebra - we need a function that grows from 0 at the start point. In the simplest version, this is y = k * (x - start) , where k a certain coefficient. growth rate. But so will be the fractional values, and you write in the question about discrete - " 10 every 10 minutes, you can 1 every minute ."
Those. the growth graph is not an inclined line, but steps by integer values. Therefore rounding is added:

How to choose the coefficients N and K Without delving into the explanation, here is the recipe. If you need to once a minute (60 seconds) by 1, divide by N=60 and you can not multiply. If every 10 minutes (600 seconds) by 10, divide by N=600 , and multiply by K=10 .