map: refactoring added direction vecotrs and directions to actor
authorLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 05:34:53 +0000 (06:34 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 15 Dec 2025 05:34:53 +0000 (06:34 +0100)
Reworking tile defs

src/actor.s
src/defs.s
src/levels.s
src/macros.inc
src/map.s
src/player.s
src/tiles.s
src/update.s

index fe5cc866600777dfcdd966b71149ae1833a7579c..ad7609477e1a5382e39c510f7b7dc13aa30eac8e 100644 (file)
@@ -1,4 +1,19 @@
-       
+
+       ; vectors for each direction
+       ; SOUTH, NORTH, WEST, EAST
+       ;       S: Sign bit
+       ;       y: y position
+       ;       x: x position
+       ;       bits:
+       ;     SYYYSXXX
+act_dir_vector:
+.db 0x90 ; SOUTH       
+.db 0x10 ; NORTH
+.db 0x09 ; WEST
+.db 0x01 ; EAST
+
+
+
        ; updates and draws an actor
        ; calls different routines fro combat and map state
        ; inputs:
index b462550be9a3198569051c204c023a72eff7d675..06ceff794bb79d69d46dda2a089bbc2d36e42fac 100644 (file)
@@ -27,8 +27,8 @@
 #define UI_TILE_HEIGHT 4
        
        ; player position offset to get center of tile
-#define MAP_W 20
-#define MAP_H 14
+#define MAP_W 6
+#define MAP_H 6
 #define MAP_TILES (MAP_W * MAP_H)
 
   ; actor type enum
 .de ACT_T_BAT, 1
        
        ; actor struct 
+       ; stats are defined by looking up the type in a table
+       ; player stats are variable
   ; act_def
 .se 0
 .de act_type, 1
 .de act_flags, 1
 .de act_pos_y, 1 ; y/x position
 .de act_pos_x, 1
+       ; actor direction information
+       ;       D: facing direction bits (0-3)
+       ;        000000DD
+.de act_dir, 1
   ; custom parameter
 .de act_p0, 1
        ; state parameter
 
        ; tile flags
 .se 1
-.de TF_WALL, 1
+       ; SOUTH EXIT
+.de TF_SE, 1
+       ; NORTH EXIT
+.de TF_NE, 2
+       ; WEST EXIT
+.de TF_WE, 4
+       ; EAST EXIT
+.de TF_EE, 8
 
        ; tile struct
 .se 0 
        ; 0 = player, 1-N = map actors
 .de t_actor, 1
 .de t_p0, 1
-       ; graphical tile
-.de t_tile, 1
 .de t_size, 0
 
        ; exit table entry
 .def int DIRLEFT = BTNLEFT
 .def int DIRRIGHT = BTNRIGHT
 
+       ; player direction
+.def int SOUTH = 0
+.def int NORTH = 1
+.def int WEST = 2
+.def int EAST = 3
+
        ; gameplay control flags
 .se 1
        
index 0d8abf7d76d36b759cbe40cc6a65dc99ca916300..efaf4cd9fd43959bb22fbe682463dbb63bc936c5 100644 (file)
@@ -1,10 +1,4 @@
        
-       ; default tile id table
-       ; 00: empty
-       ; 01: wall up left
-       ;       02: wall up right
-       ;       03: wall down left
-       ;       04: wall down right
 
        ; level definitions
        ; levels always have a header
 
 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 0, 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
+       .db 0, 0, 0, 0, 0, 0
+       .db 0, 0, 0, 0, 0, 0
+
 #include "spawn.inc"
 
 tile_banks_default:
index 8569572cdf0ecabb101373b273a83a032140d03c..04bfd618a55d61704e7f8d1cacaff48d03d70390 100644 (file)
@@ -170,13 +170,11 @@ $1:
        ;               $1: type
        ;               $2: flags
        ;               $3: p0
-       ;               $4: tile gfx
 #macro tiledef
        .db $1, $2 
        ; t_actor
        .db 0
        .db $3
-       .db $4
 #endmacro
 
        ; defines a new actor
@@ -189,8 +187,8 @@ $1:
        ;               $6: mp
 #macro actdef
        .db $1, $2, $3, $4
-       ; p0 and state
-       .db 0, 0 
+       ; dir, p0 and state
+       .db 0, 0, 0 
        .db $5, $6
 #endmacro
 
index 8262043b5635eb35c906856c54a90da6162152d1..a30f518ddb3aae200b08bfb1303aa5b21b18dde4 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -282,143 +282,13 @@ map_get_tile:
        ld hl, tile_null
        ret
        
-       ; prepares tile draw
-       ; by writing the expected tiles
-       ; to tile_to_draw[0] to [3]
-       ; inputs:
-       ;               b/c: y/x position
-       ;       returns:
-       ;               update_tile_to_draw: 1 bytes of new tile data
-       ;               upte_tile_vram: ptr to vram
-map_draw_tile_prep:
-       ; find tile to draw
-       push bc
-       call map_get_tile
-       ld a, h
-       ld [update_tile_ptr], a
-       ld a, l
-       ld [update_tile_ptr+1], a
-
-       ld bc, t_tile
-       add hl, bc ; hl = tile gfx
-       pop bc
-       
-       ; load tile into a
-       ld a, [hl] ; a = tile
-       push af ; save tile gfx
-       
-       ; TODO: this needs to wrap around
-       ; if hl goes oob in y-loop
-       ld a, [map_vram_tl]
-       ld h, a
-       ld a, [map_vram_tl+1]
-       ld l, a
-       ld de, ((MAP_W) + 12) ; one row
-       
-       ; skip y loop if b is 0
-       ld a, b
-       cp a, 0
-       jr z, @skip_y REL
-
-@y_loop:
-               add hl, de 
-               dec b
-               jr nz, @y_loop REL
-@skip_y:
-
-       ld d, 0
-       ld a, c
-       ld e, a
-       add hl, de ; hl = SCRN location
-
-       ; save hl to vram ptr 
-
-       ld a, h
-       ld [update_tile_vram], a
-       ld a, l
-       ld [update_tile_vram+1], a
-       
-       ; hl = tile data buffer
-       ld hl, update_tile_to_draw
-
-       ; a = start tile
-       pop af 
-
-       ; draw 1 tile
-       ld [hl], a
-
-       ret
-
-#macro map_draw_row_inc_c
-       push bc
-       call map_draw_tile_prep
-       pop bc
-       push bc
-       call map_draw_tile
-       pop bc
-       inc c
-#endmacro
-
-       ; draws a row of tiles
-       ; inputs:
-       ;               b: y position
-map_draw_row:  
-       ld c, 0
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-       map_draw_row_inc_c
-
-       ret
-
-#macro map_full_draw_inc_b
-       call map_draw_row
-       inc b
-#endmacro
 
        ; draws a full page of the currently selected map
+       ; into the map render buffer
+       ; the map render buffer is then written to the screen
        ; inputs:
        ;               [map]
 map_full_draw:
-       ld b, 0
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-       
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-
-       map_full_draw_inc_b
-       map_full_draw_inc_b
-
        ret
        
        ; nop map rotuine
index a32d998888adda57a810ffcfe6d3e242644ee810..1aac9b68ba3fe0b00ca00f59be4e20fc07293800 100644 (file)
@@ -3,7 +3,7 @@
 
        ; sets up the player actor
 player_init:
-       ld a, 0x5A
+       xor a, a
        ld [player+act_pos_y], a
        ld a, 0x47
        ld [player+act_pos_x], a
@@ -19,77 +19,13 @@ player_update:
 
        ret
        
+       ; draws the players current facing direction
+       ; as a compass
+compass_draw:
+       ret
+       
        ; moves the player 
        ; does not move out of bounds
        ; based on the last queued input
 player_handle_move:
        ret
-       
-       ; draws player at current location
-player_draw:
-       ; flicker the cursor 
-       ; for transparency effect
-       ld a, [frame_count]
-       and a, 1
-       ret z
-
-       ld a, 2
-       call oamalloc
-       
-       ; write left cursor
-
-       ; calculate y pos
-       ld a, [scroll_y]
-       ld b, a ; b = scroll y
-
-       ld a, [player+act_pos_y]
-       add a, OBJ_OFF_Y
-       sub a, b ; - scroll y
-       ; store y for second obj
-       ld [tmp_y], a
-
-       ; write y
-       ld [hl+], a
-       
-       ; calculate x pos
-       ld a, [scroll_x]
-       ld b, a
-
-       ld a, [player+act_pos_x]
-       add a, OBJ_OFF_X
-       sub a, b ; - scroll x
-       ; store x for second obj
-       ld [tmp_x], a
-
-       ; write x
-       ld [hl+], a
-
-       ; write tile
-       ld a, PLAYER_CURSOR_L
-       ld [hl+], a
-
-       ; write flags
-       xor a, a
-       ld [hl+], a
-
-       ; write right cursor
-
-
-       ; write y
-       ld a, [tmp_y]
-       ld [hl+], a
-
-       ; write x
-       ld a, [tmp_x]
-       add a, 8
-       ld [hl+], a
-
-       ; write tile
-       ld a, PLAYER_CURSOR_R
-       ld [hl+], a
-
-       ; write flags
-       xor a, a
-       ld [hl+], a
-
-       ret
index bff21e7d01731b91ee26ab196ceafb6cc1e65d04..f7acae096a2d192bca84316cb3dc82aab79d472f 100644 (file)
@@ -1,43 +1,18 @@
        ; tile definitions
 
-#define GFX_GRASS 0x20
-#define GFX_WALL 0x40
-
        
        ; maps from tile ids 
        ; to tile presets (tile index)
 tile_id_table:
-       ; 0
-       dw tile_grass
-
-       ; 1
-       dw tile_wall_tl
-       dw tile_wall_tr
-       dw tile_wall_bl
-       dw tile_wall_br
+       ; 0 all exit flags set
+       dw tile_all_exit
 
-       ; 4
-       dw tile_wall_single
        
        ; fallback tile 
 tile_null:
        tiledef 0, 0, 0, 0
 
-tile_grass:
-       tiledef TT_EMPTY, 0, 0, GFX_GRASS
-
-
-tile_wall_tr:
-       tiledef TT_WALL, TF_WALL, 0, GFX_WALL+1
-
-tile_wall_tl:
-       tiledef TT_WALL, TF_WALL, 0, GFX_WALL
-
-tile_wall_bl:
-       tiledef TT_WALL, TF_WALL, 0, GFX_WALL+16
 
-tile_wall_br:
-       tiledef TT_WALL, TF_WALL, 0, GFX_WALL+17
+tile_all_exit:
+       tiledef TT_WALL, TF_SE | TF_NE | TF_EE | TF_WE, 0 
 
-tile_wall_single:
-       tiledef TT_WALL, TF_WALL, 0, 0x42
index 5bbccb78144974aed94281a6fb427924c41124c3..d97381799ae8cd90203e549b6df87c336aedbc51 100644 (file)
@@ -8,7 +8,7 @@ update_game:
        
        ; player should update even in debug mode
        call player_update
-       call player_draw
+       call compass_draw
        
   ; tick rng every frame
        call rand