From f03952513a84db555fb0df32c661ff936210c106 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 20 Mar 2025 19:51:28 +0100 Subject: [PATCH] cursor: working on making cursor movement better Mostly trying to improvie cursor sprite positoning when scrolling. --- src/player.s | 49 ++++++++++++++++++++++++------------------------- src/update.s | 2 ++ src/video.s | 7 ++++++- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/player.s b/src/player.s index 2587b2c..1dd2db9 100644 --- a/src/player.s +++ b/src/player.s @@ -4,7 +4,7 @@ .def int CURSOR_TILE = 0x04 #define CURSOR_MOVE_TIMER TILE_SIZE -#define CURSOR_MOVE_SPEED 1 +#define CURSOR_MOVE_SPEED 8 ; init the player player_init: @@ -112,32 +112,31 @@ handle_inputs: cursor_move: push af - ld hl, cursor - ; hl = cursor_y - - ld b, [hl] - ld a, [cursor_move_y] - add a, b - ld [cursor_y], a - - ; hl = cursor_x - inc hl - ld b, [hl] - ld a, [cursor_move_x] - add a, b - ld [cursor_x], a - inc hl ; hl = cursor_move_timer - - ld a, [hl] + + + ld a, [cursor_move_timer] dec a - ld [hl], a + ld [cursor_move_timer], a + cp a, 0 + jr nz, @done REL + + ; if timer is 0 apply movement + ; and jump to next tile + ld a, [cursor_y] + ld b, a + + ld a, [cursor_move_y] + add a, b + ld [cursor_y], a + ld a, [cursor_x] + ld b, a + + ld a, [cursor_move_x] + add a, b + ld [cursor_x], a + +@done: pop af ret - ; aborts cursor move - ; uses: a -cursor_abort_move: - xor a, a - ld [cursor_move_timer], a - ret diff --git a/src/update.s b/src/update.s index 06751b8..fc5831d 100644 --- a/src/update.s +++ b/src/update.s @@ -13,6 +13,8 @@ update_game: call player_update call sim_update + + call scroll_update ret diff --git a/src/video.s b/src/video.s index f288585..d9ad061 100644 --- a/src/video.s +++ b/src/video.s @@ -9,7 +9,7 @@ vblank: call poll_inputs call ui_draw - call scroll_update + call scroll_write ld a, 1 ld [frame_ready], a @@ -77,6 +77,11 @@ scroll_update: ld [scroll_x], a @no_scroll_left: @done: + ret + + ; writes scroll to scroll registers + ; only call during blank +scroll_write: ld a, [scroll_y] ld [RSCY], a -- 2.30.2