diff options
| -rw-r--r-- | main.c | 1 | ||||
| -rw-r--r-- | path.c | 31 |
2 files changed, 25 insertions, 7 deletions
@@ -134,6 +134,7 @@ int main(int argc, char **argv) { case 'l': offset_x += 2; break; case 'j': offset_y += 1; break; case 'k': offset_y -= 1; break; + case 'a': anim = !anim; break; case 'n': if (is_maze) { map_free(map, height); @@ -9,13 +9,20 @@ #include "priority_queue.h" #include "error.h" +/* TODO: somehow get offsets back to main */ int anim(Map map, size_t width, size_t height, Position start, Position end, Position *cur, char visited[height][width], PositionPQ *frontier) { - draw_map(map, width, height, 0, 0, start, end, cur, NULL, visited, frontier); - mvprintw(height+2, 0, "cur: %zu %zu", cur->x, cur->y); - /* TODO: input, automatic mode */ - switch (getch()) { - case 'q': - return -1; + static int offset_y = 0, offset_x = 0; + while (1) { + draw_map(map, width, height, offset_x, offset_y, start, end, cur, NULL, visited, frontier); + mvprintw(height+2 + offset_y, offset_x, "cur: %zu %zu", cur->x, cur->y); + switch (getch()) { + case 'h': offset_x -= 2; break; + case 'l': offset_x += 2; break; + case 'j': offset_y += 1; break; + case 'k': offset_y -= 1; break; + case 'q': return -1; + default: return 0; + } } return 0; } @@ -48,6 +55,9 @@ Path breadth_first_search_path(int dirs, Map map, size_t width, size_t height, P if (cur.x == end.x && cur.y == end.y) { ppq_free(frontier); + if (should_anim) { + clear(); + } return path; /* Found path */ } @@ -64,10 +74,17 @@ Path breadth_first_search_path(int dirs, Map map, size_t width, size_t height, P } if (should_anim) { - if (anim(map, width, height, start, end, &cur, visited, frontier) == -1) return NULL; + if (anim(map, width, height, start, end, &cur, visited, frontier) == -1) { + clear(); + return NULL; + } } } + if (should_anim) { + clear(); + } + return NULL; } |
