.def int CURSOR_TILE = 0x04
+#define CURSOR_MOVE_TIMER TILE_SIZE
+#define CURSOR_MOVE_SPEED 1
; init the player
player_init:
; hl: pointer to player memory
player_update:
+ ; check cursor movement
+ ld a, [cursor_move_timer]
+ cp a, 0
+ call nz, cursor_move
+ call z, handle_inputs
+
+
@draw_cursor:
; draw cursor
ret
+handle_inputs:
+ input_held BTNDOWN
+ jr z, @notdown REL
+
+ xor a, a
+ ld [cursor_move_x], a
+ ld a, CURSOR_MOVE_TIMER
+ ld [cursor_move_timer], a
+ ld a, CURSOR_MOVE_SPEED
+ ld [cursor_move_y], a
+ ret
+@notdown:
+
+ input_held BTNUP
+ jr z, @notup REL
+
+ xor a, a
+ ld [cursor_move_x], a
+ ld a, CURSOR_MOVE_TIMER
+ ld [cursor_move_timer], a
+ ld a, CURSOR_MOVE_SPEED * NEGATE
+ ld [cursor_move_y], a
+ ret
+@notup:
+
+ input_held BTNLEFT
+ jr z, @notleft REL
+
+ xor a, a
+ ld [cursor_move_y], a
+ ld a, CURSOR_MOVE_TIMER
+ ld [cursor_move_timer], a
+ ld a, CURSOR_MOVE_SPEED * NEGATE
+ ld [cursor_move_x], a
+ ret
+@notleft:
+
+ input_held BTNRIGHT
+ jr z, @notright REL
+
+ xor a, a
+ ld [cursor_move_y], a
+ ld a, CURSOR_MOVE_TIMER
+ ld [cursor_move_timer], a
+ ld a, CURSOR_MOVE_SPEED
+ ld [cursor_move_x], a
+@notright:
+
+ ret
+
+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]
+ dec a
+ ld [hl], a
+
+ pop af
+ ret