diff options
Diffstat (limited to 'map.c')
| -rw-r--r-- | map.c | 32 |
1 files changed, 30 insertions, 2 deletions
@@ -210,6 +210,8 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position * /* TODO: so many fucking arguments lmao. Break it down into several functions? */ /* TODO: draw the start and goal with no background, allowing us to see the frontier/path/whatever's underneath. I think attr_get() will be useful */ +/* TODO: only draw a portion of the map (for bigger ones) */ +/* TODO: draw path arrows, because why not */ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, Position start, Position goal, Position *cursor, Path path, char **visited, PositionPQ *frontier) { /* I think it flickers less when we do that */ wnoutrefresh(stdscr); @@ -300,15 +302,41 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, if (path != NULL) { size_t length = 0; attron(COLOR_PAIR(PATH_COLOR)); + Position prev = goal; Position cur = goal; while (cur.x != start.x || cur.y != start.y) { - mvaddch(cur.y + DRAW_MAP_OFFSET_Y + offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + offset_x, ' '); - mvaddch(cur.y + DRAW_MAP_OFFSET_Y + offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, ' '); + char c1 = ' ', c2 = ' '; + if (cur.x + 1 - prev.x == 0) { /* To the right */ + if (cur.y == prev.y) { + c1 = ' '; c2 = '>'; + } else if (cur.y + 1 - prev.y == 0) { + c1 = ' '; c2 = 'J'; + } else { + c1 = ' '; c2 = '*'; + } + } else if (cur.x - prev.x == 1) { /* To the left */ + if (cur.y == prev.y) { + c1 = '<'; c2 = ' '; + } else if (cur.y + 1 - prev.y == 0) { + c1 = 'L'; c2 = ' '; + } else { + c1 = 'F'; c2 = ' '; + } + } else { /* Purely vertical */ + if (cur.y + 1 - prev.y == 0) { + c1 = '\\'; c2 = '/'; + } else if (cur.y - prev.y == 1) { + c1 = '/'; c2 = '\\'; + } + } + mvaddch(cur.y + DRAW_MAP_OFFSET_Y + offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + offset_x, c1); + mvaddch(cur.y + DRAW_MAP_OFFSET_Y + offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, c2); if (cur.x - path[cur.y][cur.x].parent.x == 0 || cur.y - path[cur.y][cur.x].parent.y == 0) { length += COST_ORTHOGONAL; } else { length += COST_DIAGONAL; } + prev = cur; cur = path[cur.y][cur.x].parent; } attroff(COLOR_PAIR(PATH_COLOR)); |
