Added slight pause every time damage is taken
authorLukas Krickl <lukas@krickl.dev>
Mon, 7 Oct 2024 16:09:57 +0000 (18:09 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 7 Oct 2024 16:09:57 +0000 (18:09 +0200)
- This allows the player to adjust to a damage source
- Added clear indication that damage was taken

src/player.s
src/video.s
src/wram.s

index d77d0a081440a89b1a3f28d66060a9718092c819..8a96dc21533509ad3cb2ae75027775e81c52ec5c 100644 (file)
@@ -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:
index 7aea143a19447fc303976303720bf6edb9b51e4b..6ca5cff0db08cb4751936a876e888e9a118412e1 100644 (file)
@@ -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 
index 8ca371e4b40432e6f09c22d48cd7a9df940c40ac..8026d8d521e6db5b4f6916e5108861d7692042b8 100644 (file)
@@ -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