我正在写一个小球赛。我有一个叫gravity
的函数,我也有一个while循环来检查用户是否想用wsad键移动球。使用graphics.h的小型C++游戏,一次调用多个函数? (多线程?)
我需要多线程这或有另一种方式呢?我删掉了一些设置程序的无关代码。这里只是重要的东西:
while(1) {
enableGravity();
char ch = getch();// i know getch() is not going to cut it
//maybe 2 different f() multi threaded , for gravity and position,
f(ch == 'w' || ch == 'W')
updateObjPosition('U');
else if(ch == 's' || ch == 'S')
updateObjPosition('D');
else if(ch == 'a' || ch == 'A')
updateObjPosition('L');
else if(ch == 'd' || ch == 'D')
updateObjPosition('R');
}
我在main中有这些函数。我需要的程序,使重力,也能够接受输入通过updateObjPosition()
同时移动球。
您可能正在寻找[的kbhit(http://www.cprogramming.com/fod/kbhit.html)功能。 –
您可能不想制作“小游戏”多线程。这个很难(硬。 –