From: Lukas Krickl Date: Thu, 18 Dec 2025 08:41:10 +0000 (+0100) Subject: actor: added collision checks for tiles that contain an active actor X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=197aa7bf91d60316fba1696f2e8ca2c135f915af;p=gbrg%2F.git actor: added collision checks for tiles that contain an active actor --- diff --git a/src/actor.s b/src/actor.s index 1f61e2f..0968dfe 100644 --- a/src/actor.s +++ b/src/actor.s @@ -394,12 +394,70 @@ act_apply_pos: ret + ; creates a copy of the actors position + ; in tmp_act_y and _x + ; inputs: + ; de: actor + ; preverse: + ; de +_act_backup_pos: + ld hl, act_pos_y + add hl, de + ld a, [hl+] + ld [tmp_act_y], a + ld a, [hl] + ld [tmp_act_x], a + ret + + ; restores actor position + ; from tmp_act_y/x + ; inputs: + ; de: actor + ; preserves: + ; de +_act_restore_pos: + ld hl, act_pos_y + add hl, de + + ld a, [tmp_act_y] + ld [hl+], a + ld a, [tmp_act_x] + ld [hl], a + ret + + ; tests if the new actor location contains + ; an actor + ; rolls back position to tmp_act_y/x if it does + ; input: + ; de: actor + ; preserves: + ; de +_act_check_act_in_location: + push de + ld hl, act_pos_y + add hl, de + ld a, [hl+] + ld b, a + ld c, [hl] + call map_get_tile + ; hl = tile + ld bc, t_act + add hl, bc + + ld a, [hl+] + or a, [hl] + pop de + call nz, _act_restore_pos + ret + ; moves the actor forward ; performs collision checks ; inputs: ; de: actor act_move_forward: + call _act_backup_pos + push de ld hl, act_dir_forward call act_can_move @@ -424,10 +482,10 @@ act_move_forward: call act_apply_vec - ; TODO: check if player collides with actor + ; check if player collides with actor ; at new location - pop de + call _act_check_act_in_location call act_set_tact ret @@ -437,6 +495,8 @@ act_move_forward: ; inputs: ; de: actor act_move_back: + call _act_backup_pos + push de ld hl, act_dir_back call act_can_move @@ -468,6 +528,7 @@ act_move_back: call act_apply_vec pop de + call _act_check_act_in_location call act_set_tact ret diff --git a/src/wram.s b/src/wram.s index d79219b..564b36c 100644 --- a/src/wram.s +++ b/src/wram.s @@ -130,6 +130,8 @@ tmp_map_near_left_door: .adv 1 tmp_map_near_right_door: .adv 1 tmp_map_far_left_door: .adv 1 tmp_map_far_right_door: .adv 1 +tmp_act_y: .adv 1 +tmp_act_x: .adv 1 ; actor that is adjacent ; to the players current facing