added positioning
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user