From: Lukas Krickl Date: Sat, 26 Jul 2025 15:28:09 +0000 (+0200) Subject: mapgen: Added room pattern placement for all 4 basic corners of the map X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5cf96fc6f15dfeccafcfd060ca17ffc34b178942;p=gbrg%2F.git mapgen: Added room pattern placement for all 4 basic corners of the map Currently there are only 2 room patterns but the basic idea works correctly ;) --- diff --git a/src/mapgen.s b/src/mapgen.s index c101245..8ffda5a 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -53,9 +53,10 @@ mapgen: ld [srand], a ; generate first room - push hl call mapgen_up_left_room - pop hl + call mapgen_bottom_left_room + call mapgen_up_right_room + call mapgen_bottom_right_room ; restore seed @@ -67,13 +68,119 @@ mapgen: ret + ; selects a random room pattern + ; inputs: + ; hl: room pattern table + ; a: table size + ; returns: + ; bc: room pattern ptr +mapgen_select_pattern: + push hl + + ld b, a + call rand + and a, b ; cap rand to table size + + pop hl + + ld b, 0 + ld c, a + add hl, bc + + + ; load table ptr + ld a, [hl+] + ld c, a + ld a, [hl] + ld b, a + + ret + + ; select room pattern 6x6 + ; preserves: hl +mapgen_select_pattern_6x6: + push hl + ld a, ROOM_PATTERN_6X6_SIZE + ld hl, room_pattern_6x6 + call mapgen_select_pattern + pop hl + ret + ; inputs: ; hl: [map] + ; preserves: hl mapgen_up_left_room: - ld bc, room_pattern_6by6 + push hl + + ; move to correct location on map + ld bc, MAP_W*c_size + add hl, bc + inc hl + inc hl + + call mapgen_select_pattern_6x6 + call mapgen_draw_room_pattern + pop hl ret + + ; inputs: + ; hl: [map] + ; preserves: hl +mapgen_bottom_left_room: + push hl + + ; move to correct location on map + ld bc, MAP_W*9*c_size + add hl, bc + inc hl + inc hl + + call mapgen_select_pattern_6x6 + + call mapgen_draw_room_pattern + pop hl + ret + + ; inputs: + ; hl: [map] + ; preserves: hl +mapgen_up_right_room: + push hl + + ; move to correct location on map + ld bc, (MAP_W/2)*c_size + MAP_W*c_size + add hl, bc + inc hl + inc hl + + call mapgen_select_pattern_6x6 + + call mapgen_draw_room_pattern + pop hl + ret + + + ; inputs: + ; hl: [map] + ; preserves: hl +mapgen_bottom_right_room: + push hl + + ; move to correct location on map + ld bc, (MAP_W/2)*c_size + MAP_W*9*c_size + add hl, bc + inc hl + inc hl + + call mapgen_select_pattern_6x6 + + call mapgen_draw_room_pattern + pop hl + ret + + ; draws a room pattern to the map ; inputs: ; hl: origin inside of map struct @@ -97,7 +204,7 @@ mapgen_draw_room_pattern: pop hl push bc - ld bc, MAP_W + ld bc, MAP_W*c_size add hl, bc ; next row pop bc @@ -143,7 +250,6 @@ mapgen_draw_room_pattern_row: ; tile table first mapgen_read_value_from_table room_pattern_tile_translation - ; write to map ld [hl+], a ; write tile diff --git a/src/roompatterns.s b/src/roompatterns.s index 35e9b1b..92d06bd 100644 --- a/src/roompatterns.s +++ b/src/roompatterns.s @@ -52,6 +52,15 @@ ; door right .de RPDR, 1 +room_pattern_empty: + rpheaderdef 0x66 + rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL + rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL + rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL + rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL + rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL + rprow RPFL, RPFL, RPFL, RPFL, RPFL, RPFL + room_pattern1: rpheaderdef 0x66 rprow RPUL, RPUW, RPUW, RPDU, RPUW, RPUR @@ -64,9 +73,9 @@ room_pattern1: ; translation tables for tiles room_pattern_tile_translation: ; walls - .db 0x6b, 0x6b, 0x6b - .db 0x6b, 0x6b, 0x6b - .db 0x6b, 0x6b + .db 0x44, 0x44, 0x44 + .db 0x44, 0x44, 0x44 + .db 0x44, 0x44 .db 0x00 ; floor ; doors .db 0x00, 0x00, 0x00, 0x00 @@ -82,6 +91,9 @@ room_pattern_flags_translation: .db CF_DOOR, CF_DOOR, CF_DOOR, CF_DOOR ; table of 6 by 6 room patterns -room_pattern_6by6: +room_pattern_6x6: + dw room_pattern_empty dw room_pattern1 -room_pattern_6by6_end: +room_pattern_6x6_end: + +#define ROOM_PATTERN_6X6_SIZE ((room_pattern_6x6_end - room_pattern_6x6) / 2)