map: Added partial room redrawn when the player touches a door.
authorLukas Krickl <lukas@krickl.dev>
Thu, 7 Aug 2025 16:28:36 +0000 (18:28 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 7 Aug 2025 16:28:36 +0000 (18:28 +0200)
Fixed room redraw request offset calculation

src/map.s
src/player.s
src/roompatterns.s

index e2ec3ee60577569bac381f254d80ab80b6625101..b921cdd5d11cca922719fb611677ce3a49c01cce 100644 (file)
--- 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
index d37cd0bc1801f96f9d86713e66ae17d912340943..baec58330ba7d7f0e671e03a28260cd9dd843836 100644 (file)
@@ -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
index dc43f01274ff5abf4910bcb723d576a4c27153ea..ee10be761ed96a939a818848fbdb55721bd0a77d 100644 (file)
@@ -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