; updates the special player actor
player_update:
call scroll_center_player
+
+ call player_inputs
+ call player_handle_move
+ ret
+
+ ; shcedules a player move
+player_inputs:
+ ; no direction inputs if timer is > 0
+ ld a, [player_move_timer]
+ cp a, 0
+ ret nz
+
+ ld b, BTNUP
+ input_held
+ jr z, @notup REL
+ ld a, DIRUP
+ jp @set
+@notup:
- call move_cursor
+ ld b, BTNDOWN
+ input_held
+ jr z, @notdown REL
+ ld a, DIRDOWN
+ jp @set
+@notdown:
+
+ ld b, BTNLEFT
+ input_held
+ jr z, @notleft REL
+ ld a, DIRLEFT
+ jp @set
+@notleft:
+
+ ld b, BTNRIGHT
+ input_held
+ jr z, @notright REL
+ ld a, DIRRIGHT
+ jp @set
+@notright:
ret
+@set:
+ ld [player_direction], a
+ ld a, 16 ; tile size
+ ld [player_move_timer], a
+ ret
+
; moves the player cursor
; does not move out of bounds
-move_cursor:
- ld b, BTNDOWN
- input_held
+ ; based on the last queued input
+player_handle_move:
+ ; remove 1 from timer
+ ld a, [player_move_timer]
+ cp a, 0
+ ret z
+ dec a
+ ld [player_move_timer], a
+
+ ld a, [player_direction]
+ and a, BTNDOWN
jr z, @not_down REL
ld a, [player+act_pos_y]
cp a, 0xF0 ; max value
ld [player+act_pos_y], a
@not_down:
- ld b, BTNUP
- input_held
+ ld a, [player_direction]
+ and a, BTNUP
jr z, @not_up REL
ld a, [player+act_pos_y]
cp a, 0 ; min value
ld [player+act_pos_y], a
@not_up:
- ld b, BTNLEFT
- input_held
+ ld a, [player_direction]
+ and a, BTNLEFT
jr z, @not_left REL
ld a, [player+act_pos_x]
cp a, 0 ; min value
ld [player+act_pos_x], a
@not_left:
- ld b, BTNRIGHT
- input_held
+ ld a, [player_direction]
+ and a, BTNRIGHT
jr z, @not_right REL
ld a, [player+act_pos_x]
cp a, 0xF0 ; max value
; seed must never be 0
srand: .adv 2
+ ; player combtat stats
+player_cb: .adv act_cb_size
+ ; stores the last move direction
+player_direction: .adv 1
+player_move_timer: .adv 1
actors:
player: .adv act_size