aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-30 20:15:15 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-30 20:15:15 +0300
commitba64d4388997a8fb02e6de17ebad623f6948a632 (patch)
treedf5540032a42ec9d63f148b77c40ec130d8c05ae
parent49427f83bc3751fdb35f567b17abf9ddbd87bd48 (diff)
downloadastar-ba64d4388997a8fb02e6de17ebad623f6948a632.tar.xz
Add automatic mode to anim()
-rw-r--r--config.h2
-rw-r--r--path.c6
2 files changed, 8 insertions, 0 deletions
diff --git a/config.h b/config.h
index a2c97dd..463d325 100644
--- a/config.h
+++ b/config.h
@@ -4,6 +4,8 @@
#define COST_ORTHOGONAL 10
#define COST_DIAGONAL 14 /* sqrt(2) * 10 */
+#define ANIM_DELAY_USEC 10*1000
+
/* The characters that represent different tiles.
* Some have two characters -- that's because of the rendering trick where we
* use two characters back-to-back so they look like a square. */
diff --git a/path.c b/path.c
index 3ea350c..2547fd3 100644
--- a/path.c
+++ b/path.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <curses.h>
#include <math.h>
+#include <unistd.h>
#include "path.h"
#include "map.h"
@@ -12,16 +13,21 @@
#include "config.h"
/* TODO: somehow get offsets back to main */
+/* TODO: make it move the map maybe to show the path */
+/* TODO: figure out input when automatic = 1 */
int anim(Map map, size_t width, size_t height, Position start, Position end, Position *cur, char **visited, PositionPQ *frontier) {
static int offset_y = 0, offset_x = 0;
+ static char automatic = 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);
+ if (automatic) { usleep(ANIM_DELAY_USEC); return 0; }
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 'a': automatic = 1; break;
case 'q': return -1;
default: return 0;
}