walking stickman is now also crawling

This commit is contained in:
Priec
2025-11-14 14:12:40 +01:00
parent 13f01d13f8
commit b147d92423
22 changed files with 135 additions and 25 deletions

View File

@@ -4,16 +4,32 @@
#include "player_mask.h"
#include <cstdio>
void draw_player(int view_width, int view_height) {
const int sprite_height = PLAYER_MASK_LINES;
const int sprite_width = 3; // all rows are same width (3 chars)
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, PLAYER_MASK[i]);
printf("\033[%d;%dH%s", center_y + i + 1, center_x + 1, sprite[i]);
}
fflush(stdout);
}