actor: Added code for allowing actors to set RF_ACTOR
authorLukas Krickl <lukas@krickl.dev>
Mon, 13 Jan 2025 08:36:44 +0000 (09:36 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 13 Jan 2025 08:36:44 +0000 (09:36 +0100)
This seems to still be a bit broken, but actors are now setting up their
room flags when they move.

src/actor.s

index 0c094ce00807b54b4889d5c9d405913e93096195..ebb345674a0773b026e3ba36752f0784ba440e73 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 
+  ld a, RF_WALL | RF_DOOR | RF_ACTOR
   call room_get_flag_masked
 
   pop bc
@@ -182,7 +182,39 @@ actor_anim_verify:
   ; returns:
   ;   sets the RF_ACTOR flag at target_y/x 
   ;   unsets RF_ACTOR at [bc] and [bc+1]
+  ; preserves registers
 actor_tile_update_flag:
+  push_all 
+  
+  ; first unset existing flags
+
+  inc bc ; bc = y pos
+  ld a, [bc]
+  ld d, a ; d = y pos
+  inc bc ; bc = x pos
+  ld a, [bc]
+  ld e, a ; e = x pos
+  call room_get_flag_ptr
+
+  ; unset flag
+  ld a, [hl]
+  and a, 0xFF ^ RF_ACTOR
+  ld [hl], a
+  
+
+  ; then set the new position's flag 
+  ld a, [anim_target_y]
+  ld d, a ; d = y pos
+  ld a, [anim_target_x]
+  ld e, a ; e = x pos
+  call room_get_flag_ptr
+
+  ; set flag
+  ld a, [hl]
+  or a, RF_ACTOR
+  ld [hl], a 
+
+  pop_all
   ret
 
 ; function ptrs for each actor type 
@@ -247,6 +279,8 @@ actor_update_bat:
 
   ; check anim collision
   call actor_anim_verify
+  ; set flags on z
+  call z, actor_tile_update_flag
 
   turn_finish