# include <stdio.h>
# include <stdlib.h>
# include <conio.h>
int position_x, position_y;
int bullet_x, bullet_y;
int height, width;
void startup()
{
height = 20;
width = 30;
position_x = width / 2;
position_y = height / 2;
bullet_x = position_x;
bullet_y = 0;
}
void show()
{
system('cls');
int i, j;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
if (i == position_y && j == position_x)
printf("*");
else if ((i == bullet_y) && (j == bullet_x))
printf("|");
else
printf(" ");
}
printf("\n");
}
}
void updatewithoutinput()
{
if (bullet_y > -1)
bullet_y--;
}
void updatewithinput()
{
char input;
if (kbhit())
{
input = getchar();
if (input == 'w')
position_y--;
if (input == 's')
position_y++;
if (input == 'a')
position_x--;
if (input == 'd')
position_x++;
if (input == " ")
{
bullet_x = position_x;
bullet_y = position_y - 1;
}
}
}
int main()
{
startup();
while (1)
{
show();
updatewithoutinput();
updatewithinput();
}
return 0;
}
# include <stdlib.h>
# include <conio.h>
int position_x, position_y;
int bullet_x, bullet_y;
int height, width;
void startup()
{
height = 20;
width = 30;
position_x = width / 2;
position_y = height / 2;
bullet_x = position_x;
bullet_y = 0;
}
void show()
{
system('cls');
int i, j;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++)
{
if (i == position_y && j == position_x)
printf("*");
else if ((i == bullet_y) && (j == bullet_x))
printf("|");
else
printf(" ");
}
printf("\n");
}
}
void updatewithoutinput()
{
if (bullet_y > -1)
bullet_y--;
}
void updatewithinput()
{
char input;
if (kbhit())
{
input = getchar();
if (input == 'w')
position_y--;
if (input == 's')
position_y++;
if (input == 'a')
position_x--;
if (input == 'd')
position_x++;
if (input == " ")
{
bullet_x = position_x;
bullet_y = position_y - 1;
}
}
}
int main()
{
startup();
while (1)
{
show();
updatewithoutinput();
updatewithinput();
}
return 0;
}