-
+#define ACTION_ATTACK_SPRITE1 0xA0
+#define UNIT_ACTION_ATTACK_ANIM_LEN 16
+
; sets up default actions for a new game
; for button A and button B
actions_new_game_init:
; bc: null if no press
; bc: unit_switch_to_active -> B pressed
; bc: bc input -> direction pressed
- ; act_rt_action_tmp: writes pressed bit BTNUP, BTNDOWN, BTNLEFT, BTNRIGHT
+ ; act_rt_action_dat1: writes pressed bit BTNUP, BTNDOWN, BTNLEFT, BTNRIGHT
+ ; act_rt_action_dat2: set to 0
unit_action_pick_direction:
- ld hl, act_rt_action_tmp
+ ld hl, act_rt_action_dat1
add hl, de ; hl = act_rt_action
; save next state
ret
@direction_pressed:
ld a, b
- ld [hl], a ; write pressed button to action tmp
+ ld [hl+], a ; write pressed button to action dat
+ xor a, a
+ ; clear dat2
+ ld [hl], a
+
+ call ui_status_line_clear
+
; should contain next state
pop bc
ret
-
; performs an attack
; based on the units rt_action tmp value
; inputs:
; de: unit
; returns:
; bc: next action
-unit_action_attack:
- call ui_status_line_clear
+unit_action_attack:
+ push de
+ ; get location
+ call unit_get_pos
+
+ ld de, act_rt_action_dat1
+ add hl, de
+ ; TODO determine where to draw animation
+ ld a, [hl] ; a = direction pressed
+
+ ; draw a slash animation at that location
+ push bc
+ call load_unit_obj
+ call load_scroll
+ push bc
+ pop de ; de = scroll
+ pop bc ; bc = pos
+ ; hl = obj
+ ; write position
+ ld a, b ; y position
+ tile_to_scrn OBJ_OFF_Y, d
+ ld [hl+], a ; y position
+
+ ld a, c ; x position
+ tile_to_scrn OBJ_OFF_X, e
+ ld [hl+], a ; x position
+
+ ; write tile
+ ld a, ACTION_ATTACK_SPRITE1
+ ld [hl+], a
+
+ ; clear flags
+ xor a, a
+ ld [hl], a
+
+
+ ; check anim length
+ pop de
+ ld hl, act_rt_action_dat2 ; dat2 = animation frame count
+ add hl, de
+ ld a, [hl]
+ inc a
+ ld [hl], a
+ cp a, UNIT_ACTION_ATTACK_ANIM_LEN
+ jr z, @done REL
+
+ ; TODO: on frame 0 perform attack action
+
+ ; otherwsie keep going
+ ldnull bc
+ ret
+
+@done:
+ ; set animation timer and delay
ld bc, st_unit_delay_to_active_template
ret
; set during unit_collision_woth_any_other
.de act_rt_collided_with, 2
; temporary buffer for any action picked
-.de act_rt_action_tmp, 1
+.de act_rt_action_dat1, 1
+.de act_rt_action_dat2, 1
; sub-tile drawing vars
; during this animation the actor is already technically in its new