From: Lukas Krickl Date: Sat, 4 Oct 2025 19:20:57 +0000 (+0200) Subject: video: scrolls now happen on a per-pixel basis X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=52c80b0095031e2230286924f127698655aef557;p=gbrg%2F.git video: scrolls now happen on a per-pixel basis map objects and draws happen every 16th scroll. --- diff --git a/src/player.s b/src/player.s index 5e751d3..b020e47 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/update.s b/src/update.s index 9ae0149..d44be69 100644 --- a/src/update.s +++ b/src/update.s @@ -5,7 +5,6 @@ update_game: ; tick rng every frame call rand - call video_map_adjust_scroll call player_draw diff --git a/src/video.s b/src/video.s index 833dafb..7e5646b 100644 --- a/src/video.s +++ b/src/video.s @@ -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]