From: Lukas Krickl Date: Wed, 19 Mar 2025 21:48:27 +0000 (+0100) Subject: cursor: working on aborting cursor move and scroll when reaching the X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=refs%2Fremotes%2Forigin%2Fscope-change;p=gbrg%2F.git cursor: working on aborting cursor move and scroll when reaching the edge of the map --- diff --git a/src/macros.inc b/src/macros.inc index 690a0c2..970075e 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -84,10 +84,13 @@ ; $1: add/sub ; $2: scroll_move_y/x ; uses: a + ; skipped if z flag is 1 #macro cursor_adjust_scroll +.beginscope ld a, [$2] $1 a, 1 ld [$2], a +.endscope #endmacro ; move cursor @@ -103,3 +106,4 @@ ld a, CURSOR_MOVE_SPEED * $3 ld [$1], a #endmacro + diff --git a/src/player.s b/src/player.s index 0a4ac40..6ac76f4 100644 --- a/src/player.s +++ b/src/player.s @@ -61,6 +61,8 @@ handle_inputs: cursor_move_direction cursor_move_y, cursor_move_x, 1 + ld a, [cursor_y] + cp a, 0 ; adjust scroll cursor_adjust_scroll add, scroll_move_y @@ -72,6 +74,8 @@ handle_inputs: cursor_move_direction cursor_move_y, cursor_move_x, NEGATE + ld a, [cursor_y] + cp a, 0 ; adjust scroll cursor_adjust_scroll sub, scroll_move_y @@ -83,8 +87,12 @@ handle_inputs: cursor_move_direction cursor_move_x, cursor_move_y, NEGATE + ld a, [cursor_x] + cp a, 0 ; adjust scroll cursor_adjust_scroll sub, scroll_move_x + + call z, cursor_abort_move ret @notleft: @@ -94,6 +102,8 @@ handle_inputs: cursor_move_direction cursor_move_x, cursor_move_y, 1 + ld a, [cursor_x] + cp a, 0 ; adjust scroll cursor_adjust_scroll add, scroll_move_x @@ -125,3 +135,10 @@ cursor_move: pop af ret + + ; aborts cursor move + ; uses: a +cursor_abort_move: + xor a, a + ld [cursor_move_timer], a + ret