1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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));
}
|