usage of enums for frames

This commit is contained in:
Priec
2025-11-14 19:20:14 +01:00
parent 9170524d33
commit 8fa8bf392b
5 changed files with 52 additions and 39 deletions

View File

@@ -1,25 +1,33 @@
// src/render/player.cpp
#include "player.h"
#include "player_mask.h"
#include <cstdio>
void draw_player(int x, int y, int frame_index) {
void draw_player(int x, int y, PlayerFrame frame) {
int frame_index = static_cast<int>(frame);
if (frame_index < 0 || frame_index >= PLAYER_FRAME_COUNT)
frame_index = 0; // fallback safety
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;
const char **character = PLAYER_FRAMES[frame_index];
// Draw the sprite starting from (x, y)
for (int i = 0; i < sprite_height; i++) {
printf("\033[%d;%dH%s", y + i + 1, x + 1, sprite[i]);
int character_height = 0;
switch (frame) {
case PlayerFrame::Walk1:
character_height = PLAYER_MASK_LINES_FRAME_1;
break;
case PlayerFrame::Walk2:
character_height = PLAYER_MASK_LINES_FRAME_2;
break;
case PlayerFrame::Crawl1:
character_height = PLAYER_MASK_LINES_FRAME_3;
break;
default:
character_height = PLAYER_MASK_LINES_FRAME_1;
break;
}
for (int i = 0; i < character_height; i++) {
printf("\033[%d;%dH%s", y + i + 1, x + 1, character[i]);
}
fflush(stdout);
}