36 lines
1.0 KiB
C++
36 lines
1.0 KiB
C++
// src/render/player.cpp
|
|
|
|
#include "player.h"
|
|
#include "player_mask.h"
|
|
#include <cstdio>
|
|
|
|
void draw_player(int view_width, int view_height, int frame_index) {
|
|
if (frame_index < 0 || frame_index >= PLAYER_FRAME_COUNT)
|
|
frame_index = 0; // fallback
|
|
|
|
const char **sprite = PLAYER_FRAMES[frame_index];
|
|
int sprite_height = 0;
|
|
if (frame_index == 0)
|
|
sprite_height = PLAYER_MASK_LINES_FRAME_1;
|
|
else if (frame_index == 1)
|
|
sprite_height = PLAYER_MASK_LINES_FRAME_2;
|
|
else
|
|
sprite_height = PLAYER_MASK_LINES_FRAME_3;
|
|
|
|
// Width from first line
|
|
int sprite_width = 0;
|
|
if (sprite_height > 0) {
|
|
const char *first_line = sprite[0];
|
|
while (first_line[sprite_width] != '\0')
|
|
sprite_width++;
|
|
}
|
|
|
|
int center_x = view_width / 2 - sprite_width / 2;
|
|
int center_y = view_height / 2 - sprite_height / 2;
|
|
|
|
for (int i = 0; i < sprite_height; i++) {
|
|
printf("\033[%d;%dH%s", center_y + i + 1, center_x + 1, sprite[i]);
|
|
}
|
|
fflush(stdout);
|
|
}
|