actor: fixed collision getting stuck when bumping into walls
authorLukas Krickl <lukas@krickl.dev>
Fri, 5 Dec 2025 04:26:20 +0000 (05:26 +0100)
committerLukas Krickl <lukas@krickl.dev>
Fri, 5 Dec 2025 04:26:20 +0000 (05:26 +0100)
src/actor.s
src/player.s

index a78d2499a88ce2da3aa0d6beb92de12b57b72456..263d78e65791a6d87abefd6b753804c6d406a9d3 100644 (file)
@@ -1,4 +1,24 @@
        
+       ; applies gravity to an actor
+       ;       sets act_direction to DOWN
+       ; inputs:
+       ;               de: actor
+act_apply_gravity:
+       ld a, [col_direction]
+       and a, DIRUP
+       ret nz
+
+       ld a, [col_direction]
+       or a, DIRDOWN
+       ld [col_direction], a
+
+       ld hl, act_pos_y
+       add hl, de
+       ld a, [hl]
+       inc a
+       ld [hl], a
+       ret
+
        ; stores current position in col_prev_pos
        ; inputs:
        ;               de: actor
@@ -116,7 +136,7 @@ _act_test_tile_left_collision:
        push de
 
        ; top left point
-       _act_tile_col_check col_point_tl, (-1 & 0xFF), 0, @collision
+       _act_tile_col_check col_point_tl, (1 & 0xFF), 0, @collision
 
        ; bottom left point
        _act_tile_col_check col_point_bl, (-1 & 0xFF), 0, @collision
@@ -132,7 +152,7 @@ _act_test_tile_right_collision:
        push de
 
        ; top right point
-       _act_tile_col_check col_point_tr, (-1 & 0xFF), 0, @collision
+       _act_tile_col_check col_point_tr, (1 & 0xFF), 0, @collision
 
        ; bottom right point
        _act_tile_col_check col_point_br, (-1 & 0xFF), 0, @collision
@@ -148,7 +168,7 @@ _act_test_tile_up_collision:
        push de
        
        ; top left point
-       _act_tile_col_check col_point_tl, 0, (-1 & 0xFF), @collision
+       _act_tile_col_check col_point_tl, 0, (1 & 0xFF), @collision
 
        ; top right point
        _act_tile_col_check col_point_tr, 0, (-1 & 0xFF), @collision
@@ -164,7 +184,7 @@ _act_test_tile_down_collision:
        push de
 
        ; bottom left point
-       _act_tile_col_check col_point_bl, 0, (-1 & 0xFF), @collision
+       _act_tile_col_check col_point_bl, 0, (1 & 0xFF), @collision
 
        ; bottom rihgt point
        _act_tile_col_check col_point_br, 0, (-1 & 0xFF), @collision
index 6846e37a835eae5854b32e68445f80aa1a185ae2..875700137f6550d58161ed99ece0c96287d9c50a 100644 (file)
@@ -64,6 +64,10 @@ player_update:
        push de
        call player_handle_move
 
+       pop de
+       push de
+       call act_apply_gravity
+
        pop de
        call act_test_tile_collision