aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--map.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/map.c b/map.c
index 2966437..9443bcf 100644
--- a/map.c
+++ b/map.c
@@ -200,12 +200,8 @@ Map file_plaintext_map(char *filename, size_t *width, size_t *height, Position *
return map;
}
-/* 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. */
/* TODO: so many fucking arguments lmao. Break it down into several functions? */
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[height][width], PositionPQ *frontier) {
- (void)path;
/* I think it flickers less when we do that */
wnoutrefresh(stdscr);
@@ -221,7 +217,7 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y,
mvaddch(i + offset_y, DRAW_MAP_OFFSET_X + width * 2 + 1 + offset_x + 2, ' ');
}
- /* Draw the borders*/
+ /* Draw the borders */
attron(COLOR_PAIR(WALL_COLOR));
for (size_t i = 0; i <= width*2 + 3; i++) { /* Horizontal */
mvaddch(DRAW_MAP_OFFSET_Y - 1 + offset_y, i + offset_x, WALL_CHAR);
@@ -236,30 +232,41 @@ void draw_map(Map map, size_t width, size_t height, int offset_x, int offset_y,
attroff(COLOR_PAIR(WALL_COLOR));
/* Draw field */
- char c; /* The char for the current tile */
- for (size_t i = 0; i < height; i++) {
- for (size_t j = 0; j < width; j++) {
- int color_pair = 0; /* The color pair of the current char */
- switch (map[i][j]) {
- case EMPTY:
- if (visited != NULL && visited[i][j])
- color_pair = COLOR_PAIR(VISITED_COLOR);
- else
- color_pair = COLOR_PAIR(EMPTY_COLOR);
- c = EMPTY_CHAR;
- break;
- case WALL:
- color_pair = COLOR_PAIR(WALL_COLOR);
- c = WALL_CHAR;
- break;
-
+ if (map != NULL) {
+ char c; /* The char for the current tile */
+ for (size_t i = 0; i < height; i++) {
+ for (size_t j = 0; j < width; j++) {
+ int color_pair = 0; /* The color pair of the current char */
+ switch (map[i][j]) {
+ case EMPTY:
+ if (visited != NULL && visited[i][j])
+ color_pair = COLOR_PAIR(VISITED_COLOR);
+ else
+ color_pair = COLOR_PAIR(EMPTY_COLOR);
+ c = EMPTY_CHAR;
+ break;
+ case WALL:
+ color_pair = COLOR_PAIR(WALL_COLOR);
+ c = WALL_CHAR;
+ break;
+
+ }
+ attron(color_pair);
+ /* We draw two characters because they roughly make a square together.
+ * It looks WAY better if we do this. */
+ mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + offset_x, c);
+ mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, c);
+ attroff(color_pair);
+ }
+ }
+ } else {
+ for (size_t i = 0; i < height; i++) {
+ for (size_t j = 0; j < width; j++) {
+ if (visited != NULL && visited[i][j]) attron(COLOR_PAIR(VISITED_COLOR));
+ mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + offset_x, ' ');
+ mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, ' ');
+ if (visited != NULL && visited[i][j]) attroff(COLOR_PAIR(VISITED_COLOR));
}
- attron(color_pair);
- /* We draw two characters because they roughly make a square together.
- * It looks WAY better if we do this. */
- mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + offset_x, c);
- mvaddch(i + DRAW_MAP_OFFSET_Y + offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + offset_x, c);
- attroff(color_pair);
}
}