aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.h3
-rw-r--r--main.c2
-rw-r--r--map.c68
3 files changed, 35 insertions, 38 deletions
diff --git a/config.h b/config.h
index 463d325..28599a0 100644
--- a/config.h
+++ b/config.h
@@ -18,7 +18,4 @@
#define CURSOR_CHAR_1 '<'
#define CURSOR_CHAR_2 '>'
-#define DRAW_MAP_OFFSET_X 2
-#define DRAW_MAP_OFFSET_Y 1
-
#endif /*CONFIG_H_ */
diff --git a/main.c b/main.c
index 33b3af7..7b0cbf1 100644
--- a/main.c
+++ b/main.c
@@ -179,7 +179,7 @@ int main(int argc, char **argv) {
case 's':
/* TODO: prompt for filename? or do a define idk */
map_to_bmp(map, width, height, start_pos, end_pos, path, visited, "out.bmp");
- mvprintw(height + map_offset_y + DRAW_MAP_OFFSET_Y + 1, map_offset_x, "Saved to out.bmp");
+ mvprintw(height + map_offset_y + 1, map_offset_x - 2, "Saved to out.bmp"); /* FIXME: clear the line first */
getch();
break;
case 'n':
diff --git a/map.c b/map.c
index 811daac..817f43c 100644
--- a/map.c
+++ b/map.c
@@ -10,8 +10,8 @@
#include "path.h"
#include "priority_queue.h"
-int map_offset_x = 0;
-int map_offset_y = 0;
+int map_offset_x = 2;
+int map_offset_y = 1;
Map empty_map(size_t width, size_t height) {
Map map = malloc(sizeof(MapTile*) * height);
@@ -221,30 +221,30 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
/* Clean up the area around the map */
for (ssize_t i = -1; i <= (ssize_t)(width*2 + 4); i++) { /* Horizontal */
- mvaddch(DRAW_MAP_OFFSET_Y - 1 + map_offset_y - 1, i + map_offset_x, ' ');
- mvaddch(DRAW_MAP_OFFSET_Y + height + map_offset_y + 1, i + map_offset_x, ' ');
- mvaddch(DRAW_MAP_OFFSET_Y + height + map_offset_y + 2, i + map_offset_x, ' ');
+ mvaddch(map_offset_y - 2, i + map_offset_x - 2, ' ');
+ mvaddch(height + map_offset_y + 1, i + map_offset_x - 2, ' ');
+ mvaddch(height + map_offset_y + 2, i + map_offset_x - 2, ' ');
}
for (size_t i = 0; i <= height + 2; i++) { /* Vertical */
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X - 2 + map_offset_x - 2, ' ');
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X - 1 + map_offset_x - 2, ' ');
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X + width * 2 + map_offset_x + 2, ' ');
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X + width * 2 + 1 + map_offset_x + 2, ' ');
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X + width * 2 + 2 + map_offset_x + 2, ' ');
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X + width * 2 + 3 + map_offset_x + 2, ' ');
+ mvaddch(i + map_offset_y - 1, map_offset_x - 4, ' ');
+ mvaddch(i + map_offset_y - 1, map_offset_x - 3, ' ');
+ mvaddch(i + map_offset_y - 1, width * 2 + 0 + map_offset_x + 2, ' ');
+ mvaddch(i + map_offset_y - 1, width * 2 + 1 + map_offset_x + 2, ' ');
+ mvaddch(i + map_offset_y - 1, width * 2 + 2 + map_offset_x + 2, ' ');
+ mvaddch(i + map_offset_y - 1, width * 2 + 3 + map_offset_x + 2, ' ');
}
/* 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 + map_offset_y, i + map_offset_x, WALL_CHAR);
- mvaddch(DRAW_MAP_OFFSET_Y + height + map_offset_y, i + map_offset_x, WALL_CHAR);
+ mvaddch(map_offset_y - 1, i + map_offset_x - 2, WALL_CHAR);
+ mvaddch(height + map_offset_y, i + map_offset_x - 2, WALL_CHAR);
}
for (size_t i = 1; i <= height; i++) { /* Vertical */
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X - 2 + map_offset_x, WALL_CHAR);
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X - 1 + map_offset_x, WALL_CHAR);
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X + width * 2 + map_offset_x, WALL_CHAR);
- mvaddch(i + map_offset_y, DRAW_MAP_OFFSET_X + width * 2 + 1 + map_offset_x, WALL_CHAR);
+ mvaddch(i + map_offset_y - 1, map_offset_x - 2, WALL_CHAR);
+ mvaddch(i + map_offset_y - 1, map_offset_x - 1, WALL_CHAR);
+ mvaddch(i + map_offset_y - 1, width * 2 + map_offset_x, WALL_CHAR);
+ mvaddch(i + map_offset_y - 1, width * 2 + map_offset_x + 1, WALL_CHAR);
}
attroff(COLOR_PAIR(WALL_COLOR));
@@ -271,8 +271,8 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
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 + map_offset_y, j*2 + DRAW_MAP_OFFSET_X + map_offset_x, c);
- mvaddch(i + DRAW_MAP_OFFSET_Y + map_offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, c);
+ mvaddch(i + map_offset_y, j*2 + map_offset_x, c);
+ mvaddch(i + map_offset_y, j*2 + 1 + map_offset_x, c);
attroff(color_pair);
}
}
@@ -280,8 +280,8 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
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 + map_offset_y, j*2 + DRAW_MAP_OFFSET_X + map_offset_x, ' ');
- mvaddch(i + DRAW_MAP_OFFSET_Y + map_offset_y, j*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, ' ');
+ mvaddch(i + map_offset_y, j*2 + map_offset_x, ' ');
+ mvaddch(i + map_offset_y, j*2 + 1 + map_offset_x, ' ');
if (visited != NULL && visited[i][j]) attroff(COLOR_PAIR(VISITED_COLOR));
}
}
@@ -291,12 +291,12 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
if (frontier != NULL) {
attron(COLOR_PAIR(FRONTIER_COLOR));
while (frontier->next != NULL) {
- mvaddch(frontier->pos.y + DRAW_MAP_OFFSET_Y + map_offset_y, frontier->pos.x*2 + DRAW_MAP_OFFSET_X + map_offset_x, ' ');
- mvaddch(frontier->pos.y + DRAW_MAP_OFFSET_Y + map_offset_y, frontier->pos.x*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, ' ');
+ mvaddch(frontier->pos.y + map_offset_y, frontier->pos.x*2 + map_offset_x, ' ');
+ mvaddch(frontier->pos.y + map_offset_y, frontier->pos.x*2 + 1 + map_offset_x, ' ');
frontier = frontier->next;
}
- mvaddch(frontier->pos.y + DRAW_MAP_OFFSET_Y + map_offset_y, frontier->pos.x*2 + DRAW_MAP_OFFSET_X + map_offset_x, ' ');
- mvaddch(frontier->pos.y + DRAW_MAP_OFFSET_Y + map_offset_y, frontier->pos.x*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, ' ');
+ mvaddch(frontier->pos.y + map_offset_y, frontier->pos.x*2 + map_offset_x, ' ');
+ mvaddch(frontier->pos.y + map_offset_y, frontier->pos.x*2 + 1 + map_offset_x, ' ');
attroff(COLOR_PAIR(FRONTIER_COLOR));
}
@@ -332,8 +332,8 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
c1 = '/'; c2 = '\\';
}
}
- mvaddch(cur.y + DRAW_MAP_OFFSET_Y + map_offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + map_offset_x, c1);
- mvaddch(cur.y + DRAW_MAP_OFFSET_Y + map_offset_y, cur.x*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, c2);
+ mvaddch(cur.y + map_offset_y, cur.x*2 + map_offset_x, c1);
+ mvaddch(cur.y + map_offset_y, cur.x*2 + 1 + map_offset_x, c2);
if (cur.x - path[cur.y][cur.x].parent.x == 0 || cur.y - path[cur.y][cur.x].parent.y == 0) {
length += COST_ORTHOGONAL;
} else {
@@ -343,27 +343,27 @@ void draw_map(Map map, size_t width, size_t height, Position start, Position goa
cur = path[cur.y][cur.x].parent;
}
attroff(COLOR_PAIR(PATH_COLOR));
- mvprintw(height + map_offset_y + DRAW_MAP_OFFSET_Y + 1, map_offset_x, "Path cost: %zu", length);
+ mvprintw(height + map_offset_y + 1, map_offset_x - 2, "Path cost: %zu", length);
}
/* Draw the start */
attron(A_BOLD);
attron(COLOR_PAIR(START_COLOR));
- mvaddch(start.y + DRAW_MAP_OFFSET_Y + map_offset_y, start.x*2 + DRAW_MAP_OFFSET_X + map_offset_x, START_CHAR_1);
- mvaddch(start.y + DRAW_MAP_OFFSET_Y + map_offset_y, start.x*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, START_CHAR_2);
+ mvaddch(start.y + map_offset_y, start.x*2 + map_offset_x, START_CHAR_1);
+ mvaddch(start.y + map_offset_y, start.x*2 + 1 + map_offset_x, START_CHAR_2);
attroff(COLOR_PAIR(START_COLOR));
/* Draw the goal */
attron(COLOR_PAIR(GOAL_COLOR));
- mvaddch(goal.y + DRAW_MAP_OFFSET_Y + map_offset_y, goal.x*2 + DRAW_MAP_OFFSET_X + map_offset_x, GOAL_CHAR_1);
- mvaddch(goal.y + DRAW_MAP_OFFSET_Y + map_offset_y, goal.x*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, GOAL_CHAR_2);
+ mvaddch(goal.y + map_offset_y, goal.x*2 + map_offset_x, GOAL_CHAR_1);
+ mvaddch(goal.y + map_offset_y, goal.x*2 + 1 + map_offset_x, GOAL_CHAR_2);
attroff(COLOR_PAIR(GOAL_COLOR));
/* Draw the cursor */
if (cursor != NULL) {
attron(COLOR_PAIR(CURSOR_COLOR));
- mvaddch(cursor->y + DRAW_MAP_OFFSET_Y + map_offset_y, cursor->x*2 + DRAW_MAP_OFFSET_X + map_offset_x, CURSOR_CHAR_1);
- mvaddch(cursor->y + DRAW_MAP_OFFSET_Y + map_offset_y, cursor->x*2 + DRAW_MAP_OFFSET_X + 1 + map_offset_x, CURSOR_CHAR_2);
+ mvaddch(cursor->y + map_offset_y, cursor->x*2 + map_offset_x, CURSOR_CHAR_1);
+ mvaddch(cursor->y + map_offset_y, cursor->x*2 + 1 + map_offset_x, CURSOR_CHAR_2);
attroff(COLOR_PAIR(CURSOR_COLOR));
}
attroff(A_BOLD);