// src/render/player.cpp
#include "player.h"
#include "../assets/character_frames.h"
#include <cstdio>

void draw_character(int x, int y, CharacterFrame frame) {
    int frame_index = static_cast<int>(frame);
    if (frame_index < 0 || frame_index >= CHARACTER_FRAME_COUNT)
        frame_index = 0; // fallback safety

    const char **character = PLAYER_FRAMES[frame_index];

    int character_height = 0;
    switch (frame) {
    case CharacterFrame::Walk1:
        character_height = CHARACTER_HEIGHT_1;
        break;
    case CharacterFrame::Walk2:
        character_height = CHARACTER_HEIGHT_2;
        break;
    case CharacterFrame::Crawl1:
        character_height = CHARACTER_HEIGHT_3;
        break;
    default:
        character_height = CHARACTER_HEIGHT_1;
        break;
    }

    for (int i = 0; i < character_height; i++) {
        printf("\033[%d;%dH%s", y + i + 1, x + 1, character[i]);
    }
    fflush(stdout);
}
