+#define PLAYER_SPEED 1
+
; sets up the player actor
player_init:
; initial position
; updates the special player actor
player_update:
+ ld b, BTNUP
+ input_held
+ jr z, @not_up REL
+ ld b, PLAYER_SPEED
+ ld c, 0
+ call player_stage_move_n
+ call player_try_move
+@not_up:
+
+ ld b, BTNDOWN
+ input_held
+ jr z, @not_down REL
+ ld b, PLAYER_SPEED
+ ld c, 0
+ call player_stage_move_p
+ call player_try_move
+
+@not_down:
+
+ ld b, BTNLEFT
+ input_held
+ jr z, @not_left REL
+ ld b, 0
+ ld c, PLAYER_SPEED
+ call player_stage_move_n
+ call player_try_move
+@not_left:
+
+ ld b, BTNRIGHT
+ input_held
+ jr z, @not_right REL
+
+ ld b, 0
+ ld c, PLAYER_SPEED
+ call player_stage_move_p
+ call player_try_move
+@not_right:
+
ret
#define PLAYER_SPRITE_IDLE1 0x8D
+
+ ; stages a move in a positive directon
+ ; inputs:
+ ; b/c: y/x movement
+ ; returns:
+ ; b/c: new y/x position
+ ; d: new y hi position
+player_stage_move_p:
+ ld a, [player+act_pos_y]
+ add a, b
+ ld b, a
+
+ ld a, [player+act_pos_y_hi]
+ adc a, 0
+ ld [player+act_pos_y_hi], a
+ ld d, a
+
+ ld a, [player+act_pos_x]
+ add a, c
+ ld c, a
+
+ ret
+
+ ; stages a move in a negative directon
+ ; inputs:
+ ; b/c: y/x movement
+ ; returns:
+ ; b/c: new y/x position
+ ; d: new y hi position
+player_stage_move_n:
+ ld a, [player+act_pos_y]
+ sub a, b
+ ld b, a
+
+ ld a, [player+act_pos_y_hi]
+ sbc a, 0
+ ld [player+act_pos_y_hi], a
+ ld d, a
+
+ ld a, [player+act_pos_x]
+ sub a, c
+ ld c, a
+
+ ret
+
+ ; moves the player
+ ; performs a collision check
+ ; moves scroll and performs map loads if needed
+ ; inputs:
+ ; b/c: new y/x position
+ ; d: new y hi position
+player_try_move:
+ ld a, b
+ ld [player+act_pos_y], a
+
+ ld a, c
+ ld [player+act_pos_x], a
+
+ ld a, d
+ ld [player+act_pos_y_hi], a
+ ret
; draws the special player actor
player_draw: