I'm writing a game currently in ncurses and I have a ship that is controlled by the user and an 'automated' that moves slowly down the lines to kill you. However, I'm using a while loop containing everything and each time I use getch() the loop pauses and waits for input, meaning that the enemy only moves after input from the user.
c=getch(); //causes a pause until a button is pressed before the next action
if(c==97) //if a is pressed, move position of '*' left
{
dir=-1;
}
if(c==100) //if d is pressed, move position of '*' right
{
dir=1;
}
解决方案
Since you're using curses, just call nodelay or halfdelay or timeout to make getch non-blocking, or have it return after a short wait if no key has been pressed. See the inopts(3ncurses) man page.