diff options
Diffstat (limited to 'src/text')
-rw-r--r-- | src/text/draw.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/text/draw.c b/src/text/draw.c index e6584bb..762fb8f 100644 --- a/src/text/draw.c +++ b/src/text/draw.c @@ -6,7 +6,10 @@ #include "util.h" #include "draw.h" -static char print_buf[(SOK_LEVEL_MAX_WIDTH + 1) * SOK_LEVEL_MAX_HEIGHT + 1]; +static char buf[(SOK_LEVEL_MAX_WIDTH + 1) * SOK_LEVEL_MAX_HEIGHT + 1]; + +#define SET_TILE(ctx, pos, c) \ + buf[(pos).y * ((ctx)->level.size.x + 1) + (pos).x] = (c) static bool draw_on_size( @@ -17,12 +20,10 @@ draw_on_size( UNUSED(ctx); UNUSED(data); - // fprintf(stderr, "size: x = %u, y = %u\n", size.x, size.y); - - memset(print_buf, ' ', sizeof(print_buf)); - print_buf[(size.x + 1) * size.y + 1] = '\0'; + memset(buf, ' ', sizeof(buf)); + buf[(size.x + 1) * size.y + 1] = '\0'; for (size_t i = 0; i < size.y; i++) { - print_buf[(i + 1) * (size.x + 1) - 1] = '\n'; + buf[(i + 1) * (size.x + 1) - 1] = '\n'; } return true; @@ -36,7 +37,7 @@ draw_on_home( void * const data ) { UNUSED(data); - print_buf[pos.y * (ctx->level.size.x + 1) + pos.x] = has_goal ? '+' : '@'; + SET_TILE(ctx, pos, has_goal ? '+' : '@'); return true; } @@ -46,9 +47,8 @@ draw_on_wall( const sok_pos_t pos, void * const data ) { - // fprintf(stderr, "wall: x = %u, y = %u\n", pos.x, pos.y); UNUSED(data); - print_buf[pos.y * (ctx->level.size.x + 1) + pos.x] = '#'; + SET_TILE(ctx, pos, '#'); return true; } @@ -62,7 +62,7 @@ draw_on_goal( ) { UNUSED(data); const char c = has_player ? '+' : (has_box ? '*' : '.'); - print_buf[pos.y * (ctx->level.size.x + 1) + pos.x] = c; + SET_TILE(ctx, pos, c); return true; } @@ -74,7 +74,7 @@ draw_on_box( void * const data ) { UNUSED(data); - print_buf[pos.y * (ctx->level.size.x + 1) + pos.x] = has_goal ? '*' : '$'; + SET_TILE(ctx, pos, has_goal ? '*' : '$'); return true; } @@ -104,7 +104,7 @@ draw( "%s\n" // level "%zu%s> ", // console level->pack, level->name, level_num, - print_buf, + buf, ctx->num_moves, sok_ctx_is_done(ctx) ? " (won!)" : "" ); } |