From: Lukas Krickl Date: Mon, 11 Aug 2025 15:44:56 +0000 (+0200) Subject: doors: doors now have collision. X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=44bfb2ec07585df2efca537810ecfef652ac8522;p=gbrg%2F.git doors: doors now have collision. The door animation now only plays when the player touches a door. This made the code a lot simpler to deal with overall. --- diff --git a/src/objanim.s b/src/objanim.s index acd2e8b..c0a6736 100644 --- a/src/objanim.s +++ b/src/objanim.s @@ -16,7 +16,7 @@ objanim_init: ; inputs: ; a: tile flags ; b: tile index - ; c: previous player rt special flags + ; unit_test_collision_pos_y/x ; de: actor objanim_door_open: push de @@ -26,23 +26,19 @@ objanim_door_open: ld bc, st_size call memcpy pop bc - pop de - ld hl, act_pos_y - add hl, de ; hl = act y pos - - ; save palyer rt flags in flags - ; but invert CF_COVERED - ld a, c + + ; clear flags ld de, objanim+obja_flags + xor a, a ld [de], a inc de ; de = y pos - ld a, [hl+] + ld a, [unit_test_collision_pos_y] ld [de], a inc de ; de = x pos - ld a, [hl] + ld a, [unit_test_collision_pos_x] ld [de], a inc de ; de = dat @@ -60,11 +56,6 @@ objanim_door_open: or a, GPF_PAUSE_UPDATE ld [gameplay_flags], a - ; prevent player from drawing - ld de, player_unit - ld bc, unit_nop_draw - call unit_set_draw - ret ; state function for door opening animation @@ -73,7 +64,6 @@ objanim_door_open: objanim_door_open_fn: #define TMP_Y, scratch #define TMP_X, scratch+1 - call load_unit_obj ld de, objanim+st_size @@ -83,9 +73,6 @@ objanim_door_open_fn: ; de = anim flags ; set first object - ; reload rt flags from backup while the animation is playing - ld a, [de] - ld [player_rt_special_flags], a inc de ; skip flags ld a, [de] ; a = y position inc de ; de = x postion @@ -141,11 +128,6 @@ objanim_door_open_fn: and a, ~GPF_PAUSE_UPDATE & 0xFF ld [gameplay_flags], a - ; restore player draw call - ld de, player_unit - ld bc, player_draw - call unit_set_draw - ld bc, st_null ret #undefine TMP_X diff --git a/src/player.s b/src/player.s index 463963f..3992e53 100644 --- a/src/player.s +++ b/src/player.s @@ -47,17 +47,7 @@ unit_player_update: ; hl should still be tile ptr here - ; check if player is on a door tile - ; if so, remove door and queue a map redraw - and a, CF_DOOR - ; save CF_DOOR flag value to - ; return before input handling later - push af - push de - call nz, unit_player_remove_door - pop de - - ; check for exit flags + ; check for exit flags push de call unit_check_exit_hit pop de @@ -66,29 +56,34 @@ unit_player_update: call unit_scroll_center pop de - ; return if CF_DOOR was handeled earlier - ; and skip inputs - ; load next state in case this ret is hit - pop af - jr nz, @early_ret REL - push de call unit_handle_inputs pop de + push de + push bc + ; test last collision flags + ld a, [unit_test_collision_cf_flags] + and a, CF_DOOR + call nz, unit_player_remove_door + pop bc + pop de + ret -@early_ret: - ldnull bc - ret ; removes the door tile the player is currently ; standing on ; inputs: + ; unit_test_collision_pos_y/x ; de: actor - ; hl: ptr to tile player is on - ; b: tile index - ; a: tile flags unit_player_remove_door: + ; get tile of last collision + ld a, [unit_test_collision_pos_y] + ld b, a + ld a, [unit_test_collision_pos_x] + ld c, a + call map_get_tile + ; schedule animation push_all call objanim_door_open @@ -102,9 +97,7 @@ unit_player_remove_door: ld a, CF_COVERED ld [hl], a - ld hl, act_pos_y - add hl, de - ld a, [hl] ; load y offset + ld a, [unit_test_collision_pos_y] ; load y offset call map_request_redraw_at ret diff --git a/src/roompatterns.s b/src/roompatterns.s index 1c4453b..4eb6e7a 100644 --- a/src/roompatterns.s +++ b/src/roompatterns.s @@ -125,7 +125,8 @@ room_pattern_flags_translation: .db CF_COLLISION, CF_COLLISION .db 0x00 ; floor ; doors - .db CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED + .db CF_COLLISION | CF_DOOR | CF_COVERED, CF_COLLISION | CF_DOOR | CF_COVERED + .db CF_COLLISION | CF_DOOR | CF_COVERED, CF_COLLISION | CF_DOOR | CF_COVERED ; roof .db CF_COVERED diff --git a/src/unit.s b/src/unit.s index e592847..af77d7e 100644 --- a/src/unit.s +++ b/src/unit.s @@ -353,13 +353,15 @@ unit_handle_inputs: #macro unit_test_collision ; perform tile collision check push de + call unit_get_pos + $1 + ; write y and x pos ld a, b ld [unit_test_collision_pos_y], a ld a, c ld [unit_test_collision_pos_x], a - call unit_get_pos - $1 + push bc call map_get_tile ; set flags result