map: Added new rectangle clear object.
authorLukas Krickl <lukas@krickl.dev>
Fri, 10 Oct 2025 15:13:37 +0000 (17:13 +0200)
committerLukas Krickl <lukas@krickl.dev>
Fri, 10 Oct 2025 15:13:37 +0000 (17:13 +0200)
This object allows the targeted removal of all collision objects.
This is way more straight forward than automatically clearing large rectangles.

src/defs.s
src/map.s
src/mapobj.s
src/video.s

index ad55b8560e19c750b28f1db9975ae942ab748322..3ca6774cd0ae683d00b302beaee9c904d0a58bb0 100644 (file)
 .de MOT_RECT, 1
 .de MOT_ACTOR_SPAWNER, 1
 .de MOT_SET_MAP_ROUTINE, 1
+.de MOT_RECT_CLEAR, 1
 
        ; map object struct
 .se 0
index ef1fb5dea6cb1c39dd9181e3ba6b7ddb76d6f619..35089cb73a279005f328af7abc79c056cf1bccd2 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -376,6 +376,7 @@ l1_objs:
        modef2 MOT_ACTOR_SPAWNER, 0, 11, ACT_T_GUARD, 0x80 
        modef MOT_SET_PAT, 0, 18, pat_center_empty_wall
 
+       modef MOT_RECT_CLEAR, 0, 18, 0
        modef2 MOT_RECT, 0, 18, 0x0F, 0x08
        modef2 MOT_ACTOR_SPAWNER, 0, 18, ACT_T_GUARD, 0x40 
 
@@ -384,6 +385,7 @@ l1_objs:
        modef MOT_DISABLE_SCROLL, 0, 0x20, 0
        modef MOT_SET_MAP_ROUTINE, 0, 0x20, map_r_enable_scroll_all_enemies_defeated
        
+       modef MOT_RECT_CLEAR, 0, 0x21, 0
        modef MOT_SET_PAT, 0, 0x21, pat_center_empty_wall
        modef MOT_SET_PAT, 0, 0x2E, pat_empty 
        modef MOT_DISABLE_SCROLL, 0, 0x30, 0
index 99fa9a8743db935c63eb698592554f13f51bf0af..8bdea40130607182a2d8f2a5f574a37d7b20ea13 100644 (file)
@@ -13,6 +13,7 @@ mo_routines:
         dw mo_rect
         dw mo_actor_spawner
         dw mo_set_map_routine
+        dw mo_rect_clear
        
 mo_nop:
        ret
@@ -229,3 +230,20 @@ mo_set_map_routine:
        ld a, [hl+]
        ld [map_routine+1], a
        ret
+       
+       ; clears all map rectangles
+       ; use this to despawn current collision
+       ; shapes
+mo_rect_clear:
+       ld hl, rectangles
+       ld de, r_size
+       ld b, RECT_MAX
+       xor a, a
+@loop:
+       ld [hl], a
+       add hl, de
+       dec b
+       jr nz, @loop REL
+
+
+       ret
index d5843867726c6063910f26260206633a89b9f112..f226a18de558e32d214c87e7ff7e71bb954d3728 100644 (file)
@@ -145,16 +145,8 @@ scroll_up_adjust:
                ld [hl+], a
                ; hl = r_pos_x
        
-               ; check if off-screen
-               cp a, -16 & 0xFF ; do not despawn if -16
-               jr nc, @no_rect_despawn REL
-
-               pop de
-               push de
-               ; despawn if *bottom* corner is far off-screen
-               cp a, 0xA0 
-               call nc, rect_despawn
-
+               ; rectangles never despawn
+               ; unless cleared with mo_rect_clear
 @no_rect_despawn:
                
                pop hl