added positioning

This commit is contained in:
Priec
2025-11-14 16:42:16 +01:00
parent f6a13309f7
commit d8da84cffc
3 changed files with 14 additions and 17 deletions

View File

@@ -4,9 +4,9 @@
#include "player_mask.h"
#include <cstdio>
void draw_player(int view_width, int view_height, int frame_index) {
void draw_player(int x, int y, int frame_index) {
if (frame_index < 0 || frame_index >= PLAYER_FRAME_COUNT)
frame_index = 0; // fallback
frame_index = 0; // fallback safety
const char **sprite = PLAYER_FRAMES[frame_index];
int sprite_height = 0;
@@ -17,19 +17,9 @@ void draw_player(int view_width, int view_height, int frame_index) {
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;
// Draw the sprite starting from (x, y)
for (int i = 0; i < sprite_height; i++) {
printf("\033[%d;%dH%s", center_y + i + 1, center_x + 1, sprite[i]);
printf("\033[%d;%dH%s", y + i + 1, x + 1, sprite[i]);
}
fflush(stdout);
}