From: Lukas Krickl Date: Mon, 15 Dec 2025 05:34:53 +0000 (+0100) Subject: map: refactoring added direction vecotrs and directions to actor X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=07d3ef9654fb3112dc4ceea6ad0dc61e12e1bf22;p=gbrg%2F.git map: refactoring added direction vecotrs and directions to actor Reworking tile defs --- diff --git a/src/actor.s b/src/actor.s index fe5cc86..ad76094 100644 --- a/src/actor.s +++ b/src/actor.s @@ -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: diff --git a/src/defs.s b/src/defs.s index b462550..06ceff7 100644 --- a/src/defs.s +++ b/src/defs.s @@ -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 @@ -38,12 +38,18 @@ .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 @@ -85,7 +91,14 @@ ; 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 @@ -96,8 +109,6 @@ ; 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 @@ -114,6 +125,12 @@ .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 diff --git a/src/levels.s b/src/levels.s index 0d8abf7..efaf4cd 100644 --- a/src/levels.s +++ b/src/levels.s @@ -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 @@ -16,6 +10,14 @@ 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: diff --git a/src/macros.inc b/src/macros.inc index 8569572..04bfd61 100644 --- a/src/macros.inc +++ b/src/macros.inc @@ -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 diff --git a/src/map.s b/src/map.s index 8262043..a30f518 100644 --- 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 diff --git a/src/player.s b/src/player.s index a32d998..1aac9b6 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/tiles.s b/src/tiles.s index bff21e7..f7acae0 100644 --- a/src/tiles.s +++ b/src/tiles.s @@ -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 diff --git a/src/update.s b/src/update.s index 5bbccb7..d973817 100644 --- a/src/update.s +++ b/src/update.s @@ -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