From: Lukas Krickl Date: Sun, 9 Mar 2025 11:38:07 +0000 (+0100) Subject: actor: restored actor ability to collide with walls and doors X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=ad37dc3d24f7292c59c1af3a2844531017544ad2;p=gbrg%2F.git actor: restored actor ability to collide with walls and doors --- diff --git a/src/actor.s b/src/actor.s index f5303c2..fe0abc6 100644 --- a/src/actor.s +++ b/src/actor.s @@ -206,6 +206,51 @@ draw_cursor: ret + ; generic collision check code + ; loads ct_mask and actor position + ; and calls collision tile + ; inputs: + ; bc: actor ptr + ; de: y/x position offset + ; returns: + ; a/h: collision flags +generic_collision_check: + ; load actor y/x into de + inc bc ; bc = actor y + ld a, [bc] + add a, d ; y + offset + + ld d, a ; d = target y + inc bc ; bc = actor x + ld a, [bc] + add a, e ; x + offset + ld e, a ; e = target x + + ; if any collision happens now + ; we stop the animation + call collision_tile + ld h, a ; store original a in h for now + ret + + ; performs a simple collision check for actors + ; inputs: + ; bc: actor ptr + ; de: y/x position offset +act_collision_check: + ; set collision mask + ld a, RF_WALL | RF_ACTOR | RF_DOOR + ld [ct_mask], a + + call generic_collision_check + + and a, RF_WALL | RF_ACTOR | RF_DOOR + jr z, @skip REL + ; abort walk state + call anim_abort_walk + jr @skip REL +@skip: + ret + ; advance to the next actor if end_turn != 0 ; effectively ending the current actor's turn who_next: diff --git a/src/player.s b/src/player.s index 947ccf5..328fafd 100644 --- a/src/player.s +++ b/src/player.s @@ -193,26 +193,11 @@ player_update: ; bc: actor ptr ; de: y/x position offset player_collision_check: - ; set collision mask ld a, RF_WALL | RF_DOOR | RF_ACTOR ld [ct_mask], a - - ; load actor y/x into de - inc bc ; bc = actor y - ld a, [bc] - add a, d ; y + offset - - ld d, a ; d = target y - inc bc ; bc = actor x - ld a, [bc] - add a, e ; x + offset - ld e, a ; e = target x - - ; if any collision happens now - ; we stop the animation - call collision_tile - ld h, a ; store original a in h for now + + call generic_collision_check and a, RF_DOOR jr z, @no_door_hit REL @@ -221,7 +206,6 @@ player_collision_check: ld a, [engine_flags] or a, EG_FLOAD_ROOM ld [engine_flags], a - @no_door_hit: diff --git a/src/state.s b/src/state.s index 727a949..326d827 100644 --- a/src/state.s +++ b/src/state.s @@ -159,6 +159,11 @@ sm_bat_pick_direction: ld [hl+], a ; set next state ld a, ANIM_PLAYER_WALK_FRAMES ld [hl], a ; set param[0] + + ; perform collision check + ld d, 0xFF & 0 - ANIM_TILE_SIZE + ld e, 0 + call act_collision_check @not_north: cp a, SOUTH @@ -170,6 +175,10 @@ sm_bat_pick_direction: ld a, ANIM_PLAYER_WALK_FRAMES ld [hl], a ; set param[0] + ; perform collision check + ld d, ANIM_TILE_SIZE + ld e, 0 + call act_collision_check @not_south: cp a, WEST @@ -181,6 +190,10 @@ sm_bat_pick_direction: ld a, ANIM_PLAYER_WALK_FRAMES ld [hl], a ; set param[0] + ; perform collision check + ld d, 0 + ld e, 0xFF & 0 - ANIM_TILE_SIZE + call act_collision_check @not_west: cp a, EAST @@ -192,6 +205,10 @@ sm_bat_pick_direction: ld a, ANIM_PLAYER_WALK_FRAMES ld [hl], a ; set param[0] + ; perform collision check + ld d, 0 + ld e, ANIM_TILE_SIZE + call act_collision_check @not_east: ; verify collision