player: wip movement on grid
authorLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 12:48:29 +0000 (13:48 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 12:48:29 +0000 (13:48 +0100)
src/actor.s
src/debug.s
src/levels.s
src/map.s
src/player.s
src/tiles.s
src/ui.s

index ad7609477e1a5382e39c510f7b7dc13aa30eac8e..d49ee35dac8e5854bd26b59480fd6b3b9dd92b4b 100644 (file)
@@ -11,8 +11,30 @@ act_dir_vector:
 .db 0x10 ; NORTH
 .db 0x09 ; WEST
 .db 0x01 ; EAST
+       
+       ; reverse direction
+act_dir_reverse:
+       .db NORTH ; SOUTH
+       .db SOUTH ; NORTH
+       .db EAST ; WEST
+       .db WEST ; EAST
+       
+       
+       ; tile flags to check if moving forward based on direction
+act_dir_forward: 
+       .db TF_SE ; SOUTH
+       .db TF_NE ; NORTH
+       .db TF_WE ; WEST
+       .db TF_EE ; EAST
+       
+       ; tile flags to check if moving back based on direction
+act_dir_back:
+       .db TF_NE ; SOUTH
+       .db TF_SE ; NORTH
+       .db TF_EE ; WEST
+       .db TF_WE ; EAST
 
-
+       
 
        ; updates and draws an actor
        ; calls different routines fro combat and map state
@@ -22,6 +44,71 @@ act_update:
        ; TODO: read type, get ptr from table
        ; and call
        ret
+       
+       ; checks if the selected actor can move forward
+       ;       inputs:
+       ;               de: actor
+       ;               hl: act_dir_forward or act_dir_back
+       ; returns:
+       ;               zero flag:  -> move not possible
+       ;               not zero flag: -> move possible
+act_can_move:
+       push hl
+
+       ld hl, act_pos_y
+       add hl, de
+
+       ld b, [hl]
+       inc hl
+       ld c, [hl]
+
+       push de
+       call map_get_tile 
+       ; hl = tile
+       ld de, t_flags
+       add hl, de
+       ld a, [hl] 
+       ld b, a ; b = tile flags
+
+       pop de
+       
+       ld hl, act_dir
+       add hl, de
+       ld a, [hl]
+       and a, ACT_DIR_MASK
+       ; a = direction
+               
+       ld d, 0
+       ld e, a ; de = direction offset
+       pop hl ; hl = flags table
+       add hl, de
+       ld a, [hl] ; a = required flag
+
+       and a, b
+
+       ret
+       
+       ; moves the actor forward
+       ; does not perform collision checks
+       ; inputs:
+       ;               de: actor
+act_move_forward:
+       ld hl, act_dir
+       ld a, [hl]
+       and a, ACT_DIR_MASK
+       ld b, 0
+       ld c, a ; bc = direction offset
+
+       ld hl, act_dir_vector
+       add hl, bc ; hl = direction vector
+       ret
+       
+       ; moves the actor back
+       ; does not perform collision checks
+       ; inputs:
+       ;               de: actor
+act_move_back:
+       ret
 
 
 act_bat:
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..d0e630981d72b3e6165a360f554a09d8feff19a3 100644 (file)
@@ -0,0 +1,49 @@
+#define DEBUG_FONT_START 0xD0
+
+debug_draw_player_pos:
+       ld a, 2
+       call oamalloc
+
+       ld de, player+act_pos_y
+       
+       ; draw y
+
+       ; y pos
+       ld a, 128
+       ld [hl+], a
+       
+       ; x pos
+       ld a, 32
+       ld [hl+], a
+
+       ; tile
+       ld a, [de]
+       add a, DEBUG_FONT_START
+       ld [hl+], a
+
+       ; flags
+       xor a, a
+       ld [hl+], a
+
+       ; draw x
+       
+       ; y pos
+       ld a, 128
+       ld [hl+], a
+
+       ; x pos
+       ld a, 40
+       ld [hl+], a
+
+       ; tile
+       inc de
+       ld a, [de]
+       add a, DEBUG_FONT_START
+       ld [hl+], a
+
+       ; flags
+       xor a, a
+       ld [hl+], a
+
+
+       ret
index efaf4cd9fd43959bb22fbe682463dbb63bc936c5..49a23c896a312bc139f8d4012cc0f26d08dcd3e5 100644 (file)
@@ -10,7 +10,7 @@
 
 l1:
        mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default, tile_id_table
-       .db 0, 0, 0, 0, 0, 0
+       .db 2, 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 a30f518ddb3aae200b08bfb1303aa5b21b18dde4..2831848859b1fcb3e9391740343a287ce8b7f5c9 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -282,9 +282,8 @@ map_get_tile:
        ld hl, tile_null
        ret
        
-
-       ; draws a full page of the currently selected map
-       ; into the map render buffer
+       ; draws a full map copy into the current map view buffer
+       ; bsed on the current location the player is facing
        ; the map render buffer is then written to the screen
        ; inputs:
        ;               [map]
index 1fcb7cebfbea406253f012ca9dab73b3673f0964..fb4ac6e83b4a383c8fd00b4adbdb13b58be0b065 100644 (file)
@@ -20,7 +20,6 @@ player_direction_turn_left:
 player_init:
        xor a, a
        ld [player+act_pos_y], a
-       ld a, 0x47
        ld [player+act_pos_x], a
        
        ret
@@ -71,5 +70,23 @@ player_handle_move:
                or a, b
                ld [player+act_dir], a
 @not_right:
+
+       ld b, DIRUP
+       input_just
+       jr z, @not_up REL
+               ld hl, act_dir_forward
+               ld de, player
+               call act_can_move
+               call nz, act_move_forward
+@not_up:
+
+       ld b, DIRDOWN
+       input_just
+       jr z, @not_down REL
+               ld hl, act_dir_back
+               ld de, player
+               call act_can_move
+               call nz, act_move_back
+@not_down:
        
        ret
index f7acae096a2d192bca84316cb3dc82aab79d472f..79d390f47e055d6bc5caf82f1f0f4e42460aa23f 100644 (file)
@@ -4,8 +4,22 @@
        ; maps from tile ids 
        ; to tile presets (tile index)
 tile_id_table:
-       ; 0 all exit flags set
+       ; 0 no exits
+       dw tile_no_exits
+       ; 1 all exit flags set
        dw tile_all_exit
+       ; 2 south exit
+       dw tile_south_exit
+       ; 3
+       dw tile_north_exit
+       ; 4
+       dw tile_west_exit
+       ; 5
+       dw tile_east_exit
+       ; 6
+       dw tile_north_south_exit
+       ; 7
+       dw tile_east_west_exit
 
        
        ; fallback tile 
@@ -16,3 +30,20 @@ tile_null:
 tile_all_exit:
        tiledef TT_WALL, TF_SE | TF_NE | TF_EE | TF_WE, 0 
 
+tile_no_exits:
+       tiledef TT_WALL, 0, 0 
+tile_south_exit:
+       tiledef TT_WALL, TF_SE, 0 
+tile_north_exit:
+       tiledef TT_WALL, TF_NE, 0 
+tile_west_exit:
+       tiledef TT_WALL, TF_WE, 0 
+tile_east_exit:
+       tiledef TT_WALL, TF_EE, 0 
+
+tile_north_south_exit:
+       tiledef TT_WALL, TF_NE | TF_SE, 0 
+tile_east_west_exit:
+       tiledef TT_WALL, TF_EE | TF_WE, 0 
+       
+
index 28dc93ee30c1be749dd29ac6138120ad3b5bbc43..2656018479d0fb2d6008362ed77f1eaa1ca09113 100644 (file)
--- a/src/ui.s
+++ b/src/ui.s
@@ -71,5 +71,5 @@ compass_draw:
        xor a, a
        ld [hl], a
 
-
+       call debug_draw_player_pos
        ret