Newer
Older
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
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#include "dungeon.h"
#include "draw_dungeon.h"
void draw_dist_map(dungeon_t *d, uint32_t dist[MAP_HEIGHT][MAP_WIDTH], int hardness_limit) {
int x, y;
for (y = 0; y < MAP_HEIGHT; y++) {
for (x = 0; x < MAP_WIDTH; x++) {
if (y == d->player_pos.y && x == d->player_pos.x) {
printf("@");
} else if (d->hardness[y][x] <= hardness_limit) {
if (dist[y][x] == INT_MAX) printf("X");
else printf("%d", dist[y][x] % 10);
} else {
printf(" ");
}
}
printf("\n");
}
}
char get_map_char(dungeon_t *d, int y, int x) {
int i;
// Check each position from top down, i.e. check the layers which would
// render over other layers first.
if (y == 0 || y == (MAP_HEIGHT-1) || x == 0 || x == (MAP_WIDTH-1)) {
if (y == 0 || y == (MAP_HEIGHT - 1)) return '-';
else return '|';
}
if (x == d->player_pos.x && y == d->player_pos.y) return '@';
for (i = 0; i < d->upstair_count; i++) {
if (x == d->upstair_list[i].x && y == d->upstair_list[i].y) {
return '<';
}
}
for (i = 0; i < d->downstair_count; i++) {
if (x == d->downstair_list[i].x && y == d->downstair_list[i].y) {
return '>';
}
}
for (i = 0; i < d->room_count; i++) {
room_t *r = d->room_list + i;
if (x >= r->x && x < r->x + r->w && y >= r->y && y < r->y + r->h) {
return '.';
}
}
if (d->hardness[y][x] == 0) {
return '#';
}
return ' ';
}
void draw_map(dungeon_t *d) {
int i, j;
for (i = 0; i < MAP_HEIGHT; i++) {
for (j = 0; j < MAP_WIDTH; j++) {
printf("%c", get_map_char(d, i, j));
}
printf("\n");
}
}