From: Lukas Krickl Date: Sat, 22 Mar 2025 17:36:30 +0000 (+0100) Subject: WIP: working on aborting moves when they would wrap map X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=8e438246ee494e3d878a73a14214e9b2f6cb2219;p=gbrg%2F.git WIP: working on aborting moves when they would wrap map --- diff --git a/src/defs.s b/src/defs.s index 87c53dd..5b79f65 100644 --- a/src/defs.s +++ b/src/defs.s @@ -63,3 +63,9 @@ .de CT_NONE, 1 .de CT_GROUND, 1 .de CT_WATER, 1 + + ; defines end of scroll location +#define CURSOR_MIN_X 0 +#define CURSOR_MAX_X 0 +#define CURSOR_MIN_Y 0 +#define CURSOR_MAX_Y 0 diff --git a/src/player.s b/src/player.s index bdb5f2a..b06eff9 100644 --- a/src/player.s +++ b/src/player.s @@ -122,6 +122,8 @@ cursor_move: ; if timer is 0 apply movement ; and jump to next tile + call try_abort_move + ld a, [cursor_y] ld b, a @@ -141,3 +143,33 @@ cursor_move: pop af ret +try_abort_move: + ld b, CURSOR_MIN_X + ld c, CURSOR_MOVE_SPEED * NEGATE + ld hl, cursor_x + ld de, cursor_move_x + call try_abort_move_at + + ret + + ; aborts a move direciton + ; inputs: + ; b: compare variable (e.g. min or max value) + ; c: move direction compare value (e.g. move + or -) + ; hl: position ptr + ; de: move variable to set to 0 +try_abort_move_at: + ; do not abort if position is wrong + ld a, [hl] + cp a, b + ret nz + + ; do not abort if direction is wrong + ld a, [de] + cp a, c + ret nz + + xor a, a + ld [de], a + + ret diff --git a/src/video.s b/src/video.s index 94019ff..a7c1e62 100644 --- a/src/video.s +++ b/src/video.s @@ -28,6 +28,7 @@ vblank: ret ; updates scroll based on scroll_move_y/x + ; do nothing if scroll would move oob scroll_update: ld a, [cursor_move_timer] cp a, 0