diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-14 21:00:51 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-03-14 21:00:51 +0300 |
| commit | d0b1a2ab1a6f5c004d675d700181b16385a30b04 (patch) | |
| tree | 1da501dd9a52654e246cde8969e48b026a8adb47 /map.c | |
| parent | 8d165ccf784dd7a3afe35b68339f2b536591362c (diff) | |
Improve rendering
Diffstat (limited to 'map.c')
| -rw-r--r-- | map.c | 38 |
1 files changed, 29 insertions, 9 deletions
@@ -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)); } |
