I’m trying to make a basic snake game in C++, I made a basic grid with a orl[x] and ory[y] arrays, and now I’m trying to add the snake.
Basically I want the snake to move until a certain key is pressed and move one array at a time. I tried using something else than timers but it is executed instantly. I need a timer so that the snake keeps doing that every second until a key is pressed. If you ever played snake you know exactly what I mean.
I need to make a timer in C++, but I don’t want to implement an ENORMOUS code by creating a timer and not understand anything from my own code. I want it as simple as possible.
Any idea how I could do this? I looked into the time header library but found nothing useful in there.
The sad truth is that Standard C++ doesn’t really have support for this type of behavior. Both Windows and Posix support a sleep function which would allow you to do this. For a higher level solution you may look at Boost::Threads.