diff --git a/w/w.c b/w/w.c index 40cab3f..3686f08 100644 --- a/w/w.c +++ b/w/w.c @@ -15,6 +15,7 @@ const char* map[] = { "wwwwwwwww" }; char pov[3][3]; +unsigned char pov3d[10][10]; typedef struct { int x; @@ -69,6 +70,146 @@ char charatpos(int x, int y) return map[8-y][x]; } +void update3dpov() +{ + for (int i = 0; i < 10; i++) + { + memset(pov3d[i], ' ', 10); + } + + // front constants + for (int i = 2; i < 8; i++) + { + pov3d[1][i] = '_'; + pov3d[7][i] = '_'; + } + + if (pov[2][0] == ' ') + { + // front left free + pov3d[1][0] = '_'; + pov3d[1][1] = '_'; + pov3d[7][0] = '_'; + pov3d[7][1] = '_'; + } + else + { + // front left wall + pov3d[0][0] = '\\'; + pov3d[1][1] = '\\'; + pov3d[8][1] = '/'; + pov3d[9][0] = '/'; + for (int i = 2; i < 8; i++) pov3d[i][1] = '|'; + } + + if (pov[2][2] == ' ') + { + // front right free + pov3d[1][8] = '_'; + pov3d[1][9] = '_'; + pov3d[7][8] = '_'; + pov3d[7][9] = '_'; + } + else + { + // front right wall + pov3d[8][8] = '\\'; + pov3d[9][9] = '\\'; + pov3d[0][9] = '/'; + pov3d[1][8] = '/'; + for (int i = 2; i < 8; i++) pov3d[i][7+1] = '|'; + } + + if (pov[1][1] == ' ') + { + // far constants + pov3d[3][4] = '_'; + pov3d[3][5] = '_'; + pov3d[5][4] = '_'; + pov3d[5][5] = '_'; + + if (pov[0][0] == ' ') + { + // far left free + pov3d[3][2] = '_'; + pov3d[3][3] = '_'; + pov3d[5][2] = '_'; + pov3d[5][3] = '_'; + + // if front is free as well + if (pov[2][0] == ' ') + { + pov3d[3][0] = '_'; + pov3d[3][1] = '_'; + pov3d[5][0] = '_'; + pov3d[5][1] = '_'; + } + } + else + { + // far left wall + pov3d[2][2] = '\\'; + pov3d[3][3] = '\\'; + pov3d[7][2] = '/'; + pov3d[6][3] = '/'; + pov3d[4][3] = '|'; + pov3d[5][3] = '|'; + + // ensure front view is complete + for (int i = 2; i < 8; i++) pov3d[i][1] = '|'; + } + + if (pov[0][2] == ' ') + { + // far right free + pov3d[3][6] = '_'; + pov3d[3][7] = '_'; + pov3d[5][6] = '_'; + pov3d[5][7] = '_'; + + // if front is free as well + if (pov[2][2] == ' ') + { + pov3d[3][8] = '_'; + pov3d[3][9] = '_'; + pov3d[5][8] = '_'; + pov3d[5][9] = '_'; + } + } + else + { + // far right wall + pov3d[6][6] = '\\'; + pov3d[7][7] = '\\'; + pov3d[2][7] = '/'; + pov3d[3][6] = '/'; + pov3d[4][5+1] = '|'; + pov3d[5][5+1] = '|'; + + // ensure front view is complete + for (int i = 2; i < 8; i++) pov3d[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++) + pov3d[i][j] = 176; + } + } + if (pov[2][0] == 'd') + { + for (int i = 5; i < 9; i++) pov3d[i][0] = 176; + } + if (pov[2][2] == 'd') + { + for (int i = 5; i < 9; i++) pov3d[i][9] = 176; + } +} + void updatepov() { int x = gamestate.location.x; @@ -79,33 +220,33 @@ void updatepov() { for (int rtoloffset = -1; rtoloffset < 2; rtoloffset++) { - int newX = x, newY = y; - switch (orientation) - { - case 'n': - newX += rtoloffset; - newY += frontoffset; - break; - case 's': - newX -= rtoloffset; - newY -= frontoffset; - break; - case 'e': - newX += frontoffset; - newY -= rtoloffset; - break; - case 'w': - newX -= frontoffset; - newY += rtoloffset; - break; - } - pov[2 - frontoffset][1 + rtoloffset] = charatpos(newX, newY); + int newX = x, newY = y; + switch (orientation) + { + case 'n': + newX += rtoloffset; + newY += frontoffset; + break; + case 's': + newX -= rtoloffset; + newY -= frontoffset; + break; + case 'e': + newX += frontoffset; + newY -= rtoloffset; + break; + case 'w': + newX -= frontoffset; + newY += rtoloffset; + break; } - + pov[2 - frontoffset][1 + rtoloffset] = charatpos(newX, newY); + } } + + update3dpov(); } - void forward() { if (pov[1][1] != 'w') @@ -227,160 +368,6 @@ void update(char command) } } -void draw2() -{ - unsigned char screen[10][10]; - for (int i = 0; i < 10; i++) - { - memset(screen[i], ' ', 10); - } - - // front constants - for (int i = 2; i < 8; i++) - { - screen[1][i] = '_'; - screen[7][i] = '_'; - } - - if (pov[2][0] == ' ') - { - // front left free - screen[1][0] = '_'; - screen[1][1] = '_'; - screen[7][0] = '_'; - screen[7][1] = '_'; - } - else - { - // 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("o----------o\n"); -} - void draw() { @@ -390,10 +377,26 @@ void draw() system("clear"); #endif - draw2(); - return; + int shift = 10; + for (int i = 0; i < shift; i++) printf("\n"); + + for (int i = 0; i < shift; i++) printf(" "); + printf("o----------o\n"); + + for (int i = 0; i < 10; i++) + { + for (int s = 0; s < shift; s++) printf(" "); + printf("|"); + for (int j = 0; j < 10; j++) + { + printf("%c", pov3d[i][j]); + } + printf("|\n"); + } + for (int i = 0; i < shift; i++) printf(" "); + printf("o----------o\n"); - printf("\n\n\n"); + /*printf("\n\n\n"); printf(" o=======o\n"); for (int y = 0; y < 3; y++) @@ -419,7 +422,7 @@ void draw() printf(" o=======o\n"); printf(" | %s |\n", gamestate.name); printf(" o=======o\n"); - printf("\n\n"); + printf("\n\n");*/ }