DungeonCrawl
Loading...
Searching...
No Matches
map_generator.h File Reference

Exposes functions for generating the game map. More...

Go to the source code of this file.

Functions

void generate_map ()
 Generate the map and populate it with keys, enemies, and the exit.

Detailed Description

Exposes functions for generating the game map.

Definition in file map_generator.h.

Function Documentation

◆ generate_map()

void generate_map ( )

Generate the map and populate it with keys, enemies, and the exit.

Definition at line 317 of file map_generator.c.

317 {
318 // Better random seed using a combination of time and process info
319 unsigned int seed = (unsigned int) time(NULL);
320 // XOR with address of a stack variable to add more entropy
321 int stack_var;
322 seed ^= (uintptr_t) &stack_var;
323 srand(seed);
324
325 // Initialize the map with walls
327
328 int start_x = 0;
329 int start_y = 0;
330 int start_edge = 0;
331 if (!exit_x && !exit_y) {
332 // No exit yet, so this is the first time generating the map
333 // Generate map with a random start position (at the start_edge)
334 // Start position must be an odd coordinate (for dfs) and should be at least 3 cells away from other edges (not start_edge)
335 start_edge = rand() % 4;
336 set_start_position(start_edge, &start_x, &start_y);
337 } else {
338 make_exit_into_start(&start_edge, &start_x, &start_y);
339 }
340
341 generate_maze(start_x, start_y);
342
343 place_exit(start_edge);
344
345 populate_map();
346
347 set_player_start_pos(start_x, start_y);
348}
void initialize_map()
Initialize the map with walls.
void place_exit(int start_edge)
Place the exit on a random edge of the map, ensuring there's a path to it.
void make_exit_into_start(int *start_edge, int *start_x, int *start_y)
Set the start position on the map based on the previous exit position.
void generate_maze(int start_x, int start_y)
Generate a new maze using recursive backtracking.
void set_start_position(int start_edge, int *start_x, int *start_y)
Set the start position on the map.
void set_player_start_pos(const int player_x, const int player_y)
Sets the starting position of the player.
Definition map_mode.c:26
void populate_map()
@breif Populates the map with a key, enemies, and fountains