actor: Fixed actor tile flagging
authorLukas Krickl <lukas@krickl.dev>
Tue, 14 Jan 2025 20:42:57 +0000 (21:42 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 14 Jan 2025 20:42:57 +0000 (21:42 +0100)
Actors now flag the correct tile, but they will unflag during their next
turn. This means that collision is till broken, but less broken than
before :^)

The actors flagged the wrong tile due to a missing offset for the target
position.

src/actor.s
src/map.s
src/player.s

index ebb345674a0773b026e3ba36752f0784ba440e73..a8b63ec221db32413989273ebf839a1c8ad3a12d 100644 (file)
@@ -183,16 +183,20 @@ actor_anim_verify:
   ;   sets the RF_ACTOR flag at target_y/x 
   ;   unsets RF_ACTOR at [bc] and [bc+1]
   ; preserves registers
-actor_tile_update_flag:
+actor_tile_update_rf_flags:
   push_all 
   
   ; first unset existing flags
 
+  ; add +8 to positions to center on tile
+
   inc bc ; bc = y pos
   ld a, [bc]
+  sub a, ANIM_MOVE_TILE_SIZE / 2 ; -8 to be in center
   ld d, a ; d = y pos
   inc bc ; bc = x pos
   ld a, [bc]
+  sub a, ANIM_MOVE_TILE_SIZE / 2 ; -8 to be in center
   ld e, a ; e = x pos
   call room_get_flag_ptr
 
@@ -204,8 +208,10 @@ actor_tile_update_flag:
 
   ; then set the new position's flag 
   ld a, [anim_target_y]
+  sub a, ANIM_MOVE_TILE_SIZE / 2 ; -8 to be in center
   ld d, a ; d = y pos
   ld a, [anim_target_x]
+  sub a, ANIM_MOVE_TILE_SIZE / 2 ; -8 to be in center
   ld e, a ; e = x pos
   call room_get_flag_ptr
 
@@ -280,7 +286,7 @@ actor_update_bat:
   ; check anim collision
   call actor_anim_verify
   ; set flags on z
-  call z, actor_tile_update_flag
+  call z, actor_tile_update_rf_flags
 
   turn_finish
 
index 9b96ef96513b0915855edf91f34faf4d3aa83bce..1c0a7692ef1307e0ef1f0c478bc7f8791ab66f03 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -435,7 +435,6 @@ room_get_flag_ptr:
   ;     d : y pos 
   ;     e : x pos
   ;     a: mask
-  ; ct_mask: bit mask for flag to check (tile & mask)
   ; returns:
   ;   a: masked flag
   ;   z-flag is set
index fd75f7be85c449fcc420ca0ea2dc3c239a84bb31..ab233d78513c1006d56cc13da522d040fb4076a5 100644 (file)
@@ -255,14 +255,24 @@ player_update:
   
 
 @no_door_hit:
+
+  ld a, h ; restore original a for next check
+  and a, RF_ACTOR
+  jr z, @no_enemy_hit REL
+
+  ; TODO add enemy hit logic 
+
+@no_enemy_hit:
+
   ld a, h ; restore original a for next check  
-  and a, RF_WALL
+  and a, RF_WALL | RF_ACTOR
   pop hl
   
   jr z, @no_collision REL
     ; clear anim memory
     call anim_clear 
 @no_collision:
+  
 
 @skip_input:
   ; hl should be player_y here