From: Lukas Krickl Date: Wed, 3 Dec 2025 09:48:45 +0000 (+0100) Subject: actor: Added collision checks X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=883a6d4c94c1bce1c9f0817ea768bfb75a24524f;p=gbrg%2F.git actor: Added collision checks The current implementation still stops x movement when there is no x collision. --- diff --git a/src/actor.s b/src/actor.s index 4157470..8230718 100644 --- a/src/actor.s +++ b/src/actor.s @@ -77,39 +77,40 @@ act_test_tile_collision: ; $1: point name ; returns: ; b/c: y/x tile position -#macro _act_tile_col_load_pt +#macro _act_col_load_pt ld a, [$1] - div16 a ld b, a ld a, [$1+1] - div16 a ld c, a #endmacro - ; test direction routines: - ; preserve: de -_act_test_tile_left_collision: - push de - - ; top left point - _act_tile_col_load_pt col_point_tl + ; checks collision + ; inputs: + ; $1: point to check + ; $2: label to jump to (jr) +#macro _act_tile_col_check + _act_col_load_pt $1 + div16 b + div16 c call map_get_tile ld de, t_flags add hl, de ld a, [hl] and a, TF_WALL - jr nz, @collision REL + jr nz, $2 REL +#endmacro + + ; test direction routines: + ; preserve: de +_act_test_tile_left_collision: + push de - ; bottom left point - _act_tile_col_load_pt col_point_bl + ; top left point + _act_tile_col_check col_point_tl, @collision - call map_get_tile - ld de, t_flags - add hl, de - ld a, [hl] - and a, TF_WALL - jr nz, @collision REL + ; bottom left point + _act_tile_col_check col_point_bl, @collision pop de ret @@ -121,17 +122,49 @@ _act_test_tile_left_collision: _act_test_tile_right_collision: push de + ; top right point + _act_tile_col_check col_point_tr, @collision + + ; bottom right point + _act_tile_col_check col_point_br, @collision + + pop de + ret +@collision: pop de + call act_rollback_pos_x ret _act_test_tile_up_collision: push de + + ; top left point + _act_tile_col_check col_point_tl, @collision + + ; top right point + _act_tile_col_check col_point_tr, @collision + pop de ret +@collision: + pop de + call act_rollback_pos_y + ret _act_test_tile_down_collision: push de + + ; bottom left point + _act_tile_col_check col_point_bl, @collision + + ; bottom rihgt point + _act_tile_col_check col_point_br, @collision + + pop de + ret +@collision: pop de + call act_rollback_pos_y ret ; update routines for each actor diff --git a/src/levels.s b/src/levels.s index e6a66cb..78fc062 100644 --- a/src/levels.s +++ b/src/levels.s @@ -17,7 +17,7 @@ l1: .db TWL, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS - .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS + .db TGS, TGS, TGS, TGS, TWL, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS .db TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TGS, TWL