From 054eb4912c832d04d49062236f5533b8aa2377e4 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 16 Feb 2026 08:30:15 +0100 Subject: [PATCH] mapgen: Added room pattern drawing. Room patterns are template for possible rooms. For now there is just one. --- assets | 2 +- makefile | 1 + maps/f1r1.inc | 7 ++++ src/mapgen.s | 98 +++++++++++++++++++++++++++++++++++++-------------- src/player.s | 2 +- 5 files changed, 82 insertions(+), 28 deletions(-) create mode 100644 maps/f1r1.inc diff --git a/assets b/assets index 0dbebcf..dfacc03 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 0dbebcf3cabc2340d9fc5c28cabcbfda248f5be8 +Subproject commit dfacc03a9d29342f17f2a688733c6124edc841a7 diff --git a/makefile b/makefile index e9bcf01..8c778e4 100644 --- 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 index 0000000..f42c70e --- /dev/null +++ b/maps/f1r1.inc @@ -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 + diff --git a/src/mapgen.s b/src/mapgen.s index 343289a..78212f3 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -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: diff --git a/src/player.s b/src/player.s index 82b95eb..6b7517f 100644 --- a/src/player.s +++ b/src/player.s @@ -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 -- 2.30.2