我想做一个2维射击小游戏
写了一个框架:
while(1)
{
if(kbhit())
{
s=getch();
if(s==方向&&是否能移动)
{
移动;
}
if(s==方向&&是否能射击)
{
射击;
}
}
敌人射击/移动;
}
但玩家只要按下一颗键
敌人就需要按一下才能动
请问怎么办?
在这错了:if(kbhit()) 应该改成if(_kbhit()),你少了一个“_”
while(1)
{
if(_kbhit())
{
s=getch();
if(s==方向&&是否能移动)
{
移动;
}
if(s==方向&&是否能射击)
{
射击;
}
}
敌人射击/移动;
}
```c++
```
```c++
#include<bits/stdc++.h>
#include<conio.h>
using namespace std;
int main()
{
string a="NO";
while(1)
{
if(_kbhit())a="YES";
cout<<a;
}
return 0;
}
```
把敌人动的函数放在while(1)下面,不管按不按都能走