From 312caeb64d9edfd4711e25ec48d7781a148dbb34 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 7 Aug 2025 18:28:36 +0200 Subject: [PATCH] map: Added partial room redrawn when the player touches a door. Fixed room redraw request offset calculation --- src/map.s | 17 ++++++++++++++++- src/player.s | 24 +++++++++++++++++++++++- src/roompatterns.s | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/map.s b/src/map.s index e2ec3ee..b921cdd 100644 --- a/src/map.s +++ b/src/map.s @@ -150,6 +150,7 @@ map_draw_area_title: ; returns: ; a: flags ; b: tile index + ; hl: ptr to tile index map_get_tile: ; current map ld hl, map @@ -179,6 +180,8 @@ map_get_tile: ld b, a ld a, [hl] ; tile flags + dec hl + ret ; loads map tiles @@ -454,7 +457,7 @@ map_draw_all: ; a: row offset map_draw_shadow2: ld hl, map - ld de, MAP_W + ld de, MAP_W * c_size ; calculate what row to draw @offset_loop: @@ -496,7 +499,19 @@ map_draw_shadow2: ; redraw_shadow and redraw steps for 4 rows of tiles ; inputs: ; hl: bg target ptr + ; a: row offset (a*2*32 + hl) map_request_redraw2: + ; adjust screen target position by row offset + ld de, 32 + add a, a +@row_offset_calc: + cp a, 0 + jr z, @row_offset_done REL + add hl, de + dec a + jr @row_offset_calc REL +@row_offset_done: + ; write bg target ld a, h ld [redraw_bg], a diff --git a/src/player.s b/src/player.s index d37cd0b..baec583 100644 --- a/src/player.s +++ b/src/player.s @@ -43,11 +43,15 @@ unit_player_update: ld [player_rt_special_flags], a pop af ; get back a for next check pop de + + ; hl should still be tile ptr here ; check if player is on a door tile ; if so, remove door and queue a map redraw and a, CF_DOOR + push de call nz, unit_player_remove_door + pop de ; check for exit flags push de @@ -69,9 +73,27 @@ unit_player_update: ; standing on ; inputs: ; de: actor + ; hl: ptr to tile player is on unit_player_remove_door: - ; TODO: remove door tile, door flag + ; remove door tile, door flag ; and redraw map + ld a, 0x48 ; roof tile + ; clear map + ld [hl+], a + ld a, CF_COVERED + ld [hl], a + + ld hl, act_pos_y + add hl, de + ld a, [hl] ; load y offset + push af ; save y for after + call map_draw_shadow2 + pop af + + ld hl, SCRN0 + ; a = y position + call map_request_redraw2 + ret ; checks the current tile diff --git a/src/roompatterns.s b/src/roompatterns.s index dc43f01..ee10be7 100644 --- a/src/roompatterns.s +++ b/src/roompatterns.s @@ -121,7 +121,7 @@ room_pattern_flags_translation: .db CF_COLLISION, CF_COLLISION .db 0x00 ; floor ; doors - .db CF_DOOR, CF_DOOR, CF_DOOR, CF_DOOR + .db CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED ; roof .db CF_COVERED -- 2.30.2