mapgen: Added room pattern drawing.
authorLukas Krickl <lukas@krickl.dev>
Mon, 16 Feb 2026 07:30:15 +0000 (08:30 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 16 Feb 2026 07:30:15 +0000 (08:30 +0100)
Room patterns are template for possible rooms. For now there is just
one.

assets
makefile
maps/f1r1.inc [new file with mode: 0644]
src/mapgen.s
src/player.s

diff --git a/assets b/assets
index 0dbebcf3cabc2340d9fc5c28cabcbfda248f5be8..dfacc03a9d29342f17f2a688733c6124edc841a7 160000 (submodule)
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit 0dbebcf3cabc2340d9fc5c28cabcbfda248f5be8
+Subproject commit dfacc03a9d29342f17f2a688733c6124edc841a7
index e9bcf01945527d81154272a65380ce88c567ec74..8c778e495f71e417f5e7ec321a2403316030910d 100644 (file)
--- a/makefile
+++ b/makefile
@@ -22,4 +22,5 @@ tiles:
 .PHONY: maps
 maps: 
        ./tools/tmx2map.py assets/maps/l1.tmx > maps/l1.inc
+       ./tools/tmx2map.py assets/maps/f1r1.tmx > maps/f1r1.inc
 
diff --git a/maps/f1r1.inc b/maps/f1r1.inc
new file mode 100644 (file)
index 0000000..f42c70e
--- /dev/null
@@ -0,0 +1,7 @@
+; this map was generated by tmx2map.py
+
+.db 0x1, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x0, 0x0
+.db 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x0, 0x1, 0x1, 0x0, 0x1, 0x0, 0x2, 0x1, 0x0, 0x1, 0x1, 0x0, 0x1, 0x2
+.db 0x0, 0x1, 0x0, 0x2, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x2
+.db 0x0, 0x0, 0x0, 0x0
+
index 343289a947e32f2b56edddc1b8f0c5859f5503c6..78212f33db8bd8362665bfa6aba5ffe93d15a621 100644 (file)
@@ -79,7 +79,11 @@ map_generate:
 .beginscope
        ld hl, mapgen_tiles + MAP_SECTION_SIZE * MAP_SECTION_PER_ROW * MAP_SECTION_SIZE \
                * $1 + MAP_SECTION_SIZE * $2
-       ld bc, 0x0808 ; 8x8 fill the entire sector for now
+       
+       ; TODO load different patterns for each floor
+       ld de, floor1_patterns
+       ld a, (floor1_patterns_end-floor1_patterns) / 2
+
        call mapgen_make_room
 .endscope
 #endmacro
@@ -101,40 +105,82 @@ mapgen_make_rooms:
        _mapgen_make_room_section 1, 3
        ret
        
+       ; draws a map row (8 tiles)
+       ; inputs:
+       ;               de: room pattern
+       ;   hl: destination
+       ;       returns:
+       ;               hl: next destination
+       ;               de: next de
+#macro _mapgen_make_room_draw_row
+               push hl
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               ld a, [de]
+               ld [hl+], a
+               inc de
+               
+               pop hl
+               ld bc, MAP_W
+               add hl, bc
+#endmacro
+
        ; generates a single rectanglular room
        ; the caller must ensutre hl has enough tiles in 
        ;       the y and x direction to allow the room to fit.
        ; places actors in the room
        ; inputs:
+       ;               de: table of 8x8 room patterns
+       ;                a: table length (must be a multiple of 2)
        ;               hl: start position in tile map
-       ;       b/c: height/width of room
 mapgen_make_room:
-       ld de, MAP_W
-@draw_row:
-               ; save original hl
-               push hl
-               
-               ; save original w
-               push bc
-
-@draw_col:
-                       ld a, TI_FLOOR
-                       ld [hl+], a
-
-                       dec c ; width--
-                       jr nz, @draw_col REL
-               
-               ; restore w
-               ld a, b ; need to save height
-               pop bc
-               ld b, a
+       ; TODO: pick a room pattern
+       
+       ; de = room pattern to draw
+       ld a, [de]
+       ld b, a
+       inc de
+       ld a, [de]
+       ld e, b
+       ld d, a
 
-               pop hl
-               ; go to next row
-               add hl, de
-               dec b ; height--
-               jr nz, @draw_row REL
+       ; draw a row (8 tiles) 8 times
+       _mapgen_make_room_draw_row
+       _mapgen_make_room_draw_row
+       _mapgen_make_room_draw_row
+       _mapgen_make_room_draw_row
+       _mapgen_make_room_draw_row
+       _mapgen_make_room_draw_row
+       _mapgen_make_room_draw_row
+       _mapgen_make_room_draw_row
        
        ; TODO: place actors
        ret
        
+
+f1r1:
+#include "f1r1.inc"
+
+floor1_patterns:
+dw f1r1
+dw f1r1
+floor1_patterns_end:
index 82b95eb19276ea7dde5b6e6cd9dc7295fdba2e86..6b7517f5eeab1b3b6b3c033bdd1a5f13e7b48c66 100644 (file)
@@ -15,7 +15,7 @@
 
        ; sets up the player actor
 player_init:
-       ld a, 2
+       ld a, 1
        ld [player+act_pos_y], a
        ld [player+act_pos_x], a