player: Added basic movement
authorLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 14:58:22 +0000 (15:58 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 14:58:22 +0000 (15:58 +0100)
src/actor.s
src/levels.s
src/player.s

index d49ee35dac8e5854bd26b59480fd6b3b9dd92b4b..5bcf01f461876b49952cd74110ec89e0652b5154 100644 (file)
@@ -7,10 +7,10 @@
        ;       bits:
        ;     SYYYSXXX
 act_dir_vector:
-.db 0x90 ; SOUTH       
-.db 0x10 ; NORTH
-.db 0x09 ; WEST
-.db 0x01 ; EAST
+.db 0x10 ; SOUTH       
+.db 0x90 ; NORTH
+.db 0x01 ; WEST
+.db 0x09 ; EAST
        
        ; reverse direction
 act_dir_reverse:
@@ -88,12 +88,72 @@ act_can_move:
 
        ret
        
+       ; applies a direction vector to the current actor
+       ; inputs:
+       ;               de: actor
+       ;                b: direction vector (SYYYSXXX)
+act_apply_vec:
+       ld hl, act_pos_y
+       add hl, de
+       
+       ld a, b
+       ; extract y direction
+       and a, 0xF0
+       swap a
+
+       ; a = y direction
+       push bc
+       push hl
+       call act_apply_pos
+       pop hl
+       pop bc
+
+       inc hl ; hl = x pos
+       
+       ld a, b
+       and a, 0x0F
+       ; a = x direction
+       call act_apply_pos
+
+       ret
+       
+       ; applies a single position based on its
+       ; sign bit
+       ; inputs:
+       ;               hl: ptr to position 
+       ;    a: 0000SNNN -> vector value
+       ;       preserves: de
+       ; uses hl, bc, af
+act_apply_pos:
+       ; check sign
+       bit 3, a
+       jr z, @nosign REL
+
+       and a, 0b00000111
+       ld b, a
+       ld a, [hl]
+
+       sub a, b
+       ld [hl], a
+
+       ret
+@nosign:
+       and a, 0b00000111
+       ld b, [hl]
+
+       add a, b
+       ld [hl], a
+
+       ret
+       
+       
        ; moves the actor forward
        ; does not perform collision checks
        ; inputs:
        ;               de: actor
 act_move_forward:
        ld hl, act_dir
+       add hl, de ; hl = act_dir
        ld a, [hl]
        and a, ACT_DIR_MASK
        ld b, 0
@@ -101,6 +161,10 @@ act_move_forward:
 
        ld hl, act_dir_vector
        add hl, bc ; hl = direction vector
+       ld b, [hl] ; b = direction
+       
+       call act_apply_vec
+
        ret
        
        ; moves the actor back
index 49a23c896a312bc139f8d4012cc0f26d08dcd3e5..0e4161bbe27bcfba7500f3af1a2f4c1d6aca4a6f 100644 (file)
@@ -11,7 +11,7 @@
 l1:
        mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default, tile_id_table
        .db 2, 0, 0, 0, 0, 0
-       .db 0, 0, 0, 0, 0, 0
+       .db 3, 0, 0, 0, 0, 0
        .db 0, 0, 0, 0, 0, 0
        .db 0, 0, 0, 0, 0, 0
        .db 0, 0, 0, 0, 0, 0
index fb4ac6e83b4a383c8fd00b4adbdb13b58be0b065..869b5aba8652a8dcfdfce6f30c00e8cab12a8bef 100644 (file)
@@ -77,6 +77,7 @@ player_handle_move:
                ld hl, act_dir_forward
                ld de, player
                call act_can_move
+               ld de, player
                call nz, act_move_forward
 @not_up:
 
@@ -86,6 +87,7 @@ player_handle_move:
                ld hl, act_dir_back
                ld de, player
                call act_can_move
+               ld de, player
                call nz, act_move_back
 @not_down: