#include #include #include #include #include "map.h" #include "config.h" #include "stack.h" Map empty_map(size_t width, size_t height) { Map map = malloc(sizeof(MapTile*) * height); if (map == NULL) return NULL; for (size_t row = 0; row < height; row++) { map[row] = malloc(sizeof(MapTile) * width); if (map[row] == NULL) return NULL; memset(map[row], 0, width*sizeof(MapTile)); } return map; } Map rbt_maze_map(size_t width, size_t height) { size_t map_width = width * 2 - 1, map_height = height * 2 - 1; Map map = empty_map(map_width, map_height); // Vertical walls for (size_t i = 1; i < map_width; i += 2) { for (size_t j = 0; j < map_height; j += 1) { map[j][i] = WALL; } } // Horizontal walls for (size_t i = 1; i < map_height; i += 2) { for (size_t j = 0; j < map_width; j += 1) { map[i][j] = WALL; } } //TODO: Draw the rest of the owl return map; } void draw_map(Map map, int width, int height, Position player_pos) { // Draw field char c; // The char for the current tile for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int color_pair = 0; // The color pair of the current char switch (map[i][j]) { case EMPTY: color_pair = COLOR_PAIR(EMPTY_COLOR); c = EMPTY_CHAR; break; case GOAL: color_pair = COLOR_PAIR(GOAL_COLOR); c = GOAL_CHAR; break; case WALL: color_pair = COLOR_PAIR(WALL_COLOR); c = WALL_CHAR; break; } attron(color_pair); mvaddch(i + DRAW_MAP_OFFSET_Y, j + DRAW_MAP_OFFSET_X, c); attroff(color_pair); } } // Draw the player attron(COLOR_PAIR(PLAYER_COLOR)); mvaddch(player_pos.y + DRAW_MAP_OFFSET_Y, player_pos.x + DRAW_MAP_OFFSET_X, PLAYER_CHAR); attroff(COLOR_PAIR(PLAYER_COLOR)); }