map: Added the ability to have branching paths in rooms
authorLukas Krickl <lukas@krickl.dev>
Sat, 25 Jan 2025 10:55:03 +0000 (11:55 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 25 Jan 2025 10:55:03 +0000 (11:55 +0100)
This is simply done by following door pointers when a direction with
an existing door is picked.

src/map.s

index 58495845e1d5dab5b2dec7c6e9f0a5325ed0069c..dbd8d3d03e75963bc3ca99b639a3dcf6e35f8509 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -557,10 +557,10 @@ map_gen_next:
   ; if not done link to next room
 
   pop de ; de = previous room ptr 
-  push de ; save it again
 
   ; for now just pick a direction
   call map_gen_pick_direction 
+  push de ; save it again
   push hl
   call map_gen_link_rooms
   
@@ -650,8 +650,22 @@ map_gen_pick_direction:
   add a, e ; this must be 0 
   pop de ; get de back before jumping :^)
   cp a, 0
-  jr nz, @again REL
+  jr z, @good_pick REL
+
+  ; if it was not a good pick we 
+  ; move the room ptr from [hl] to de
+  dec hl ; hl = exit ptr
+  ld a, [hl+]
+  ld e, a
+  ld a, [hl]
+  ld d, a
+  ; fix value on the stack
+  pop bc  
+  push de 
+
+  jr @again REL
 
+@good_pick:
   ; get original result
   ld a, [tmp]