I'm writing a terminal based game similar to that of an old school racer where you can only change lanes to avoid obstacles. I've been able to code everything else except the part where it asks for input in order to change lanes. The function for this is supposed to wait 2 seconds for an input and if there is an input, it determines which lane to change to. cin>>input;
makes the program wait indefinitely and for some reason getchar();
doesn't work.
I've already searched and found this: Wait for input for a certain time
My problem is that I don't have <conio.h>
, <curses.h>
, and <ncurses.h>
so I wouldn't be able to use getch();
Is there any way I could make the computer do this without those library files?
I also need help decreasing the time needed for waiting in order to increase the game's difficulty. sleep();
isn't working because it's library file isn't included and I'm having trouble using nanosleep();
but I want to be able to decrease time interval by .1 sec each time the player has to input until there is only .5 secs to input. Is there a way I can do this as well?
Code related to what I have now: