map: wip map scrolling
authorLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 11:40:45 +0000 (13:40 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 11:40:45 +0000 (13:40 +0200)
src/defs.s
src/player.s
src/video.s
src/wram.s

index ae493a7e2f468c8c696b4d1154e3ff476d252612..319a96b37c2c9c6e31b9131faa583aa3b11c4af8 100644 (file)
@@ -17,6 +17,8 @@
 #define MAP_OBJ_MAX 32
 #define RECT_MAX 32
 
+#define MAP_ROW_H 16 ; pixels per row
+
 #define STACK_BEGIN 0xDFFF
 
   ; seed for the rng
 .de r_h, 1
 .de r_w, 1
 .de r_size, 0
+
+
+       ; gameplay control flags
+.se 1
+.de GPF_NO_SCROLL, 1
+       ; scroll a row up next vblank
+.de GPF_SCROLL, 2
index 31e966c394e729a88d2bbe48aac48ad6e8ff51ea..e0eb4f5d3975c5bcf9f4f82ff82a81f1a5643c42 100644 (file)
@@ -10,6 +10,9 @@ player_init:
 
        ld a, 0 
        ld [player+act_pos_y_hi], a
+
+       ld a, 0xA0 ; initial next scroll
+       ld [player_next_scroll_y], a
        ret
        
        ; updates the special player actor
@@ -21,6 +24,7 @@ player_update:
                ld c, 0
                call player_stage_move_n
                call player_try_move
+               call player_try_scroll_up
 @not_up:
 
        ld b, BTNDOWN
@@ -56,6 +60,30 @@ 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
+       ; inputs:
+       ;               player setp up counter
+player_try_scroll_up:
+       ld a, [game_flags]
+       and a, GPF_NO_SCROLL
+       ret nz ; no scroll allowed for now
+       
+       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
+
+       
+@no_scroll:
+       ret
+       
        ; stages a move in a positive directon
        ; inputs:
        ;               b/c: y/x movement
index 82a8cda4ae40254c4bac783bf4b928ae79e5e052..7a223904c2f25316f26d08ea0f5aa7a8d6804183 100644 (file)
@@ -14,6 +14,8 @@ vblank:
   ; dma previous frame's oam
   call OAMDMAFN
 
+       call video_map_perform_scroll
+
   call scroll_write
   
   ; get inputs 
@@ -23,6 +25,28 @@ vblank:
   ld [frame_ready], a
   pop_all
   ret
+       
+       ; scrolls if the flag is set
+video_map_perform_scroll:
+       ld a, [game_flags]
+       and a, GPF_SCROLL
+       ret z
+
+       ld a, [scroll_y]
+       sub a, MAP_ROW_H
+       ld [scroll_y], a
+
+       ld a, [player_next_scroll_y]
+       sub a, MAP_ROW_H
+       ld [player_next_scroll_y], a
+       
+       call map_advance_row
+
+       ; unset flag
+       ld a, [game_flags]
+       and a, ~GPF_SCROLL & 0xFF
+       ld [game_flags], a
+       ret
 
 
   ; writes scroll to scroll registers
index c26d6ddd11996f3183ac326e6dd4c8e07fc06f88..adb6125f0de1502bbc207849db1ba98f54d3fc58 100644 (file)
@@ -39,6 +39,9 @@ vblank_jp: .adv 4
   ; of the input list
   ; if set to NULL do not read from this address
 demo_inputs: .adv 2
+       
+       ; gameplay control flags
+game_flags: .adv 1
 
 ; dummy oam 
 ; same memory as empty_unit
@@ -53,6 +56,10 @@ scroll_x: .adv 1
   ; 16 bit srand seed
   ; seed must never be 0
 srand: .adv 2
+       
+       ; if player y < next_scroll
+       ; advance if possible
+player_next_scroll_y: .adv 1
 
 
 player: .adv act_size