【发布时间】:2013-11-17 23:53:23
【问题描述】:
我正在尝试让玩家光循环继续向一个方向移动而不会停止,直到玩家按下按钮将其向另一个方向移动。我不确定如何使用 kbhit 做到这一点,所以请给我一些建议!谢谢。
void Lightcycle(){
if (kbhit()) {// get user key input
char GetCh = getch(); // GetCh equal to the button the user presses
if (GetCh == 'w'){PlayerX = PlayerX - 1;}
else if (GetCh == 's'){PlayerX = PlayerX +1;}
else if (GetCh == 'd'){PlayerY = PlayerY +1;}
else if (GetCh == 'a'){PlayerY = PlayerY - 1;}
}// end kbhit
}// end function
【问题讨论】:
-
与其让输入直接移动玩家,不如给玩家一个方向并让输入修改它,然后将玩家朝他们指向的方向移动。
-
你能用代码展示一个例子吗?我不知道如何在实际代码中应用它