From d0b1a2ab1a6f5c004d675d700181b16385a30b04 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Sat, 14 Mar 2026 21:00:51 +0300 Subject: Improve rendering --- map.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'map.c') diff --git a/map.c b/map.c index f83269f..b0dbb2a 100644 --- a/map.c +++ b/map.c @@ -94,21 +94,31 @@ Map rbt_maze_map(size_t width, size_t height, unsigned int seed) { return map; } -void draw_map(Map map, int width, int height, Position start) { +void draw_map(Map map, size_t width, size_t height, Position start, Position goal) { + // Draw the walls around the map (they are not in map) + attron(COLOR_PAIR(WALL_COLOR)); + for (size_t i = 0; i <= width*2 + 3; i++) { + mvaddch(DRAW_MAP_OFFSET_X - 2, i, WALL_CHAR); + mvaddch(DRAW_MAP_OFFSET_Y + height, i, WALL_CHAR); + } + for (size_t i = 1; i <= height; i++) { + mvaddch(i, DRAW_MAP_OFFSET_X - 2, WALL_CHAR); + mvaddch(i, DRAW_MAP_OFFSET_X - 1, WALL_CHAR); + mvaddch(i, DRAW_MAP_OFFSET_X + width * 2, WALL_CHAR); + mvaddch(i, DRAW_MAP_OFFSET_X + width * 2 + 1, WALL_CHAR); + } + attroff(COLOR_PAIR(WALL_COLOR)); + // Draw field char c; // The char for the current tile - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { + for (size_t i = 0; i < height; i++) { + for (size_t j = 0; j < width; j++) { int color_pair = 0; // The color pair of the current char switch (map[i][j]) { case EMPTY: color_pair = COLOR_PAIR(EMPTY_COLOR); c = EMPTY_CHAR; break; - case GOAL: - color_pair = COLOR_PAIR(GOAL_COLOR); - c = GOAL_CHAR; - break; case WALL: color_pair = COLOR_PAIR(WALL_COLOR); c = WALL_CHAR; @@ -116,14 +126,24 @@ void draw_map(Map map, int width, int height, Position start) { } attron(color_pair); - mvaddch(i + DRAW_MAP_OFFSET_Y, j + DRAW_MAP_OFFSET_X, c); + /* We draw two characters because they roughly make a square together. + * It looks WAY better if we do this. */ + mvaddch(i + DRAW_MAP_OFFSET_Y, j*2 + DRAW_MAP_OFFSET_X, c); + mvaddch(i + DRAW_MAP_OFFSET_Y, j*2 + DRAW_MAP_OFFSET_X + 1, c); attroff(color_pair); } } // Draw the start attron(COLOR_PAIR(START_COLOR)); - mvaddch(start.y + DRAW_MAP_OFFSET_Y, start.x + DRAW_MAP_OFFSET_X, START_CHAR); + mvaddch(start.y + DRAW_MAP_OFFSET_Y, start.x*2 + DRAW_MAP_OFFSET_X, START_CHAR_1); + mvaddch(start.y + DRAW_MAP_OFFSET_Y, start.x*2 + DRAW_MAP_OFFSET_X + 1, START_CHAR_2); attroff(COLOR_PAIR(START_COLOR)); + + /* Draw the goal */ + attron(COLOR_PAIR(GOAL_COLOR)); + mvaddch(goal.y + DRAW_MAP_OFFSET_Y, goal.x*2 + DRAW_MAP_OFFSET_X, GOAL_CHAR_1); + mvaddch(goal.y + DRAW_MAP_OFFSET_Y, goal.x*2 + DRAW_MAP_OFFSET_X + 1, GOAL_CHAR_2); + attroff(COLOR_PAIR(GOAL_COLOR)); } -- cgit v1.2.3