.def int PLAYER_TILE_IDLE2 = 0x1E
.def int PLAYER_TILE_IDLE3 = 0x2E
+#define DAMAGE_ANIM_LEN 20
+
; init the player
; inputs:
; hl: pointer to player memory
; hl = player_x right now
inc hl
inc hl ; hl = player_hp
- call player_use_resource
+ call player_take_damage
; call for UI redraw
ld a, UI_REDRAW_HP
ld [ui_flags], a
@skip:
ret
+ ; same as use_resource but specifically
+ ; also starts a damage animation
+player_take_damage:
+ ld [tmp], a
+ ld a, DAMAGE_ANIM_LEN
+ ld [damage_anim], a
+ ld a, [tmp]
+ jp player_use_resource
+
; gains a resource such as
; hp, mp, atk, or def up to max
; inputs:
-; vblank handler
+#define BGP 0b11100100
+
+ ; vblank handler
vblank:
; dma previous frame's oam
call OAMDMAFN
; get inputs
call poll_inputs
-
+
+ ; check if damage animation is active
+ ld a, [damage_anim]
+ cp a, 0
+ jr z, @no_damage_taken REL
+
+ ; damage was taken
+ ; damage_anim--
+ dec a
+ ld [damage_anim], a
+ cp a, 0
+ jr z, @restore_bgp REL
+
+ ; play animation by scrambling palette
+ ld a, BGP
+ rlc a
+ ld [RBGP], a
+ ret ; do not update rest
+@restore_bgp:
+ ; restore original bgp
+ ld a, BGP
+ ld [RBGP], a
+ ret ; return for one more frame
+@no_damage_taken:
call ui_draw
ld a, 1
; set up bgp
- ld a, 0b11100100
+ ld a, BGP
ld [RBGP], a
ld a, 0b11100100
player: .adv player_size
+ ; play a damage animation
+ ; until this value is 0
+ ; pause all other update execution until then
+damage_anim: .adv 1
+
; struct map
.se 0
.de map_size, 0