aboutsummaryrefslogtreecommitdiff
path: root/map.c
diff options
context:
space:
mode:
authorKirill Petrashin <kirill8201@yandex.ru>2026-03-10 18:59:23 +0300
committerKirill Petrashin <kirill8201@yandex.ru>2026-03-10 18:59:23 +0300
commitfe40ce26ec975c2e2f89409913321064a7876d5c (patch)
tree143eccd14ef8270cf102aaf658abfadbe5f532dd /map.c
Initial commit
Diffstat (limited to 'map.c')
-rw-r--r--map.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/map.c b/map.c
new file mode 100644
index 0000000..21023f0
--- /dev/null
+++ b/map.c
@@ -0,0 +1,77 @@
+#include <string.h>
+#include <stdlib.h>
+#include <curses.h>
+#include <limits.h>
+#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));
+}
+