unit rendering: units are now hidden if they are inside a room
authorLukas Krickl <lukas@krickl.dev>
Thu, 31 Jul 2025 17:00:56 +0000 (19:00 +0200)
committerLukas Krickl <lukas@krickl.dev>
Thu, 31 Jul 2025 17:00:56 +0000 (19:00 +0200)
This is done by simply swapping the bg tilemap to a tile when the player is
not indoors. The BG priority bit is also set for all unit objects.

src/hw.inc
src/player.s
src/roompatterns.s
src/unit_demo.s
src/video.s
tiles/bank8000.inc

index e781a94ebb4b37699ddac284617fb2e8a1d638ad..0f0294e0df536583829901a3001b4c6c9678fc37 100644 (file)
@@ -89,7 +89,7 @@
 .def int OBJSIZE = 4
 .def int OAMRAM_SIZE = OBJSMAX * OBJSIZE
 
-#define OAM_FPRIO 0b10000000
+.def int OAM_FPRIO = 0b10000000
 #define OAM_FYFLIP 0b01000000
 #define OAM_FXFLIP 0b00100000
 #define OAM_DMG_PAL 0b00010000
index 5a8e8c912afe38bc7c5ab77833c62d79515133d2..d843ba049d2fd14bf6f439138ba221e20798097f 100644 (file)
@@ -214,7 +214,7 @@ unit_player:
   act_stat_def1 1, 1, 1, 1
   act_stat_def2 1, 1, 90, 1 
   act_st_def NULL, NULL, st_unit_player_update, st_unit_idle
-  act_def_meta unit_draw, 0x8C, 0, NULL
+  act_def_meta unit_draw, 0x8C, OAM_FPRIO, NULL
 
 st_unit_player_update:
   st_def 0x00, unit_player_update, st_unit_player_update 
index 76e745974e503a3d4524792c1dd51ea222ac8de0..dc43f01274ff5abf4910bcb723d576a4c27153ea 100644 (file)
@@ -111,7 +111,7 @@ room_pattern_tile_translation:
  ; doors
  .db 0x2E, 0x0E, 0x0C, 0x2C 
  ; roof
- .db 0x4A
+ .db 0x48
 
   ; translation table for flags
 room_pattern_flags_translation:
index f0416897aff58e8f712427706c1b545b2fefa484..1a9e3135b160886f81d0159ad5ff8bf2dae046ed 100644 (file)
@@ -41,11 +41,11 @@ unit_demo_1_cpu_update_idle:
 
 unit_demo_2:
   st_def 0x00, unit_demo_1_init, st_unit_idle
-  act_def ACT_T_DEMO_1, 0, 8, 8, 0 
+  act_def ACT_T_DEMO_1, 0, 3, 3, 0 
   act_stat_def1 1, 1, 1, 1
   act_stat_def2 1, 1, 32, 1
   act_st_def NULL, NULL, st_unit_demo_1_cpu_update_idle, st_unit_idle
-  act_def_meta unit_draw, 0x88, 0, NULL
+  act_def_meta unit_draw, 0x88, OAM_FPRIO, NULL
 
 unit_demo_warrior:
   st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update
@@ -53,7 +53,7 @@ unit_demo_warrior:
   act_stat_def1 1, 1, 1, 1 
   act_stat_def2 1, 1, 32, 1
   act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle
-  act_def_meta unit_draw, 0x88, 0, NULL
+  act_def_meta unit_draw, 0x88, OAM_FPRIO, NULL
 
 unit_demo_mage:
   st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update
@@ -61,7 +61,7 @@ unit_demo_mage:
   act_stat_def1 1, 1, 1, 1 
   act_stat_def2 1, 1, 32, 1
   act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle
-  act_def_meta unit_draw, 0x8C, 0, NULL
+  act_def_meta unit_draw, 0x8C, OAM_FPRIO, NULL
 
 unit_demo_thief:
   st_def 0x00, unit_demo_1_init, st_unit_demo_1_cpu_update
@@ -69,7 +69,7 @@ unit_demo_thief:
   act_stat_def1 1, 1, 1, 1 
   act_stat_def2 1, 1, 32, 1
   act_st_def NULL, NULL, st_unit_demo_1_cpu_update, st_unit_idle
-  act_def_meta unit_draw, 0x90, 0, NULL
+  act_def_meta unit_draw, 0x90, OAM_FPRIO, NULL
 
 
 unit_demo_priest:
index 1b7e60f19357c4a5bc4cb056c4c01a3afb38c30b..ddba5e53befa4b4f28104dcec4f1792cd4c6d912 100644 (file)
@@ -22,16 +22,7 @@ vblank:
   ; get inputs 
   call poll_inputs
 
-
-  ; cycle bg tiles for animations
-  ld a, [frame_count]
-  and a, BG_CYCLE_FRAMES
-  jr nz, @skip_cycle REL
-
-  ld a, [RLCD]
-  xor a, LCDCF_TILE_BANK 
-  ld [RLCD], a
-@skip_cycle:
+       call video_swap_tile_bank_player_indoors
 
   ld a, 1
   ld [frame_ready], a
@@ -50,6 +41,43 @@ scroll_write:
 
   ret
 
+       ; swaps tilebank if the player is currently
+       ; inside a room
+       ; sets LCDC_TILE_BANK if player is inside
+       ; unsets it otherwise
+video_swap_tile_bank_player_indoors:
+       ld a, [player_rt_special_flags]
+       and a, CF_COVERED
+       jr nz, @not_covered REL
+       
+       ld a, [RLCD]
+       ; set bit
+       or a, LCDCF_TILE_BANK
+       ld [RLCD], a
+
+       ret
+@not_covered:
+       ld a, [RLCD]
+       ; unset bit
+       and a, (~LCDCF_TILE_BANK) & 0xFF
+       ld [RLCD], a
+
+       ret
+
+       ; swaps the current tilebank by setting/unsetting 
+       ; LCDC_TILE_BANK
+video_swap_tile_bank:
+  ; cycle bg tiles for animations
+  ld a, [frame_count]
+  and a, BG_CYCLE_FRAMES
+  jr nz, @skip_cycle REL
+
+               ld a, [RLCD]
+               xor a, LCDCF_TILE_BANK 
+               ld [RLCD], a
+@skip_cycle:
+       ret
+
   ; wait for next vblank
 vblank_wait:
   ; disable interrupts
index cc016f478009901d1606440719c55f82a4e71ab3..e75f707430964e093bb024cf2db8b2a89f7bfeb8 100644 (file)
 .chr 11111111
 .chr 11111111
 ; tile 72
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
 ; tile 73
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
 ; tile 74
 .chr 33333333
 .chr 32222222
 .chr 11111111
 .chr 11111111
 ; tile 88
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
 ; tile 89
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
+.chr 33333333
 ; tile 90
 .chr 32222222
 .chr 32222222