.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
; 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:
+#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
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
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]
player_init:
xor a, a
ld [player+act_pos_y], a
- ld a, 0x47
ld [player+act_pos_x], a
ret
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
; 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
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
+
+
xor a, a
ld [hl], a
-
+ call debug_draw_player_pos
ret