mapgen: player spawn map is now selected randomly
authorLukas Krickl <lukas@krickl.dev>
Sun, 24 Aug 2025 17:21:26 +0000 (19:21 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 24 Aug 2025 17:21:26 +0000 (19:21 +0200)
src/mapgen.s

index ec7bbc4d7f798c51d9f7c8f2499f4fbeed542ff9..bc1383860188d194f4695f9829bbc9cee0fd274f 100644 (file)
@@ -8,6 +8,7 @@ mapgen_init:
        call act_save_init
        call mapgen_seed
        call mapgen_make_doors
+       call mapgen_select_player_spawn
        call mapgen
        ret
        
@@ -576,4 +577,29 @@ mapgent_unit_randomize_or_reaload_position:
 
        pop_all
        ret
+       
+       ; selects player spawn room 
+       ; selects a random room that has an exit and
+       ; sets the map cursor
+       ; then places the player on a tile without flags
+mapgen_select_player_spawn:
+       call rand
+       and a, FLOOR_MAP_COUNT-1
+       ld hl, map_doors_location
+       ld d, 0
+       ld e, a
+       add hl, de
+       ; check if the selected room has doors (is not 0)
+
+       ld a, [hl]
+       cp a, 0
+       jr z, mapgen_select_player_spawn REL
+
+       ; write selected room
+       ld a, e 
+       ld [player_map_cursor], a
 
+       ; TODO: move player position
+       
+
+       ret