video: Added fade out and fade in for map transitions
authorLukas Krickl <lukas@krickl.dev>
Mon, 7 Jul 2025 07:11:57 +0000 (09:11 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 7 Jul 2025 07:11:57 +0000 (09:11 +0200)
src/player.s
src/video.s

index e089beee469ee1801233a50107c4a025055bec6e..e93d82134904343adaf67c3dd8730cd008659ed7 100644 (file)
@@ -99,6 +99,9 @@ unit_check_exit_hit:
     ret z ; if not input bail
 @skip_input_check:
   
+  ; fade out
+  call video_fade_out
+
   ; now we can load the map
 
   ; load map ptr
@@ -106,8 +109,6 @@ unit_check_exit_hit:
   ld de, exit_to
   add hl, de ; hl = map ptr
   
-  ; fade out
-  call video_fade_out
 
   ld a, [hl+]
   ld c, a
@@ -117,9 +118,6 @@ unit_check_exit_hit:
   ld l, a ; hl = map header ptr
   call map_load 
 
-  ; fade back in
-  call video_fade_in
-
   pop bc ; bc = exit table now 
   ; finally adjust player position
   
@@ -153,6 +151,17 @@ unit_check_exit_hit:
   call z, map_exit_absolute_adjust
   call nz, map_exit_relative_adjust
 
+
+  ; scroll to player's position
+  ld de, player_unit 
+  call unit_scroll_center
+  call next_vblank_wait
+  call scroll_write
+
+  ; fade back in
+  call video_fade_in
+
+
   ret
 
   ; adjusts player position to aboslute
index 5b712ade2f874ceab51f8cec9a89505910a3db55..7b5fa9d6b2fbc565807861acd2d53328a2d40750 100644 (file)
@@ -126,34 +126,73 @@ video_wait_n_frames:
     or a, c
   jr nz, video_wait_n_frames REL
   ret
-  
+  ; sets BGP | $1
+  ; and then waits
+  ; inputs:
+  ;   $1: BGP
+#macro video_fade_set_bgp
+  ld a, BGP 
+  and a, $1 
+  ld [RBGP], a
+
+  ; wait for 5 frames
+  ld bc, 0x4
+  call video_wait_n_frames
+#endmacro
+
   ; fades out the background
   ; interrupts must be enabled
   ; preserved all registers
+  ; disables window
 video_fade_out:
-  push_all
+  push_all 
+  
+  ; disable winodw
+  ld a, [RLCD]
+  and a, ~LCDF_WINDOWON & 0xFF
+  ld [RLCD], a
 
-  ld bc, 0xF
-  call video_wait_n_frames
+  video_fade_set_bgp 0b11111111
+  video_fade_set_bgp 0b11111100
+  video_fade_set_bgp 0b11110000
+  video_fade_set_bgp 0b11000000
+  video_fade_set_bgp 0b00000000
 
   pop_all
   ret
 
+
+
   ; fades the background in
   ; sets RBGP to BGP
   ; interrupts must be enabled
   ; preserved all registers
+  ; enables window
 video_fade_in:
   push_all
 
-  ld bc, 0xF
-  call video_wait_n_frames
+  ; disable winodw
+  ld a, [RLCD]
+  and a, ~LCDF_WINDOWON & 0xFF
+  ld [RLCD], a
+
+  video_fade_set_bgp 0b11000000
+  video_fade_set_bgp 0b11110000
+  video_fade_set_bgp 0b11111100
+  video_fade_set_bgp 0b11111111
+
+  ; re-enable window
+  ld a, [RLCD]
+  or a, LCDF_WINDOWON
+  ld [RLCD], a
 
   ld a, BGP 
   ld [RBGP], a
 
   pop_all
   ret
+#undefine video_fade_set_bgp
 
   ; loads tilesets
   ; inputs: