We don't see the type of start
, but I'm assuming it's a double
. If so the culprit is this line:
start = (int) (cTime/1000); //cTime is the milisecond since game started
Imagine cTime
is 900 and the last wave started at time 0
(so a new wave should be starting). Then when this new wave starts, you'll set start = (int)(900/1000);
This is a truncating integer division, so the new value of start
is 0
. But this is the same as the old value -- so since nothing has changed, a new wave will start again immediately the next time the time condition is checked.
Instead of doing an integer division, convert the integer cTime to a double
and perform the division and the comparison in floating point:
start = ((double) cTime) / 1000.0;
// ...
if ((((double)cTime/1000.0) - start) >= TIME) { //changing speed
The new value of start
in the scenario above should then be 0.9
, and the new round should be allowed to last for 0.8 seconds.