I need a shorter sleep in order to move my snake faster
i got an email a while ago from somebody who had read this. The person was trying to implement a snake game and the question was about sleep times since the person used sleep to define difficulty levels. The higher level, the faster the snake should move. the problem was that he used a small sleep in a very tight loop and the snake did not really move any faster once you completed a few levels. He experimented and figured out that the sleep always slept between 10 and 15 milliseconds even though he tried to do a sleep for just 5 milliseconds. The problem was that he forgot this fact; Sleep does not sleep for a specified time. And interestingly enough; on Windows the resolution of a sleep call is between 10 and 15 milliseconds.
So how do you solve this problem? Since we're talking about a game we can safely assume it will be played by humans. And the human eye/brain combination can be happy with as low as 30 updates per second, but 60 should be a safe bet under most circumstances. Hence updating the snake position more often than 60 times per second (note that a sleep of 15 milliseconds gives you 66.666... updates per second) is not really necessary. So in order to move the snake faster at higher levels, all you need to do is to move it further each time you move it but always move it at the same interval.