player: wip jumping
authorLukas Krickl <lukas@krickl.dev>
Mon, 8 Dec 2025 08:49:16 +0000 (09:49 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 8 Dec 2025 08:49:16 +0000 (09:49 +0100)
maps/spawn.inc
src/actor.s
src/player.s
src/wram.s

index da0c2266846966aef53109baf177b4c047870832..37ff478d337ad93a23e000bb1d6d427b89d4a9dd 100644 (file)
@@ -1,8 +1,8 @@
 ; this map was generated by tmx2map.py
 
-.db 0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
-.db 0x0, 0x1, 0x2, 0x5, 0x3, 0x4, 0x0, 0x0
+.db 0x1, 0x2, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5
+.db 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5
+.db 0x5, 0x1, 0x2, 0x5, 0x3, 0x4, 0x0, 0x0
 .db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
 .db 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x4, 0x5
 .db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
index 24b35adae7b31ae988927151d772f52a8749b956..3354a64c615c15b1deb08b6a2a80f99b4103e3d3 100644 (file)
@@ -61,34 +61,41 @@ act_rollback_pos_y:
        ;               col_prev_pos: set to previous positions
        ; if collision occures rolls back to 
        ; previous position
+       ;       retuns:
+       ;       col_tile_collided_with: directions collided with
 act_test_tile_collision:
+       xor a, a
+       ld [col_tile_collided_with], a
+       
+       push af
        ld a, [col_direction]
        and a, DIRUP
        call nz, _act_test_tile_up_collision
+       pop bc
+       or a, b
+       push af
 
        ld a, [col_direction]
        and a, DIRDOWN
        call nz, _act_test_tile_down_collision
+       pop bc
+       or a, b
+       push af
 
        ld a, [col_direction]
        and a, DIRLEFT
        call nz, _act_test_tile_left_collision
+       pop bc
+       or a, b
+       push af
 
        ld a, [col_direction]
        and a, DIRRIGHT
        call nz, _act_test_tile_right_collision
+       pop bc
+       or a, b
 
-
-       ld hl, act_pos_y
-       add hl, de
-
-       ; b/c = y/x
-       call map_get_tile
-
-       ld de, t_flags
-       add hl, de
-       ld a, [hl]
-       and a, TF_WALL
+       ld [col_tile_collided_with], a
 
        ret
        
@@ -132,6 +139,9 @@ act_test_tile_collision:
        
        ; test direction routines:
        ;       preserve: de
+       ;       retunrs:
+       ;               a: collided direction bit
+       ;               a: 0 no collision
 _act_test_tile_left_collision:
        push de
 
@@ -142,10 +152,12 @@ _act_test_tile_left_collision:
        _act_tile_col_check col_point_bl, (-1 & 0xFF), 0, @collision
 
        pop de
+       xor a, a
        ret
 @collision:
        pop de
        call act_rollback_pos_x
+       ld a, DIRLEFT
        ret
 
 _act_test_tile_right_collision:
@@ -158,10 +170,12 @@ _act_test_tile_right_collision:
        _act_tile_col_check col_point_br, (-1 & 0xFF), 0, @collision
 
        pop de
+       xor a, a
        ret
 @collision:
        pop de
        call act_rollback_pos_x
+       ld a, DIRRIGHT
        ret
 
 _act_test_tile_up_collision:
@@ -174,10 +188,12 @@ _act_test_tile_up_collision:
        _act_tile_col_check col_point_tr, 0, (-1 & 0xFF), @collision
 
        pop de
+       xor a, a
        ret
 @collision:
        pop de
        call act_rollback_pos_y
+       ld a, DIRUP
        ret
 
 _act_test_tile_down_collision:
@@ -190,10 +206,12 @@ _act_test_tile_down_collision:
        _act_tile_col_check col_point_br, 0, (-1 & 0xFF), @collision
 
        pop de
+       xor a, a
        ret
 @collision:
        pop de
        call act_rollback_pos_y
+       ld a, DIRDOWN
        ret
 
        ; update routines for each actor
index 0dc8702e3982c85675b80fce04e8e8b2f4fa7e93..645418f7607b95d7fbb00ae72b4b0fd514e1e2f9 100644 (file)
@@ -79,6 +79,24 @@ player_update:
        pop de
        call act_test_tile_collision
 
+       ld a, [col_tile_collided_with]
+       and a, DIRUP
+       jr z, @not_up_collision REL
+               ld a, 1
+               ld [player_jump_peak], a
+@not_up_collision:
+
+       ld a, [col_tile_collided_with]
+       and a, DIRDOWN
+       jr z, @not_down_collision REL
+               ; wait for input button to be cleared before grounding player
+               ld a, [curr_inputs]
+               and a, BTNA
+               jr nz, @not_down_collision REL
+
+               xor a, a
+               ld [player_jump_peak], a
+@not_down_collision:
        ret
        
        ; moves the player 
@@ -102,9 +120,13 @@ player_handle_move:
                ld [col_direction], a
 @not_down:
 
-       ld b, BTNUP
+       ld b, BTNA
        input_held
        jr z, @not_up REL
+               ld a, [player_jump_peak]
+               cp a, 0
+               jr nz, @not_up REL
+
                ld a, [player+act_pos_y]
                cp a, 0 ; min value
                jr z, @not_up REL 
index 9ab5bb9dc6c39d6bd87a9b3e4660c1450a3e4e94..ededf33d02f71270d0ae1df29a0b154e5809bd3c 100644 (file)
@@ -72,6 +72,11 @@ srand: .adv 2
        ; stores the last move direction
 player_direction: .adv 1
 
+       ; how many frames can the player jump?
+player_jump_timer: .adv 1
+       ; flag to indicate player jump has peaked
+player_jump_peak: .adv 1
+
 actors:
 player: .adv act_size
 map_actors: .adv act_size * ACT_MAX
@@ -103,6 +108,8 @@ col_point_ct: .adv 2
        ; in. this is required so that the collision code
        ; can handle pushbacks in case of wall collision
 col_direction: .adv 2
+       ; holds tile collision direction result
+col_tile_collided_with: .adv 1
        
        ; y/x previous position
 col_prev_pos: .adv 2