map: Added rectangle loader and adjustment for rectangle position when scrolling
authorLukas Krickl <lukas@krickl.dev>
Sun, 21 Sep 2025 15:05:02 +0000 (17:05 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 21 Sep 2025 15:05:02 +0000 (17:05 +0200)
src/defs.s
src/map.s
src/mapobj.s
src/video.s

index c3399a5161e6c235dacc6f3024424b796e93deab..235030b0967a860748ab33db923c2f5c1f495c13 100644 (file)
@@ -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
   
 
index 86430a8557864ca2c2a9ae5acbe84d31439a5c45..1e1503193be17d12828a35f7fe904f03c3644abb 100644 (file)
--- 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 
index 930b653ffdf2915e54145821f1fd7229db07f5e9..e629ce361126c971d32e4bac39c71ce0d92d4c91 100644 (file)
@@ -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
index e4bb9d43a516b7465294e81ac2f74adb532bfa84..5611a8392b7684dd058eb559e0648e35a81c74fa 100644 (file)
@@ -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