19 int neighbor_count = 0;
21 for (
int i = 0; i < 4; i++) {
22 int dx = x + directions[i].dx;
23 int dy = y + directions[i].dy;
25 if (map[dx][dy] != WALL) {
30 return neighbor_count == 1 && map[x][y] == FLOOR;
43 x = rand() % (WIDTH - 2) + 1;
44 y = rand() % (HEIGHT - 2) + 1;
58 for (
int i = -ENEMY_MIN_DISTANCE; i <= ENEMY_MIN_DISTANCE + 1; i++) {
59 for (
int j = -ENEMY_MIN_DISTANCE; j <= ENEMY_MIN_DISTANCE + 1; j++) {
60 if (map[x + i][y + j] == GOBLIN || map[x + i][y + j] == START_DOOR) {
72 for (
int i = 0; i < ENEMY_COUNT; i++) {
78 x = rand() % (WIDTH - 2) + 1;
79 y = rand() % (HEIGHT - 2) + 1;
96 x = rand() % (WIDTH - 2) + 1;
97 y = rand() % (HEIGHT - 2) + 1;
100 map[x][y] = LIFE_FOUNTAIN;
104 x = rand() % (WIDTH - 2) + 1;
105 y = rand() % (HEIGHT - 2) + 1;
108 map[x][y] = MANA_FOUNTAIN;
Exposes common types and constants for the games map.
void place_enemies()
Place enemies in random locations on the map.
int is_close_to_enemy(int x, int y)
Check if a cell is close to an enemy (based on ENEMY_MIN_DISTANCE)
void place_key()
Place a key in a dead end that is not the start or exit edge.
void place_fountains()
Place a mana fountain and a life fountain in random dead ends on the map.
int is_dead_end(int x, int y)
Check if a cell is a dead end (is floor and has only one neighboring non-wall cell)
void populate_map()
@breif Populates the map with a key, enemies, and fountains
Exposes functions for populating the generated map with a key, enemies and fountains.