push de
call unit_handle_inputs
pop de
+
+ push bc
+ call unit_demo_1_draw
+ pop bc
+ ret
; inputs
; de: actor
jr z, @notup REL
call unit_try_move_up
+ ld bc, st_unit_delay
+ ret
@notup:
+ input_held BTNDOWN
+ jr z, @notdown REL
+
+ call unit_try_move_down
+ ld bc, st_unit_delay
+ ret
+@notdown:
+
+ input_held BTNLEFT
+ jr z, @notleft REL
+
+ call unit_try_move_left
+ ld bc, st_unit_delay
+ ret
+@notleft:
+
+ input_held BTNRIGHT
+ jr z, @notright REL
+
+ call unit_try_move_right
+ ld bc, st_unit_delay
+ ret
+@notright:
+
ldnull bc
ret
; actor initiative based on tile flags
; actor position
unit_try_move_up:
+ ld hl, act_pos_y
+ add hl, de
+ ; hl = actor y
+ ld a, [hl]
+ dec a
+ ld [hl], a
+
+ ret
+
+unit_try_move_down:
+ ld hl, act_pos_y
+ add hl, de
+ ; hl = actor y
+ ld a, [hl]
+ inc a
+ ld [hl], a
+ ret
+
+unit_try_move_left:
+ ld hl, act_pos_x
+ add hl, de
+ ; hl = actor x
+ ld a, [hl]
+ dec a
+ ld [hl], a
+ ret
+
+unit_try_move_right:
+ ld hl, act_pos_x
+ add hl, de
+ ; hl = actor x
+ ld a, [hl]
+ inc a
+ ld [hl], a
ret
; centers the current scroll on the selected unit
; de: actor
unit_scroll_center:
ret
+
+ ; switches a unit to active state
+ ; inputs:
+ ; de: unit
+unit_switch_to_active:
+ ld hl, act_st_active
+ add hl, de ; hl = st_active ptr
+ ld a, [hl+]
+ ld c, a
+ ld a, [hl]
+ ld b, a
+
+ ; bc = next active state
+
+ ret
unit_demo_1:
st_def 0x00, unit_demo_1_init, st_unit_demo_1_update
act_def ACT_T_DEMO_1, 0, 1, 1, 1, 1, 1, 2, 2, 0
- act_st_def NULL, st_unit_demo_1_update, NULL, NULL
+ act_st_def NULL, NULL, st_unit_demo_1_update, NULL
st_unit_demo_1_update:
st_def 0x00, unit_demo_1_update, st_unit_demo_1_update
+
+st_unit_delay:
+ st_def CURSOR_MOVE_TIMER, st_null_fn, st_unit_switch_to_active
+
+st_unit_switch_to_active:
+ st_def 0, unit_switch_to_active, st_unit_switch_to_active