From f9fa3d548755b791a57d7f8d7cc6e547be1adadc Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 11 Aug 2025 18:50:34 +0200 Subject: [PATCH] collision: moved last cf flags y and x position for collision to actor --- src/defs.s | 4 ++-- src/macros.inc | 2 +- src/objanim.s | 8 +++++--- src/player.s | 23 ++++++++++++++++------- src/unit.s | 14 +++++++------- src/wram.s | 6 ------ 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/defs.s b/src/defs.s index fa23635..d36597d 100644 --- a/src/defs.s +++ b/src/defs.s @@ -165,11 +165,11 @@ ; 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 diff --git a/src/macros.inc b/src/macros.inc index e3c2580..0a75620 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -183,7 +183,7 @@ .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 diff --git a/src/objanim.s b/src/objanim.s index c0a6736..5057a20 100644 --- a/src/objanim.s +++ b/src/objanim.s @@ -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 diff --git a/src/player.s b/src/player.s index 3992e53..89d5f64 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/unit.s b/src/unit.s index af77d7e..7537776 100644 --- a/src/unit.s +++ b/src/unit.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 56cb518..d761532 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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 -- 2.30.2