Added simple flashing animation for iframes
authorLukas Krickl <lukas@krickl.dev>
Tue, 8 Oct 2024 15:05:36 +0000 (17:05 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 8 Oct 2024 15:05:36 +0000 (17:05 +0200)
src/player.s

index bc8d1e603117449dc085f03aeadd817f5a41f608..3b39871e37b07ec4473adb4b6ea92b6bc366168b 100644 (file)
@@ -5,7 +5,7 @@
 .def int PLAYER_TILE_IDLE2 = 0x1E
 .def int PLAYER_TILE_IDLE3 = 0x2E
 
-#define PLAYER_IFRAME_TIMER 8
+#define PLAYER_IFRAME_TIMER 64
 #define DAMAGE_ANIM_LEN 20
 
   ; init the player 
@@ -55,10 +55,6 @@ player_update:
   ; e: player_x
   ; b: obj flags mask
   
-  ; set up obj flag mask based on frame counter 
-  ld a, [frame_count]
-  and a, 4
-  ld b, 0 
 
   ; input handling
   input_held BTNDOWN
@@ -137,12 +133,56 @@ player_update:
   pop hl
 
 @notb:
-
-  ; drawing 
-
   ; sotre x in e
   ld a, [hl]
   ld e, a
+  
+  ; hl is ok to use again
+  ; bc is free
+  ; de is still used
+
+  ; check if i-frame 
+  ; if iframe is divisible by 2
+  ; flash all sprites off
+  ; otherwise continue with regular code
+  ; hl = player_x
+  dec hl ; hl = player_y = player start 
+  ld bc, player_timer_i
+  add hl, bc ; hl = timer now
+  ld a, [hl] 
+  cp a, 0
+  jr z, @draw_visible REL
+  
+  dec a
+  ld [hl], a ; timer--
+  inc a
+
+  and a, 4 ; blink every 4 frames
+  jr z, @draw_visible REL
+
+@hide_player:
+  
+  ; hide 3 player sprites 
+  ld a, 0
+  ld hl, PLAYER_SPRITE1
+  ld [hl+], a
+  ld [hl+], a
+  ld hl, PLAYER_SPRITE1+4 
+  ld [hl+], a
+  ld [hl+], a
+  ld hl, PLAYER_SPRITE1+8
+  ld [hl+], a
+  ld [hl+], a
+
+  ret
+@draw_visible:
+  ; drawing 
+
+  ; set up obj flag mask based on frame counter 
+  ; b is now not free anymore!
+  ld a, [frame_count]
+  and a, 4
+  ld b, 0
 
   ; obj 1
   ld hl, PLAYER_SPRITE1