From: Lukas Krickl Date: Mon, 7 Oct 2024 16:09:57 +0000 (+0200) Subject: Added slight pause every time damage is taken X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=e8b2a71870feeeb47e78543f40cfcafab06bba12;p=gbrg%2F.git Added slight pause every time damage is taken - This allows the player to adjust to a damage source - Added clear indication that damage was taken --- diff --git a/src/player.s b/src/player.s index d77d0a0..8a96dc2 100644 --- a/src/player.s +++ b/src/player.s @@ -5,6 +5,8 @@ .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 @@ -109,7 +111,7 @@ player_update: ; 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 @@ -220,6 +222,15 @@ player_use_resource: @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: diff --git a/src/video.s b/src/video.s index 7aea143..6ca5cff 100644 --- a/src/video.s +++ b/src/video.s @@ -1,11 +1,36 @@ -; 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 @@ -56,7 +81,7 @@ video_init: ; set up bgp - ld a, 0b11100100 + ld a, BGP ld [RBGP], a ld a, 0b11100100 diff --git a/src/wram.s b/src/wram.s index 8ca371e..8026d8d 100644 --- a/src/wram.s +++ b/src/wram.s @@ -55,6 +55,11 @@ actor_table: .adv ACTORS_MAX * actor_size 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