video: scrolls now happen on a per-pixel basis
authorLukas Krickl <lukas@krickl.dev>
Sat, 4 Oct 2025 19:20:57 +0000 (21:20 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 4 Oct 2025 19:20:57 +0000 (21:20 +0200)
map objects and draws happen every 16th scroll.

src/player.s
src/update.s
src/video.s

index 5e751d3c6040ea200e1deb1d4d93f20a9c0d1221..b020e474af190c19a9581f41f70cbbade0ca478a 100644 (file)
@@ -89,28 +89,35 @@ player_update:
 
 #define PLAYER_SPRITE_IDLE1 0x8D
        
-       ; if the player's real y position is over
-       ; a certain value we should scroll the map
-       ; if scrolling is allowed
-player_try_scroll_up:
-       ; do not scroll if the scroll timer is enabled
+       ; sets scroll unless scroll is diabled
+player_set_scroll:
+       ; scroll can still be allowed to complete the next tile
+       ; even if the scroll disable object is loaded
        ld a, [scroll_timer]
-       cp a, 0
-       ret nz
+       cp a, MAP_ROW_H-1
+       jr z, @scroll_anyway REL
 
        ld a, [game_flags]
        and a, GPF_NO_SCROLL
-       ret nz ; no scroll allowed for now
+       ret nz
+
+@scroll_anyway:
+       ld a, [game_flags]
+       or a, GPF_SCROLL
+       ld [game_flags], a
+       ret
        
+       ; if the player's real y position is over
+       ; a certain value we should scroll the map
+       ; if scrolling is allowed
+player_try_scroll_up:
        ld a, [player_next_scroll_y]
        ld b, a 
        ld a, [player+act_pos_y]
        cp a, b
        jp nc, @no_scroll
 
-               ld a, [game_flags]
-               or a, GPF_SCROLL
-               ld [game_flags], a
+               call player_set_scroll
                
                ; run next objects
                ; so they are loaded before a move is attempted
index 9ae0149a711acb8c83f00fa0f87f5726990c44bf..d44be69f6cec34f3ae32bd917fc71ed48c2b9b38 100644 (file)
@@ -5,7 +5,6 @@ update_game:
   ; tick rng every frame
   call rand
 
-       
        call video_map_adjust_scroll
 
        call player_draw
index 833dafbcd1613c5306ee95e218ca3293d89b9cf9..7e5646bd325e5fe7cb309a906a518bbb4507767e 100644 (file)
@@ -38,29 +38,31 @@ vblank:
        ; loads a new map row and sets the scroll
        ; timer
 video_map_perform_scroll:
-       ld a, [game_flags]
-       and a, GPF_SCROLL
-       ret z
+       ld a, [scroll_timer]
+       cp a, MAP_ROW_H-1 
+       ret nz
 
-       call map_advance_row
+       xor a, a
+       ld [scroll_timer], a
 
-       ; unset flag
-       ld a, [game_flags]
-       and a, ~GPF_SCROLL & 0xFF
-       ld [game_flags], a
+       call map_advance_row
 
-       ld a, MAP_ROW_H 
-       ld [scroll_timer], a
        ret
        
        ; adjusts the scroll slowly 1 pixel each frame
        ; until the timer reaches 0
 video_map_adjust_scroll:
-       ld a, [scroll_timer]
-       cp a, 0
+       ld a, [game_flags]
+       and a, GPF_SCROLL
        ret z
 
-       dec a
+       ; unset flag
+       ld a, [game_flags]
+       and a, ~GPF_SCROLL & 0xFF
+       ld [game_flags], a
+       
+       ld a, [scroll_timer]
+       inc a
        ld [scroll_timer], a
 
        ld a, [scroll_y]