aboutsummaryrefslogtreecommitdiff
path: root/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'path.c')
-rw-r--r--path.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/path.c b/path.c
index a462a25..033f881 100644
--- a/path.c
+++ b/path.c
@@ -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;
}