mapgen: added fix for left doors
authorLukas Krickl <lukas@krickl.dev>
Tue, 29 Jul 2025 15:51:19 +0000 (17:51 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 29 Jul 2025 15:51:19 +0000 (17:51 +0200)
This fix prevents doors from being generated
next to walls

src/mapgen.s

index 948502e4be1391360d0f5dc4026c3a38ce855e23..bfe045decdcf59cf927ecac7f6dd258cbfcbb5ed 100644 (file)
@@ -281,6 +281,7 @@ mapgen_draw_room_pattern_row:
   push de  
 @x_loop:
     ld a, [bc]
+               call mapgen_fix_door_adjacent_to_collider
 
     ; read from tile and flag tables and write to map
 
@@ -307,3 +308,66 @@ mapgen_draw_room_pattern_row:
 
   pop de
   ret
+
+       ; fixed door tile if it is adjacent to
+       ; a collider tile
+       ; inputs:
+       ;       hl: map_ptr
+       ;                a: pattern entry
+       ; returns:
+       ;               a: unchanged if not next to collider or not a door pattern
+       ;   a: changed to wall tile if it is a door and is next to a collider
+       ; preserves:
+       ;               hl, bc, de
+mapgen_fix_door_adjacent_to_collider:
+       cp a, RPDU
+       jp z, @up_door 
+
+       cp a, RPDB
+       jp z, @down_door 
+
+       cp a, RPDL
+       jp z, @left_door 
+
+       cp a, RPDR
+       jp z, @right_door 
+
+       ret
+@up_door:
+
+       ; move up one row
+       ; and see if the tile is a collider
+
+       ret
+
+@down_door:
+       ret
+@left_door:
+       push hl
+       push de
+
+       ; move left one tile
+       ; and check for colliders
+       ld de, (-c_size) & 0xFFFF
+       add hl, de
+       ; hl = tile to the left
+
+       inc hl ; go to flags
+       ld d, a ; store a for later
+       ld a, [hl]
+       and a, CF_COLLISION
+       ld a, d ; restore a's value
+
+       ; if not collider do not fix
+       jr z, @no_left_fix REL
+               ; otherwise load left wall into a
+               ld a, RPLW
+
+@no_left_fix:
+               
+       pop de
+       pop hl
+
+       ret
+@right_door:
+       ret