player: wip collision checks
authorLukas Krickl <lukas@krickl.dev>
Wed, 3 Dec 2025 07:04:31 +0000 (08:04 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 3 Dec 2025 07:04:31 +0000 (08:04 +0100)
src/actor.s
src/player.s
src/wram.s

index 529078272b2a51c69e516337fe979f4e5ab221f9..796c39cd726b265b4857ba4e9a5eaec9906fdcf7 100644 (file)
@@ -84,23 +84,43 @@ _act_test_col_x:
        pop af
        ret
        
+       ; stores current position in tmp_prev_pos
+       ; inputs:
+       ;               de: actor
+act_backup_pos:
+       ld hl, act_pos_y
+       add hl, de
+       ld a, [hl+]
+       ld [tmp_prev_pos], a ; y 
+
+       ld a, [hl]
+       ld [tmp_prev_pos+1], a ; x
+       ret
+       
+       ; restores prev x pos
+       ; inputs:
+       ;               de: actor
+act_rollback_pos_x:
+       ret
+
+       ; restores prev y pos
+       ; inputs:
+       ;               de: actor
+act_rollback_pos_y:
+       ret
+       
        ; test collision based on an actor
        ; and a direction
        ;       inputs:
        ;               de: actor
-       ;                a: direction
-       ;       returns:
-       ;               a: new direction
-       ;               a: 0 if move should be aborted
-act_test_collision:
-       push af
+       ;               col_point_xx: collision points
+       ; if collision occures rolls back to 
+       ; previous position
+act_test_tile_collision:
 
        ld hl, act_pos_y
        add hl, de
 
-       call _act_test_col_y
-       call _act_test_col_x
-
        ; b/c = y/x
        call map_get_tile
 
@@ -108,43 +128,26 @@ act_test_collision:
        add hl, de
        ld a, [hl]
        and a, TF_WALL
-       jr nz, @collision REL
 
-       pop af
-       ret
-@collision:
-       pop af
-       ld a, 0
        ret
 
        ; update routines for each actor
-actor_map_update_table:
+act_map_update_table:
        
        ; draw routine for each actor
-actor_map_draw_table:
+act_map_draw_table:
        
-       ; combat update table
-actor_combat_update_table:
-       
-       ; combat draw table
-actor_combat_draw_table:
        
        
        ; updates and draws an actor
        ; calls different routines fro combat and map state
        ; inputs:
        ;               hl: actor ptr
-actors_map_update:
+act_update:
        ; TODO: read type, get ptr from table
        ; and call
        ret
 
-       
-       ; calls combat update and draw routines
-actors_combat_update:
-       ; TODO: read type, get ptr from table
-       ; and call
-       ret
 
 act_bat:
        actdef ACT_T_BAT, 0, 10, 10, 0, 0 
index 8d97d6f3c5361b1c4d2de4124e4714e6d6771f70..de85d0c7f50cf274879b9cc00aeffa8b61be6414 100644 (file)
@@ -10,75 +10,71 @@ player_init:
        
        ret
        
+       ; writes collision points for player
+       ; inputs:
+       ;               de: actor
+player_col_write_points:
+       ld hl, act_pos_y
+       add hl, de
+       
+       ld a, [hl+]
+       ld b, a ; b = y
+       ld a, [hl]
+       ld c, a ; c = x
+       
+       ; top left point
+       ld a, b 
+       ld [col_point_tl], a
+       ld a, c
+       ld [col_point_tl+1], a
+
+       ; top right point
+       ld a, b
+       ld [col_point_tr], a
+
+       ld a, c
+       add a, 16
+       ld [col_point_tr+1], a
+
+       ; bottom left point
+       ld a, b
+       add a, 16
+       ld [col_point_bl], a
+       ld a, c
+       ld [col_point_bl+1], a
+
+       ; bottom right points
+       ld a, b
+       add a, 16
+       ld [col_point_br], a
+       ld a, c
+       add a, 16
+       ld [col_point_br+1], a
+
+       ret
+
        ; updates the special player actor
 player_update: 
+       ld de, player
        ; call scroll_center_player
+       call act_backup_pos
 
-       call player_inputs
-       call player_handle_move
-
-       ret
-       
-       ; shcedules a player move
-player_inputs:
-       ; no direction inputs if timer is > 0
-       ld a, [player_move_timer]
-       cp a, 0
-       ret nz
-       
-       ld b, BTNUP
-       input_held
-       jr z, @notup REL
-               ld a, DIRUP
-               jp @set
-@notup:
+       call player_col_write_points
 
-       ld b, BTNDOWN
-       input_held
-       jr z, @notdown REL
-               ld a, DIRDOWN
-               jp @set
-@notdown:      
+       push de
+       call player_handle_move
 
-       ld b, BTNLEFT
-       input_held
-       jr z, @notleft REL
-               ld a, DIRLEFT
-               jp @set
-@notleft:
+       pop de
+       call act_test_tile_collision
 
-       ld b, BTNRIGHT
-       input_held
-       jr z, @notright REL
-               ld a, DIRRIGHT
-               jp @set
-@notright:
        ret
-@set:
-       ld de, player
-       call act_test_collision
-       cp a, 0
-       ret z
-
-       ld [player_direction], a
-       ld a, 16 ; tile size
-       ld [player_move_timer], a
        
-       ret
-
-       ; moves the player cursor
+       ; moves the player 
        ; does not move out of bounds
        ; based on the last queued input
 player_handle_move:
-       ; remove 1 from timer
-       ld a, [player_move_timer]
-       cp a, 0
-       ret z
-       dec a
-       ld [player_move_timer], a
-
-       ld a, [player_direction]
-       and a, BTNDOWN
+       ld b, BTNDOWN
+       input_held
        jr z, @not_down REL
                ld a, [player+act_pos_y]
                cp a, 0x60 ; max value
@@ -87,8 +83,8 @@ player_handle_move:
                ld [player+act_pos_y], a
 @not_down:
 
-       ld a, [player_direction]
-       and a, BTNUP
+       ld b, BTNUP
+       input_held
        jr z, @not_up REL
                ld a, [player+act_pos_y]
                cp a, 0 ; min value
@@ -97,8 +93,8 @@ player_handle_move:
                ld [player+act_pos_y], a
 @not_up:
 
-       ld a, [player_direction]
-       and a, BTNLEFT
+       ld b, BTNLEFT
+       input_held
        jr z, @not_left REL
                ld a, [player+act_pos_x]
                cp a, 0 ; min value
@@ -107,8 +103,8 @@ player_handle_move:
                ld [player+act_pos_x], a
 @not_left:
 
-       ld a, [player_direction]
-       and a, BTNRIGHT
+       ld b, BTNRIGHT
+       input_held
        jr z, @not_right REL
                ld a, [player+act_pos_x]
                cp a, 0x90 ; max value
index 9acbc11920311edfce66bf71aa045ebc9b2d9a08..a75c72195470a9eb379567daca89a85179600e41 100644 (file)
@@ -71,7 +71,6 @@ srand: .adv 2
        
        ; stores the last move direction
 player_direction: .adv 1
-player_move_timer: .adv 1
 
 actors:
 player: .adv act_size
@@ -90,7 +89,16 @@ map_tmp_tile_id_table: .adv 2
        ; ptr to current tile to be updated
 tiles: .adv t_size * MAP_TILES
 tiles_end: .adv 0
-
+       
+       ; collision related data
+       ; y/x positions
+col_point_tl: .adv 2
+col_point_tr: .adv 2
+col_point_bl: .adv 2
+col_point_br: .adv 2
+       
+       ; y/x previous position
+tmp_prev_pos: .adv 2
        
        
        ; space for 4 tile ids