This is the bulletfire(move) code
void fire(int bx, int by)
{
gotoxy(bx, by);
int a;
for (int i = bx; i >= MAP_X + 2; i--) {
gotoxy(i+1, by);
printf(" ");
gotoxy(i, by);
printf("<");
Sleep(10);
a = i;
}
gotoxy(a, by);
printf(" ");
}
This is PlayerMove code "wasd" move and "n" bulletfire
while (1)
{
ch = '\0';
bx = x - 1;
by = y;
if (_kbhit())ch = _getch();
gotoxy(x, y);
printf(" ");
gotoxy(x, y + 1);
printf(" ");
gotoxy(x, y + 2);
printf(" ");
switch (ch)
{
case 'w':
if (y > 2) y--;
break;
case 's':
if (y < MAP_HEIGHT - 4) y++;
break;
case 'a':
if (x > 6) x--;
break;
case 'd':
if (x < MAP_WIDTH - 6) x++;
break;
case 'n':
fire(bx, by);
break;
}
if (y <= 4 && x <= 8) {
shop();
x = 70; y = 6;
first();
}
else if (y <= 4 && x >= 50 && x <= 57) {
first();
dunjun();
x = 70; y = 6;
}
gotoxy(x, y);
printf("\\()()/");
gotoxy(x, y + 1);
printf(" \\ /");
gotoxy(x, y + 2);
printf(" \\/");
gotoxy(1, 26);
printf("%d, %d", x, y);
Sleep(50);
}
This is a code that shoots bullets horizontally when the n button is pressed.
Now, when the bullet button is pressed, the bullet is fired and the bullet moves, but the player's output is cut off.
I want to print the bullet firing animation and the player at the same time, how do I do that?
It seems you are trying to make a command-line game that interacts with the console.
Update both at the same time.
You will need to paint/update the entire canvas to achieve this effect.
Maintain a 2D array char Map[MAP_HEIGHT][MAP_WIDTH]
and make changes to it depending on the user's input.
Then clear your console and print the contents of your Map
.
Suggestion: Consolidate and separate the input processing and canvas updation steps .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.