improve 3d view

This commit is contained in:
quenousimporte 2025-03-27 18:03:12 +01:00
parent ea58c5883d
commit a5f6410159
1 changed files with 129 additions and 126 deletions

249
w/w.c
View File

@ -227,155 +227,158 @@ void update(char command)
}
}
char replacechar(char in, int y)
{
if (in == 'w')
{
return '#';
}
else if (in == 'd')
{
return '*';
}
return in;
}
void draw2()
{
char screen[10][10];
unsigned char screen[10][10];
for (int i = 0; i < 10; i++)
{
memset(screen[i], ' ', 10);
}
if (pov[2][0] != ' ')
{
// wall on the left
screen[0][0] = '\\';
screen[1][1] = '\\';
screen[9][0] = '/';
screen[8][1] = '/';
}
else
{
screen[1][0] = '_';
screen[1][1] = '_';
screen[7][0] = '_';
screen[7][1] = '_';
screen[2][1] = '|';
screen[3][1] = '|';
screen[4][1] = '|';
screen[5][1] = '|';
screen[6][1] = '|';
screen[7][1] = '|';
}
if (pov[2][2] != ' ')
{
// wall on the right
screen[0][9] = '/';
screen[1][8] = '/';
screen[9][9] = '\\';
screen[8][8] = '\\';
}
else
{
screen[1][9] = '_';
screen[1][8] = '_';
screen[7][9] = '_';
screen[7][8] = '_';
screen[2][8] = '|';
screen[3][8] = '|';
screen[4][8] = '|';
screen[5][8] = '|';
screen[6][8] = '|';
screen[7][8] = '|';
}
if (pov[1][1] == ' ')
{
// front is free
screen[3][4] = '_';
screen[3][5] = '_';
screen[5][4] = '_';
screen[5][5] = '_';
if (pov[0][0] != ' ')
{
screen[2][2] = '\\';
screen[3][3] = '\\';
screen[4][3] = '|';
screen[5][3] = '|';
screen[7][2] = '/';
screen[6][3] = '/';
}
if (pov[0][2] != ' ')
{
screen[3][6] = '/';
screen[2][7] = '/';
screen[4][6] = '|';
screen[5][6] = '|';
screen[6][6] = '\\';
screen[7][7] = '\\';
}
else
{
screen[2][8] = '|';
screen[3][8] = '|';
screen[4][8] = '|';
screen[5][8] = '|';
screen[6][8] = '|';
screen[7][8] = '|';
screen[3][6] = '_';
screen[3][7] = '_';
screen[5][6] = '_';
screen[5][7] = '_';
}
}
else
{
// front is blocked
// front constants
for (int i = 2; i < 8; i++)
{
screen[1][i] = '_';
screen[7][i] = '_';
}
if (pov[2][0] != ' ')
if (pov[2][0] == ' ')
{
// wall on the left
for (int i = 2; i < 8; i++) screen[i][1] = '|';
}
if (pov[2][2] != ' ')
{
// wall on the right
for (int i = 2; i < 8; i++) screen[i][8] = '|';
// front left free
screen[1][0] = '_';
screen[1][1] = '_';
screen[7][0] = '_';
screen[7][1] = '_';
}
else
{
for (int i = 8; i < 10; i++)
{
screen[1][i] = '_';
screen[7][i] = '_';
// front left wall
screen[0][0] = '\\';
screen[1][1] = '\\';
screen[8][1] = '/';
screen[9][0] = '/';
for (int i = 2; i < 8; i++) screen[i][1] = '|';
}
if (pov[2][2] == ' ')
{
// front right free
screen[1][8] = '_';
screen[1][9] = '_';
screen[7][8] = '_';
screen[7][9] = '_';
}
else
{
// front right wall
screen[8][8] = '\\';
screen[9][9] = '\\';
screen[0][9] = '/';
screen[1][8] = '/';
for (int i = 2; i < 8; i++) screen[i][7+1] = '|';
}
if (pov[1][1] == ' ')
{
// far constants
screen[3][4] = '_';
screen[3][5] = '_';
screen[5][4] = '_';
screen[5][5] = '_';
if (pov[0][0] == ' ')
{
// far left free
screen[3][2] = '_';
screen[3][3] = '_';
screen[5][2] = '_';
screen[5][3] = '_';
// if front is free as well
if (pov[2][0] == ' ')
{
screen[3][0] = '_';
screen[3][1] = '_';
screen[5][0] = '_';
screen[5][1] = '_';
}
}
else
{
// far left wall
screen[2][2] = '\\';
screen[3][3] = '\\';
screen[7][2] = '/';
screen[6][3] = '/';
screen[4][3] = '|';
screen[5][3] = '|';
// ensure front view is complete
for (int i = 2; i < 8; i++) screen[i][1] = '|';
}
if (pov[0][2] == ' ')
{
// far right free
screen[3][6] = '_';
screen[3][7] = '_';
screen[5][6] = '_';
screen[5][7] = '_';
// if front is free as well
if (pov[2][2] == ' ')
{
screen[3][8] = '_';
screen[3][9] = '_';
screen[5][8] = '_';
screen[5][9] = '_';
}
}
else
{
// far right wall
screen[6][6] = '\\';
screen[7][7] = '\\';
screen[2][7] = '/';
screen[3][6] = '/';
screen[4][5+1] = '|';
screen[5][5+1] = '|';
// ensure front view is complete
for (int i = 2; i < 8; i++) screen[i][7+1] = '|';
}
}
// doors (front only)
if (pov[1][1] == 'd')
{
for (int i = 4; i <= 7; i++)
{
for (int j = 3; j < 7; j++)
screen[i][j] = 176;
}
}
if (pov[2][0] == 'd')
{
for (int i = 5; i < 9; i++) screen[i][0] = 176;
}
if (pov[2][2] == 'd')
{
for (int i = 5; i < 9; i++) screen[i][9] = 176;
}
// print result
printf("o----------o\n");
for (int i = 0; i < 10; i++)
{
printf("|");
for (int j = 0; j < 10; j++)
{
printf("%c", screen[i][j]);
}
printf("\n");
printf("|\n");
}
printf("o----------o\n");
}
void draw()
@ -388,7 +391,7 @@ void draw()
#endif
draw2();
return;
printf("\n\n\n");
printf(" o=======o\n");
@ -408,7 +411,7 @@ void draw()
}
else
{
printf("%c", replacechar(pov[y][x], y));
printf("%c", pov[y][x]);
}
}
printf(" |\n");