#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
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
ld c, 0
call player_stage_move_n
call player_try_move
+ call player_try_scroll_up
@not_up:
ld b, BTNDOWN
#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
; dma previous frame's oam
call OAMDMAFN
+ call video_map_perform_scroll
+
call scroll_write
; get inputs
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
; 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
; 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