From: Lukas Krickl Date: Mon, 15 Dec 2025 14:58:22 +0000 (+0100) Subject: player: Added basic movement X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=ec753400a021cb90d2aeab102253af0abf30f0fd;p=gbrg%2F.git player: Added basic movement --- diff --git a/src/actor.s b/src/actor.s index d49ee35..5bcf01f 100644 --- a/src/actor.s +++ b/src/actor.s @@ -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 diff --git a/src/levels.s b/src/levels.s index 49a23c8..0e4161b 100644 --- a/src/levels.s +++ b/src/levels.s @@ -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 diff --git a/src/player.s b/src/player.s index fb4ac6e..869b5ab 100644 --- a/src/player.s +++ b/src/player.s @@ -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: