diff options
| -rw-r--r-- | engine/slop_menu.asm | 138 |
1 files changed, 110 insertions, 28 deletions
diff --git a/engine/slop_menu.asm b/engine/slop_menu.asm index 258770f5..2e1adaaa 100644 --- a/engine/slop_menu.asm +++ b/engine/slop_menu.asm @@ -247,36 +247,10 @@ SlopExplore: push af call LoadMapData ; reload current map + tileset (menu clobbered VRAM) .renderView -; block-aligned camera; view pointer = wOverworldMap + (by+1)*stride + bx, -; where by = wYCoord/2, bx = wXCoord/2, stride = wCurMapWidth + 2*MAP_BORDER. xor a - ld [wYBlockCoord], a + ld [wYBlockCoord], a ; block-aligned camera centred on wYCoord/wXCoord ld [wXBlockCoord], a - ld a, [wCurMapWidth] - add MAP_BORDER * 2 - ld c, a - ld b, 0 - ld a, [wYCoord] - srl a - inc a - ld hl, 0 -.mulRow - add hl, bc - dec a - jr nz, .mulRow - ld a, [wXCoord] - srl a - add l - ld l, a - jr nc, .noCarry - inc h -.noCarry - ld bc, wOverworldMap - add hl, bc - ld a, l - ld [wCurrentTileBlockMapViewPointer], a - ld a, h - ld [wCurrentTileBlockMapViewPointer + 1], a + call SlopSetViewPtr call LoadCurrentMapView ld b, HIGH(vBGMap0) call CopyScreenTileBufferToVRAM @@ -369,6 +343,8 @@ SlopExplore: ld d, a bit B_PAD_B, d jp nz, .exit + bit B_PAD_A, d + jp nz, .warp bit B_PAD_UP, d jr z, .ckDown ld a, [wYCoord] @@ -472,6 +448,73 @@ SlopExplore: ld a, b ld [wXCoord], a jp .renderView +; ---- A: warp the player to the walkable tile nearest the screen centre ---- +; the centre tile is wTileMap(col 8,row 9) = coord (wYCoord,wXCoord); a coord +; offset (dy,dx) maps to wTileMap(8+2dx, 9+2dy). Scan outward for a passable tile. +.warp + ld hl, SlopWarpOffsets +.warpScan + ld a, [hli] + cp $80 + jr z, .warpGo ; nothing walkable found -> land on the centre + ld d, a ; d = dy + ld a, [hli] + ld e, a ; e = dx + push hl + ld a, d + add a + add 9 ; row = 9 + 2*dy + ld b, a + ld hl, wTileMap +.warpRow + ld a, b + and a + jr z, .warpCol + ld a, 20 + add l + ld l, a + jr nc, .warpRowNC + inc h +.warpRowNC + dec b + jr .warpRow +.warpCol + ld a, e + add a + add 8 ; col = 8 + 2*dx + add l + ld l, a + jr nc, .warpColNC + inc h +.warpColNC + ld a, [hl] + ld c, a + call IsTilePassable ; carry clear -> walkable + pop hl + jr c, .warpScan + ld a, [wYCoord] + add d + ld [wYCoord], a + ld a, [wXCoord] + add e + ld [wXCoord], a +.warpGo + ld a, $ff + ld [wDestinationWarpID], a ; enter at wYCoord/wXCoord (not a warp position) + ld a, [wYCoord] + and 1 + ld [wYBlockCoord], a + ld a, [wXCoord] + and 1 + ld [wXBlockCoord], a + call SlopSetViewPtr + call LoadMapData ; enter the map (player sprite, wild data, warps) + pop af ; drop the 4 saved-origin values (we're staying here) + pop bc + pop bc + pop bc + scf ; carry set -> close menu, resume overworld here + ret .exit pop af ld [wCurMap], a @@ -494,6 +537,45 @@ SlopExplore: and a ; carry clear -> back to SL0P menu ret +; wCurrentTileBlockMapViewPointer = wOverworldMap + (wYCoord/2 + 1)*stride + wXCoord/2 +SlopSetViewPtr: + ld a, [wCurMapWidth] + add MAP_BORDER * 2 + ld c, a + ld b, 0 + ld a, [wYCoord] + srl a + inc a + ld hl, 0 +.loop + add hl, bc + dec a + jr nz, .loop + ld a, [wXCoord] + srl a + add l + ld l, a + jr nc, .nc + inc h +.nc + ld bc, wOverworldMap + add hl, bc + ld a, l + ld [wCurrentTileBlockMapViewPointer], a + ld a, h + ld [wCurrentTileBlockMapViewPointer + 1], a + ret + +; (dy, dx) coord offsets scanned outward from the centre for a walkable tile +SlopWarpOffsets: + db 0, 0 + db -1, 0, 1, 0, 0,-1, 0, 1 + db -1,-1, -1, 1, 1,-1, 1, 1 + db -2, 0, 2, 0, 0,-2, 0, 2 + db -2,-1, -2, 1, 2,-1, 2, 1, -1,-2, -1, 2, 1,-2, 1, 2 + db -3, 0, 3, 0, 0,-3, 0, 3 + db $80 + ; =========================================================================== ; ITEMS submenu: give 99 of the chosen item (stacks via GiveItem) ; =========================================================================== |
