actor: moved rf flag setter to a macro
authorLukas Krickl <lukas@krickl.dev>
Sat, 18 Jan 2025 05:58:24 +0000 (06:58 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 18 Jan 2025 05:58:24 +0000 (06:58 +0100)
This allows it to also be used as a copy-paste for palyer flag purposes.

src/actor.s
src/player.s
src/wram.s

index 9d5e1e4975936b02afc45c82013f6c23ea1fbbff..b65d3772958f02a4608328e9b11073f2652bcc63 100644 (file)
@@ -162,7 +162,7 @@ actor_anim_verify:
   ld a, [anim_target_x]
   sub a, ANIM_MOVE_TILE_SIZE / 2 ; -8 to be in center
   ld e, a
-  ld a, RF_WALL | RF_DOOR | RF_ACTOR
+  ld a, RF_WALL | RF_DOOR | RF_ACTOR | RF_PLAYER
   call room_get_flag_masked
 
   pop bc
@@ -181,33 +181,17 @@ actor_anim_verify:
   ;   hl: trunacted y/x
 anim_truncate_pos:
   ret
-
-  ; same as actor_tile_update_rf_flags 
-  ; but decs hl before calling and 
-  ; increments again after 
-player_tile_update_rf_flags:
-  dec hl
-  call actor_tile_update_rf_flags 
-  inc hl
-  ret
-
-  ; marks the current actor's tile 
-  ; as occupied by an actor
-  ; also removes the flag from the actor's current tile 
-  ; this only works for the default case of 
-  ; an acotr needing a single tile.
+  
+  ; macro version of actor_tile_update_rf_flag
   ; inputs:
-  ;   bc: (actor ptr) original y/x position ptr
+  ;   $1: RF FLAG to set / unset 
+  ;   bc: original y/x position ptr
   ;  anim_target_y/x: target position
   ; returns:
-  ;   sets the RF_ACTOR flag at target_y/x 
-  ;   unsets RF_ACTOR at [bc] and [bc+1]
+  ;   sets the $1 flag at target_y/x 
+  ;   unsets $1 at [bc] and [bc+1]
   ; preserves registers
-actor_tile_update_rf_flags:
-  push_all 
-  
-  inc bc ; bc = y pos
-
+#macro update_rf_flag
   ; first unset existing flags
 
   ; sub 8 to positions to center on tile
@@ -222,7 +206,7 @@ actor_tile_update_rf_flags:
 
   ; unset flag
   ld a, [hl]
-  and a, 0xFF ^ RF_ACTOR
+  and a, 0xFF ^ $1 
   ld [hl], a
   
 
@@ -237,10 +221,40 @@ actor_tile_update_rf_flags:
 
   ; set flag
   ld a, [hl]
-  or a, RF_ACTOR
+  or a, $1 
   ld [hl], a 
 
 @skip:
+#endmacro 
+
+  ; same as actor_tile_update_rf_flags 
+  ; but decs hl before calling and 
+  ; increments again after 
+player_tile_update_rf_flags:
+  push_all
+  update_rf_flag RF_PLAYER
+  pop_all
+  ret
+
+  ; marks the current actor's tile 
+  ; as occupied by an actor
+  ; also removes the flag from the actor's current tile 
+  ; this only works for the default case of 
+  ; an acotr needing a single tile.
+  ; inputs:
+  ;   bc: (actor ptr) original y/x position ptr
+  ;  anim_target_y/x: target position
+  ; returns:
+  ;   sets the RF_ACTOR flag at target_y/x 
+  ;   unsets RF_ACTOR at [bc] and [bc+1]
+  ; preserves registers
+actor_tile_update_rf_flags:
+  push_all 
+  
+  inc bc ; bc = y pos
+  
+  update_rf_flag RF_ACTOR
+
   pop_all
   ret
 
index ab233d78513c1006d56cc13da522d040fb4076a5..272ad92b5eb8054974108590641c612701c15cdb 100644 (file)
@@ -270,9 +270,10 @@ player_update:
   
   jr z, @no_collision REL
     ; clear anim memory
-    call anim_clear 
+    call anim_clear
+    jr @skip_input REL
 @no_collision:
-  
+  ; call z, player_tile_update_rf_flags 
 
 @skip_input:
   ; hl should be player_y here 
index d259311c0d96445ecf36be539170d59594966f5e..cc6c7afafe45b1808bfa0932c64be34ebea486d0 100644 (file)
@@ -130,6 +130,8 @@ damage_anim: .adv 1
   ; note: if RF_ACTOR is set the highest 4 bits of RF flags will
   ;       be set to the actor's id
 .de RF_ACTOR, 4
+  ; same as RF_ACTOR, but for the player 
+.de RF_PLAYER, 8 
 
   ; current room struct 
   ; same layout as room struct itself