aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-29 16:30:06 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-29 16:30:06 +0300
commit3cdb2a67a452ec39dc13268ab86c11e737685073 (patch)
treec188ee6f083d0cb7c00e97722b3f3604a837f654
parent3f4d45ae2ad3258a4c13fe7bacc9f52d6ad68ee1 (diff)
downloadastar-3cdb2a67a452ec39dc13268ab86c11e737685073.tar.xz
Add direction arrows to draw_map()
-rw-r--r--main.c2
-rw-r--r--map.c32
2 files changed, 31 insertions, 3 deletions
diff --git a/main.c b/main.c
index f876697..eded452 100644
--- a/main.c
+++ b/main.c
@@ -39,7 +39,7 @@ void initialize_colors(void) {
init_pair(GOAL_COLOR, -1, COLOR_RED);
init_pair(WALL_COLOR, COLOR_WHITE, COLOR_WHITE);
init_pair(START_COLOR, -1, COLOR_RED);
- init_pair(PATH_COLOR, COLOR_RED, COLOR_RED);
+ init_pair(PATH_COLOR, COLOR_YELLOW, COLOR_RED);
init_pair(FRONTIER_COLOR, COLOR_BLUE, COLOR_BLUE);
init_pair(CURSOR_COLOR, -1, COLOR_RED);
}
diff --git a/map.c b/map.c
index 4303003..242af58 100644
--- a/map.c
+++ b/map.c
@@ -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));