diff options
| author | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-03 17:52:45 +0300 |
|---|---|---|
| committer | Kirill Petrashin <kirill8201@yandex.ru> | 2026-04-03 17:52:45 +0300 |
| commit | 104d23d1e4949fe01038f4a2fd706acf163b55c9 (patch) | |
| tree | 2d04966fe2155b5b845b53680b05ae84d6283b05 /map.c | |
| parent | 0dd0adf9547758381573caa6a7d485415fafb33d (diff) | |
| download | astar-104d23d1e4949fe01038f4a2fd706acf163b55c9.tar.xz | |
Remove DRAW_MAP_OFFSET_[XY]
Diffstat (limited to 'map.c')
| -rw-r--r-- | map.c | 68 |
1 files changed, 34 insertions, 34 deletions
@@ -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); |
