.se 1
.de CF_COLLISION, 1
; exit flag
- ; if this flag is set
- ; the upper nibble is
- ; an index into the current map's
- ; exit table
+ ; flags this tile as a valid exit
+ ; must be at the edge of the map
+ ; TODO: maybe add a special exit as a default
.de CF_EXIT, 2
.de CF_DOOR, 4
; if this flag is set do not
.de map_tile_bank1_ptr, 2
.de map_tile_bank2_ptr, 2
.de map_tile_bank3_ptr, 2
-
- ; pointer to exit table
- ;
-.de map_exit_table_ptr, 2
.de map_header_size, 0
; map actor table struct
; list of be pointers to actors
.de map_actor_table_act_ptrs, 0
- ; map exit flags
-.se 1
- ; if these flags are set goto_y and
- ; goto_x are treated as relative offsets
- ; instead of absolute tile positions
-.de EXITF_GOTOY_REL, 1
-.de EXITF_GOTOX_REL, 2
-
-.def int EXITF_GOTOXY_REL = EXITF_GOTOY_REL | EXITF_GOTOX_REL
; map exit table entry struct
.se 0
-; exit tables:
-; down: 0
-; left: 1
-; right: 2
-; up: 3
-
-map_tc_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_tw_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_te_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header
-
-map_te_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_ce_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_tc_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header
-
-map_tw_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_cw_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_tc_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header
-
-map_c_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_bc_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_cw_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_ce_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_tc_header
-
-map_ce_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_be_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_te_header
-
-map_cw_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_bw_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_tw_header
-
-map_bc_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_bw_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_be_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_c_header
-
-map_be_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_bc_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_bc_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_ce_header
-
-map_bw_exit_table:
-exit_def EXITF_GOTOXY_REL, BTNDOWN, -15, 0, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNLEFT, 0, 15, map_c_header
-exit_def EXITF_GOTOXY_REL, BTNRIGHT, 0, -15, map_bc_header
-exit_def EXITF_GOTOXY_REL, BTNUP, 15, 0, map_cw_header
ld a, 0x48 ; roof tile
; clear map
ld [hl+], a
- ld a, CF_COVERED
+ ld a, CF_EXIT
ld [hl], a
ld hl, act_rt_collision_pos_y
; checks the current tile
; and checks for exit flags
+ ; if an exit flag is set, checks if
+ ; the player is in position y == 0
+ ; y == MAP_H-1, x == 0 or x == MAP_W-1
+ ; to determine where to take the player
+ ; the direction moving the player oob must be pressed to move the player
; inputs:
; de: actor
unit_check_exit_hit:
+ push de
ld hl, act_pos_y
add hl, de ; hl = actor_y
; a = flags
ld b, a ; b = flags for later use
and a, CF_EXIT
+ pop de
ret z ; if not we bail
; now it's time to look up
- ; the exit
-
- ; de = exit ptr
- ld de, map_exit_table
- ld a, [de]
- ld l, a
- inc de
- ld a, [de]
- ld h, a
- ; hl = first entry in exit table
- ld a, b ; a = flags
- and a, 0xF0 ; we only care about the upper nibble
- swap a ; a = exit table offset
- cp a, 0 ; do not do this if a == 0
- jr z, @done_calculate_ptr REL
-
- ; add exit size to de a times
- ld de, exit_size
-@calculate_ptr:
- add hl, de
- dec a
- jr nz, @calculate_ptr REL
-@done_calculate_ptr:
+ ; the exit's position
- ; hl == the exit table entry
- ; check if input is required
-
- inc hl ; hl = required input
- ld a, [hl]
- dec hl ; hl = exit flags
-
- cp a, 0
- jr z, @skip_input_check REL
- ; if inputs is not 0 we check button state
- ld b, a ; b = button mask
- input_held
- ret z ; if not input bail
-@skip_input_check:
+@load_map:
; fade out
call video_fade_out
+
+ ; TODO: adjust player map cursor
- ; now we can load the map
-
- ; load map ptr
- push hl
- ld de, exit_to
- add hl, de ; hl = map ptr
-
-
- ld a, [hl+]
- ld c, a
- ld a, [hl]
- ld h, a
- ld a, c
- ld l, a ; hl = map header ptr
- call map_load
-
- pop bc ; bc = exit table now
- ; finally adjust player position
+ ; generate new map
+ call mapgen
; hl = player
ld hl, player_unit
ld de, act_pos_y
add hl, de ; hl = y pos
- ; adjust y position
- ld a, [bc]
- and a, EXITF_GOTOY_REL
-
- inc bc
- inc bc ; bc = y adjust
- ld a, [bc]
- dec bc
- dec bc
- call z, map_exit_absolute_adjust
- call nz, map_exit_relative_adjust
-
- inc hl ; hl = x pos
-
- ; adjust x position
- ld a, [bc]
- and a, EXITF_GOTOX_REL
-
- inc bc
- inc bc
- inc bc ; bc = x adjust
- ld a, [bc]
- call z, map_exit_absolute_adjust
- call nz, map_exit_relative_adjust
-
; scroll to player's position
ld de, player_unit
ret
- ; adjusts player position to aboslute
- ; position
- ; inputs:
- ; hl: player_y or player_x
- ; a: new y or new x
- ; preserves all registers and flags
-map_exit_absolute_adjust:
- ld [hl], a
- ret
-
- ; adjusts player position by a relative
- ; position offset
- ; inputs:
- ; hl: player_y or player_x
- ; a: new y or new x
- ; preserves all registers and flags
-map_exit_relative_adjust:
- push_all
-
- ld b, a
- ld a, [hl]
- add a, b
- ld [hl], a
-
- pop_all
- ret
; player attack state
; inputs: