aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'map.c')
-rw-r--r--map.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/map.c b/map.c
index 9d0a264..0c0bf86 100644
--- a/map.c
+++ b/map.c
@@ -2,10 +2,12 @@
#include <stdlib.h>
#include <curses.h>
#include <limits.h>
+
#include "map.h"
#include "config.h"
#include "stack.h"
#include "error.h"
+#include "path.h"
Map empty_map(size_t width, size_t height) {
Map map = malloc(sizeof(MapTile*) * height);
@@ -143,7 +145,8 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position *
/* FIXME: I don't think we need DRAW_MAP_OFFSET_{X,Y} anymore
* Although, at the same time, it does make less magic values, so I guess it's fine */
/* TODO: Maybe add an option to render with ▄? that doubles the resolution, but requires us to use ncursesw, probably. */
-void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, Position start, Position goal) {
+void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y, Position start, Position goal, Path path) {
+ (void)path;
/* I think it flickers less when we do that */
wnoutrefresh(stdscr);
@@ -198,6 +201,17 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y,
}
}
+ /* Draw path */
+ if (path != NULL) {
+ attron(COLOR_PAIR(PATH_COLOR));
+ 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, ' ');
+ cur = path[cur.y][cur.x].parent;
+ }
+ }
+
/* Draw the start */
attron(A_BOLD);
attron(COLOR_PAIR(START_COLOR));
@@ -215,3 +229,15 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y,
doupdate();
}
+void print_map_out(Map map, size_t width, size_t height) {
+ for (size_t i = 0; i < height; i++) {
+ for (size_t j = 0; j < width; j++) {
+ switch(map[i][j]) {
+ case EMPTY: putchar(EMPTY_CHAR); break;
+ case WALL: putchar(WALL_CHAR); break;
+ }
+ }
+ putchar('\n');
+ }
+}
+