#include "main.h"
#include "world.h"
#include "player.h"

void render_console_slice() {
    // 플레이어의 현재 높이(y) 단면에 있는 블록들을 간단히 콘솔에 출력
    int py = (int)player.y;
    if (py < 0) py = 0;
    if (py >= WORLD_HEIGHT) py = WORLD_HEIGHT - 1;

    printf("\n--- World Slice at Y = %d (Player: %.1f, %.1f, %.1f) ---\n", py, player.x, player.y, player.z);
    for (int z = 0; z < WORLD_DEPTH; z++) {
        for (int x = 0; x < WORLD_WIDTH; x++) {
            if ((int)player.x == x && (int)player.z == z) {
                printf("P "); // 플레이어 위치
            } else {
                switch (get_block(x, py, z)) {
                    case BLOCK_AIR:   printf(". "); break;
                    case BLOCK_GRASS: printf("# "); break;
                    case BLOCK_DIRT:  printf("D "); break;
                    case BLOCK_STONE: printf("S "); break;
                    case BLOCK_WOOD:  printf("W "); break;
                }
            }
        }
        printf("\n");
    }
}

int main(void) {
    printf("Initializing Minecraft World in C...\n");
    init_world();
    init_player(16.0f, 5.0f, 16.0f);

    char cmd;
    while (true) {
        render_console_slice();
        printf("\nControls: [W] Forward [S] Backward [A] Left [D] Right [Q] Quit\n");
        printf("Command: ");
        scanf(" %c", &cmd);

        if (cmd == 'q' || cmd == 'Q') {
            printf("Exiting game...\n");
            break;
        } else if (cmd == 'w') {
            move_player(0, 0, -1);
        } else if (cmd == 's') {
            move_player(0, 0, 1);
        } else if (cmd == 'a') {
            move_player(-1, 0, 0);
        } else if (cmd == 'd') {
            move_player(1, 0, 0);
        }
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: