From d5bdf8a273b74e2d2f1de42d57ba477f37c626bc Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 21 Sep 2025 17:05:02 +0200 Subject: [PATCH] map: Added rectangle loader and adjustment for rectangle position when scrolling --- src/defs.s | 2 +- src/map.s | 3 ++- src/mapobj.s | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/video.s | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/defs.s b/src/defs.s index c3399a5..235030b 100644 --- a/src/defs.s +++ b/src/defs.s @@ -81,7 +81,7 @@ .de act_ac, 1 ; every actor has a collision rectangle -.de act_rectangle, r_size +.de act_rect, r_size .de act_size, 0 diff --git a/src/map.s b/src/map.s index 86430a8..1e15031 100644 --- a/src/map.s +++ b/src/map.s @@ -236,7 +236,8 @@ l1_map: l1_objs: modef MOT_SET_PAT, 0, 3, pat_center_empty_wall - modef MOT_RECT, 0, 3, 0 + ; rectangle at y/x 0/0 with height 16 width 64 + modef MOT_RECT, 0, 3, 0x0802 modef MOT_SET_PAT, 0, 8, pat_center_grass modef MOT_SET_PAT, 0, 10, pat_center_empty_wall modef MOT_SET_PAT, 0, 0x1E, pat_empty diff --git a/src/mapobj.s b/src/mapobj.s index 930b653..e629ce3 100644 --- a/src/mapobj.s +++ b/src/mapobj.s @@ -115,6 +115,50 @@ mo_enable_scroll: ; inputs: ; de: map object ptr mo_rect: + ld hl, mo_dat + add hl, de + ; hl = dat1 + + ; current row always has y-position 16 + ; for the bottom left corner + + ; calculate y position + ld a, [hl] + and a, 0xF0 + swap a + mul8 a + ; a = y offset + ld b, MAP_ROW_H + add a, b + ld b, a ; b = y position + + ; calculate height + ld a, [hl+] ; hl = dat2 + and a, 0x0F + mul8 a + ; d = height + ld d, a + + ; calculate x position + ld a, [hl] + and a, 0xF0 + swap a + mul8 a + ; c = x offset + ld c, a + + ; calculate width + ld a, [hl] + and a, 0x0F + mul8 a + ; e = width + ld e, a + + ; flag hard-coded to WALL + ld a, RF_WALL + + call rect_try_add + ret ; spawns an actor spawner diff --git a/src/video.s b/src/video.s index e4bb9d4..5611a83 100644 --- a/src/video.s +++ b/src/video.s @@ -87,6 +87,16 @@ scroll_up_adjust: cp a, 0x70 call nc, actor_despawn pop af + + pop hl + push hl + + ; adjust actor rectangle position + ld de, act_rect+r_pos_y + add hl, de + ld a, [hl] + add a, 1 + ld [hl], a pop hl @@ -102,7 +112,29 @@ scroll_up_adjust: add a, 1 ld [player+act_pos_y], a - ; TODO: adjust rectangles + ld a, [player+act_rect+r_pos_y] + inc a + ld [player+act_rect+r_pos_y], a + + ; adjust rectangles + ld b, RECT_MAX + ld hl, rectangles + +@rect_loop: + push hl + + ld de, r_pos_y + add hl, de + + ld a, [hl] + inc a + ld [hl], a + + pop hl + dec b + ld de, r_size + add hl, de + jr nz, @rect_loop REL ret ; writes scroll to scroll registers -- 2.30.2