The character is not moving fluently, is stopping and not moving left or right. I don't know very much about moving a char but I want to learn to use it in my snake project is there any problem with the code?
while(true)
{
system("CLS");
for(int i=0;i<10;i++)
{
cout<<map[i]<<endl;
}
system("pause>nul");
if(GetAsyncKeyState(VK_DOWN))
{
int y2=y+1;
if(map[y2][x]==' ')
{
map[y][x]=' ';
y++;
map[y][x]='@';
}
}
if(GetAsyncKeyState(VK_UP))
{
int y2=y-1;
if(map[y2][x]==' ')
{
map[y][x]=' ';
y--;
map[y][x]='@';
}
}
if(GetAsyncKeyState(VK_RIGHT))
{
int x2=x+1;
if(map[x2][x]==' ')
{
map[y][x]=' ';
x++;
map[y][x]='@';
}
}
if(GetAsyncKeyState(VK_LEFT))
{
int x2=x-1;
if(map[x2][x]==' ')
{
map[y][x]=' ';
x--;
map[y][x]='@';
}
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire