collision: moved last cf flags y and x position for collision to actor
authorLukas Krickl <lukas@krickl.dev>
Mon, 11 Aug 2025 16:50:34 +0000 (18:50 +0200)
committerLukas Krickl <lukas@krickl.dev>
Mon, 11 Aug 2025 16:50:34 +0000 (18:50 +0200)
src/defs.s
src/macros.inc
src/objanim.s
src/player.s
src/unit.s
src/wram.s

index fa236356c3b52c54fc639fae7c6f32b90195ab92..d36597da1573b12d9ae4590639bb794a916c6b32 100644 (file)
 
   ; actor runtime values
 
-       ; last collision flags
-.de act_rt_collision_cf, 1
        ; last collision tile position
 .de act_rt_collision_pos_y, 1
 .de act_rt_collision_pos_x, 1
+       ; last collision flags
+.de act_rt_collision_cf, 1
   ; last collision with actor
   ; set during unit_collision_woth_any_other
 .de act_rt_collided_with, 2
index e3c25809dfc94ef47619d77f3136c16bfb6d77e5..0a75620613096e7b4a2d6e942c8b67badb5b6fe8 100644 (file)
   .db $4 ; x pos
   .db $5 ; p0
        
-       ; act rt collision cf, pos y, pos x
+       ; act rt pos y, pos x, collision cf
        .db 0, 0, 0
   ; act_rt_collided_with
   dw 0 
index c0a6736d4ef0ca12fff6e51638d1f84cd93e6645..5057a209d73753074f063118dd402ff3440179f7 100644 (file)
@@ -16,7 +16,6 @@ objanim_init:
        ; inputs:
        ;               a: tile flags
        ;               b: tile index
-       ;  unit_test_collision_pos_y/x
        ;        de: actor
 objanim_door_open:
        push de
@@ -28,17 +27,20 @@ objanim_door_open:
        pop bc
        pop de
 
+       ld hl, act_rt_collision_pos_y
+       add hl, de ; hl = col pos y
+
        ; clear flags
        ld de, objanim+obja_flags       
        xor a, a
        ld [de], a
        inc de ; de = y pos
        
-       ld a, [unit_test_collision_pos_y]
+       ld a, [hl+]
        ld [de], a
        inc de ; de = x pos
 
-       ld a, [unit_test_collision_pos_x]
+       ld a, [hl]
        ld [de], a
        inc de ; de = dat
        
index 3992e531821cfbcdff47f7f2daec904e95ed068f..89d5f6426a587618191e6954af9b4def7a91daef 100644 (file)
@@ -63,7 +63,11 @@ unit_player_update:
        push de
        push bc
        ; test last collision flags
-       ld a, [unit_test_collision_cf_flags]
+       push de
+       ld hl, act_rt_collision_cf
+       add hl, de
+       ld a, [hl]
+       pop de
        and a, CF_DOOR
        call nz, unit_player_remove_door
        pop bc
@@ -74,19 +78,22 @@ unit_player_update:
        ; removes the door tile the player is currently
        ; standing on
        ; inputs:
-       ;       unit_test_collision_pos_y/x 
        ;               de: actor
 unit_player_remove_door:
        ; get tile of last collision
-       ld a, [unit_test_collision_pos_y]
+       push de
+       ld hl, act_rt_collision_pos_y
+       add hl, de
+       ld a, [hl+] ; load y
        ld b, a
-       ld a, [unit_test_collision_pos_x]
+       ld a, [hl] ; load x
        ld c, a
        call map_get_tile
+       pop de
 
        ; schedule animation
        push_all
-       call objanim_door_open
+       call objanim_door_open
        pop_all
 
        ; remove door tile, door flag
@@ -96,8 +103,10 @@ unit_player_remove_door:
        ld [hl+], a
        ld a, CF_COVERED
        ld [hl], a
-
-       ld a, [unit_test_collision_pos_y] ; load y offset
+       
+       ld hl, act_rt_collision_pos_y
+       add hl, de
+       ld a, [hl] ; load y offset
        call map_request_redraw_at
 
        ret
index af77d7eba0ccf500882845288c1dab870d23b110..7537776b868d868aa1b312d1b5927aeab9040017 100644 (file)
@@ -357,24 +357,24 @@ unit_handle_inputs:
   $1 
 
        ; write y and x pos
+       ld hl, act_rt_collision_pos_y
+       add hl, de ; de = collision vars y pos
        ld a, b
-       ld [unit_test_collision_pos_y], a
+       ld [hl+], a ; write y
        ld a, c
-       ld [unit_test_collision_pos_x], a
+       ld [hl+], a ; write x
 
   push bc
+       push hl ; save hl = rt cf value
   call map_get_tile
        ; set flags result
-       ld [unit_test_collision_cf_flags], a
+       pop hl
+       ld [hl], a ; store last cf
   and a, $2
   pop bc
   pop de
   ret nz
 
-       ; set to 0 if we did not collide
-       xor a, a
-       ld [unit_test_collision_cf_flags], a
-
   push de
   call unit_collides_with_any_other
        ; TODO: write collided unit here as well
index 56cb518edb83c3e30de2e619d76f3cdc13d11015..d76153257012e7b4e7ee18e83470f6d226b44edc 100644 (file)
@@ -33,12 +33,6 @@ shadow_ie: .adv 1
 
   ; status text buffer
 status_text: .adv 32
-       
-       ; stores the last collision flag result
-       ; that was performed by a test collision call
-unit_test_collision_cf_flags: .adv 1
-unit_test_collision_pos_y: .adv 1
-unit_test_collision_pos_x: .adv 1
 
        ; self modifying code
        ; the vblank interrupt jumps here