From: Lukas Krickl Date: Thu, 21 Aug 2025 16:17:55 +0000 (+0200) Subject: mapgen: fixed most issues with the current door placement implementation X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=66d6c07be50160f55b9a613370c7788c47d98837;p=gbrg%2F.git mapgen: fixed most issues with the current door placement implementation --- diff --git a/src/map.s b/src/map.s index 22afe0d..903e464 100644 --- a/src/map.s +++ b/src/map.s @@ -76,6 +76,11 @@ map_draw_area_title: dec b jr nz, @loop REL + ; draw player map cursor number + ld a, [player_map_cursor] + add a, FONT_OFFSET+1 + ld [de], a + call ui_request_redraw ret diff --git a/src/mapgen.s b/src/mapgen.s index 043bdfc..ec7bbc4 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -146,22 +146,21 @@ mapgen: ; avoids placing doors at the edge. ; stops after plaving at least N doors mapgen_make_doors: - ld b, 1 - ld c, 1 ; bc = y/x position + ld b, 0 + ld c, 0 ; bc = y/x position ; start current ptr at 1/1 as well - ld hl, map_doors_location + 1 + FLOOR_W + ld hl, map_doors_location ; set map cursor - ld a, 1 + FLOOR_W + ld a, 0 ld [player_map_cursor], a - BREAK ; select how many doors we want push bc push hl call rand - add a, 12 ; at least N doors - and a, (FLOOR_MAP_COUNT - 1) + add a, 24 ; at least N doors + and a, (FLOOR_MAP_COUNT * 2) - 1 pop hl pop bc @@ -180,15 +179,11 @@ mapgen_make_doors: pop hl call make_door - cp a, 0xFF - jp z, @loop ; try again - BREAK call make_opp_door pop af dec a jr nz, @loop REL - BREAK ret ; creates the counterpart to @@ -236,7 +231,6 @@ make_opp_door: ; bc: current coordinate ; hl: current ptr ; returns: - ; a: FF -> unable to place door ; a: door direction -> door placed ; [hl]: ors new door bit ; bc: if door placed moves coordinates @@ -257,9 +251,9 @@ make_door: @try_again: pop af - ; try again... - ld a, 0xFF - ret + inc a + and a, 3 + jp make_door @left: ; can we even place it? @@ -267,9 +261,14 @@ make_door: cp a, 0 jp z, @try_again + ; is this door already set? + ; ld a, [hl] + ; and a, DIRLEFT + ; jp nz, @try_again + ; we can! ld a, [hl] - or a, DIRRIGHT + or a, DIRLEFT ld [hl], a dec c ; x-- @@ -282,8 +281,12 @@ make_door: cp a, FLOOR_W-1 jp z, @try_again + ; ld a, [hl] + ; and a, DIRRIGHT + ; jp nz, @try_again + ld a, [hl] - or a, DIRLEFT + or a, DIRRIGHT ld [hl], a inc c ; x++ @@ -297,12 +300,16 @@ make_door: cp a, 0 jp z, @try_again + ; ld a, [hl] + ; and a, DIRUP + ; jp nz, @try_again + ld a, [hl] or a, DIRUP ld [hl], a dec b ; y-- - + ; move hl up one row .rep i, FLOOR_W, 1, dec hl @@ -314,6 +321,10 @@ make_door: cp a, FLOOR_H-1 jp z, @try_again + ; ld a, [hl] + ; and a, DIRDOWN + ; jp nz, @try_again + ld a, [hl] or a, DIRDOWN ld [hl], a