diff --git a/Animal.cpp b/Animal.cpp index 4be1fd1..aa5ef61 100644 --- a/Animal.cpp +++ b/Animal.cpp @@ -304,30 +304,48 @@ void Animal::resetTimes(Uint64 t) { } Uint64 Animal::step(Uint64 cur, bool press) { - if (!press && cur >= move_time) { + short move_interval = 25; + if (!press && cur >= move_time + move_interval) { move(); - move_time += 25; + move_time += move_interval; + // don't allow move_time be too far away from cur + if (cur > move_time + move_interval * 5) { + move_time = cur; + } } - if (cur >= animate_time) { + if (cur >= animate_time + cur_state->interval) { animate(false); animate_time += cur_state->interval; + // don't allow animate_time be too far away from cur + if (cur > animate_time + cur_state->interval * 5) { + animate_time = cur; + } } - if (!press && cur >= random_time) { + short random_interval = 1000 * 5; + if (!press && cur >= random_time + random_interval) { shuffle(); - random_time += 1000 * 5; + random_time += random_interval; + // don't allow random_time be too far away from cur + if (cur >= random_time + random_interval * 5) { + random_time = cur; + } } - Uint64 lowest_time = move_time; - if (lowest_time > animate_time) lowest_time = animate_time; - if (lowest_time > random_time) lowest_time = random_time; - - if (lowest_time < cur) { - lowest_time = cur; + Uint64 nearest_time = move_time + move_interval; + if (nearest_time > animate_time + cur_state->interval) { + nearest_time = animate_time + cur_state->interval; + } + if (nearest_time > random_time + random_interval) { + nearest_time = random_time + random_interval; } - return lowest_time - cur; + if (nearest_time < cur) { + nearest_time = cur; + } + + return nearest_time - cur; } SDL_Surface *Animal::getImage() {