[英]How to stop trail behind moving char in NCurses?
我正在使用 ncurses 庫在 C 中制作終端游戲。字符 @ 使用 WASD 鍵在屏幕上移動。 但是,我希望它不會留下任何痕跡,到目前為止,它會留下諸如@@@@@@@之類的痕跡。
有誰知道這方面的方法? 謝謝!
下面是移動字符的代碼。
init_Curses(); //start ncurses
mvwprintw(stdscr, y, x, "@");
curs_set(0);
while (1)
{
refresh();
direction = getchar();
switch (direction)
{
//proccess movement with WASD controls
case 'w':
y -= 1;
break;
case 'a':
x -= 1;
break;
case 's':
y += 1;
break;
case 'd':
x += 1;
break;
default:
continue;
}
if (x == -1 && y == -1)
{
y += 1;
x += 1;
} //keep in grid
mvwprintw(stdscr, y, x, "@");
}
endwin();
您必須自己刪除軌跡,即將它替換為@
傳遞之前的字符。
您必須跟蹤 position 之前是@
並且打印被@
刪除的字符,假設它是一個空格:
if (x == -1 && y == -1) { y += 1;x += 1;} //keep in grid
mvwprintw(stdscr,previous_pos_y,previous_pos_x," ");
mvwprintw(stdscr,y,x,"@");
}
不用說,您還必須跟蹤此類字符,以便恢復它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.