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
+2 -2
View File
@@ -65,14 +65,14 @@ void update_enemy_logic(void) {
int16_t min_dist_sq = (int16_t)dx * dx + (int16_t)dy * dy;
// Controllo 1: Direzione Down-Right (+1 X)
if (enemy_lx + 1 < MAP_SIZE && maze[enemy_ly][enemy_lx + 1] != 0) {
if (enemy_lx + 1 < map_size && maze[enemy_ly][enemy_lx + 1] != 0) {
int8_t ndx = (int8_t)player_lx - (int8_t)(enemy_lx + 1);
int8_t ndy = (int8_t)player_ly - (int8_t)enemy_ly;
int16_t d_sq = (int16_t)ndx * ndx + (int16_t)ndy * ndy;
if (d_sq < min_dist_sq) { min_dist_sq = d_sq; best_nx = enemy_lx + 1; best_ny = enemy_ly; }
}
// Controllo 2: Direzione Down-Left (+1 Y)
if (enemy_ly + 1 < MAP_SIZE && maze[enemy_ly + 1][enemy_lx] != 0) {
if (enemy_ly + 1 < map_size && maze[enemy_ly + 1][enemy_lx] != 0) {
int8_t ndx = (int8_t)player_lx - (int8_t)enemy_lx;
int8_t ndy = (int8_t)player_ly - (int8_t)(enemy_ly + 1);
int16_t d_sq = (int16_t)ndx * ndx + (int16_t)ndy * ndy;