I started writing this classic snake game today that runs on the console.
It's principle is same with the classic snake. (ie eat a fruit and the snake grows bigger)
I was still working on the movement and control when I hit a brick wall.
The keys (w,a,s,d) are used for the controls and I'm using the getche() function to get the input and I implemented a timer using <time.h> but the problem is.. even when the timer is up, the console still waits for an input. Is ther e a way to fix this please?
Thanks for the reply. But, I'm still having a problem with the function:
error: 'VK_A' was not declared in this scope
Do I need to include any other library?
And also, I'm trying to stay away from platform specific programming. Do you know of a way to do it with a cross platform library?
If your complier recognizes GetAsyncKeyState() but doesn't know what VK_A is, use this :
#define VK_A 0x41
Or replace (VK_A) with 0x41 :
if(GetAsyncKeyState(0x41 + (i - 'a')))
Maybe it is possible, but I can't imagine a way to do it with cross platform library. It is very hard to find a standard input function that is specialized in catching the human input the instant moment when the function is called, without having to pause the program to wait for a proper human input. You should do some research and figure out how the same program feature is done in different platforms (Linux, Mac, etc) using different methods. And if you can somehow find a universal way for this, then good for you.
Since you're doing this in the console, maybe see if ncurses/pdcurses would help. I believe there is a way to make their version of getch() non-blocking by calling nodelay() ahead of time.
They also offer a number of printing functions that may be of interest to you since you're trying to use your console for fancier stuff than simple reading and writing text.