Grow maze size with level (7x7 -> 17x17, +2 per level)

The maze side length is now a runtime global 'map_size' (MAP_SIZE=7 at
level 1, +2 per level, capped at MAX_MAP_SIZE=17), while the maze array
is allocated with the MAX_MAP_SIZE bound. All modules (maze DFS, fog
rendering, player/enemy bounds, hatch and enemy-spawn placement) now use
map_size at runtime.

- globals: maze[MAX_MAP_SIZE][MAX_MAP_SIZE], map_size global, MAX_MAP_SIZE=17.
- maze.c: DFS on map_size; stack/valid arrays made static (WRAM) and sized
  for the max maze to avoid hardware-stack overflow; hatch min distance
  scales with map_size/2.
- engine.c: sets map_size from level before generate_maze; enemy spawn min
  distance scales with map_size/2.
- render.c: flush the full 32x32 background map (the old rows 2-17
  optimization broke for large mazes where the 5x5 fog window wraps outside
  that range); dynamic bounds; signed/unsigned casts.
- player_logic/enemy_logic: dynamic map_size bounds.

Verified via PyBoy: sizes 7,9,11,13,15,17,17 across levels 1-7, each with
a hatch; rendering and movement intact at 17x17 and at 7x7.
This commit is contained in:
2026-06-24 12:26:48 +02:00
parent 509f162380
commit 5e8709ade0
11 changed files with 112 additions and 90 deletions
+7 -7
View File
@@ -22,9 +22,11 @@ extern volatile uint8_t game_over;
extern volatile uint8_t game_over_timer;
// --- Map Data ---
#define MAP_SIZE 7
// The generated maze: 0 = Wall, 1 = Floor, 2 = Victory Tile
extern uint8_t maze[MAP_SIZE][MAP_SIZE];
#define MAP_SIZE 7 // initial maze size (level 1); must be odd
#define MAX_MAP_SIZE 17 // hard cap for maze growth (odd); used as the array bound
// The generated maze: 0 = Wall, 1 = Floor, 2 = Victory Tile (hatch)
extern uint8_t map_size; // current maze side length (grows with level, MAP_SIZE..MAX_MAP_SIZE)
extern uint8_t maze[MAX_MAP_SIZE][MAX_MAP_SIZE];
// --- Camera & Rendering ---
// Map buffer used to draw the isometric tiles into the Game Boy Background map
@@ -36,9 +38,7 @@ extern int8_t scroll_y;
extern uint8_t stairs_lx;
extern uint8_t stairs_ly;
// --- Mappa e Entità ---
// The generated maze: 0 = Wall, 1 = Floor, 2 = Victory Tile
extern uint8_t maze[MAP_SIZE][MAP_SIZE];
// --- Mappa e Entita ---
extern uint8_t player_lx;
extern uint8_t player_ly;
extern uint8_t player_dir; // 0=DR, 1=DL, 2=UL, 3=UR
@@ -74,4 +74,4 @@ extern int16_t enemy_start_px, enemy_start_py;
extern int16_t enemy_target_px, enemy_target_py;
extern uint8_t enemy_cooldown;
#endif
#endif