attack: wip added attack animation
authorLukas Krickl <lukas@krickl.dev>
Sun, 17 Aug 2025 15:51:17 +0000 (17:51 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 17 Aug 2025 15:51:17 +0000 (17:51 +0200)
The location is still wrong but the basic idea is there :^)

src/action.s
src/defs.s
src/macros.inc
tiles/bank8800.inc

index 4ac3b491eb1d5e6f5f70189f395646cd126014d7..3b77df74bcc1d47bbdb3c3939e08b4336c496164 100644 (file)
@@ -1,4 +1,6 @@
-       
+#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:
@@ -68,9 +70,10 @@ unit_action_attack_pick_direction:
        ;               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
@@ -107,20 +110,77 @@ unit_action_pick_direction:
        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
 
index bf8d2d658a8d30149e55a7d8072bdaa24a9fd30c..a378c3016fc386306e0716dc90e1ea8f5fa01afd 100644 (file)
   ; 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 
index 6952a31a9da23b53fb57ce91f5f467469513fefb..808b29c625fdc14aef1a0f4b8e63281a39f373a0 100644 (file)
   .db 0  ; act_rt_sub_tile 
   ; act_rt_loot_table_dat
   dw 0
-       ; act_rt_action_tmp
-       .db 0
+       ; act_rt_action_dat1/2
+       .db 0, 0
 #endmacro
   
   ; defines an actor's stats (1/2)
index cf2b3b181a43e93fd6c72136e41baa19f98867e8..6c6010bb1b5ed610ba45fe3bdb8f87084b9f968c 100644 (file)
 ; tile 16
 .chr 00000000
 .chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 00300000
+.chr 03130000
+.chr 03213000
+.chr 00313000
+.chr 00321300
+.chr 00031300
+.chr 00032130
+.chr 00003130
+.chr 00003213
+.chr 00000313
+.chr 00000323
+.chr 00000030
 .chr 00000000
 .chr 00000000
 ; tile 17