Level selection menu: entry transition events (#12) (#35) [commit 2]

This commit is contained in:
xCrystal 2024-01-29 19:52:08 +01:00
parent 52bb92028e
commit 9d0fbf3883
6 changed files with 32 additions and 20 deletions

View File

@ -29,3 +29,7 @@ DEF STAGE_4 EQU 1 << STAGE_4_F
const UNLOCK_WHEN_LEVELS_CLEARED ; 00 const UNLOCK_WHEN_LEVELS_CLEARED ; 00
const UNLOCK_WHEN_NUMBER_OF_LEVELS_CLEARED ; 01 const UNLOCK_WHEN_NUMBER_OF_LEVELS_CLEARED ; 01
const UNLOCK_WHEN_TECHNIQUES_CLEARED ; 02 const UNLOCK_WHEN_TECHNIQUES_CLEARED ; 02
; maximum amount of levels that can be unlocked in a single level cleared run.
; levels to unlock are processed in level order.
DEF MAX_UNLOCK_LEVELS_AT_ONCE EQU 10

View File

@ -31,10 +31,6 @@ ClearedLevelScreen:
.exit .exit
call AddLevelCoinsToBalance call AddLevelCoinsToBalance
call ClearLevel call ClearLevel
xor a
ld [wNumTempUnlockedLevels], a
ld a, $ff
ld [wTempUnlockedLevels], a
jp UnlockLevels jp UnlockLevels
.LevelCleared1Text: .LevelCleared1Text:
@ -92,7 +88,10 @@ ComputeLevelsToUnlock:
inc b inc b
ld a, b ld a, b
cp NUM_LEVELS cp NUM_LEVELS
jr z, .done jr z, .done ; done if went through all existing levels
ld a, [wLastUnlockedLevelsCount]
cp MAX_UNLOCK_LEVELS_AT_ONCE
jr nc, .done ; done if reached the capacity of wLastUnlockedLevels
; advance hl to next level in LevelUnlockRequirements ; advance hl to next level in LevelUnlockRequirements
.loop .loop
ld a, [hli] ld a, [hli]
@ -169,19 +168,19 @@ ComputeLevelsToUnlock:
jr .check_techniques_cleared_loop jr .check_techniques_cleared_loop
.reqs_met .reqs_met
; add level to wTempUnlockedLevels ; add level to wLastUnlockedLevels
pop bc ; b = which level pop bc ; b = which level
push hl push hl
ld a, [wNumTempUnlockedLevels] ld a, [wLastUnlockedLevelsCount]
ld e, a ld e, a
ld d, 0 ld d, 0
ld hl, wTempUnlockedLevels ld hl, wLastUnlockedLevels
add hl, de add hl, de
ld [hl], b ld [hl], b
inc hl inc hl
ld [hl], $ff ld [hl], $ff
inc a inc a
ld [wNumTempUnlockedLevels], a ld [wLastUnlockedLevelsCount], a
pop hl pop hl
pop de pop de
ret ret
@ -192,7 +191,7 @@ ComputeLevelsToUnlock:
ret ret
SaveUnlockedLevels: SaveUnlockedLevels:
ld hl, wTempUnlockedLevels ld hl, wLastUnlockedLevels
.loop .loop
ld a, [hli] ld a, [hli]
ld e, a ld e, a

View File

@ -145,14 +145,22 @@ GameMenu_WorldMap:
call ClearObjectStructs call ClearObjectStructs
call ClearBGPalettes call ClearBGPalettes
call ClearSprites call ClearSprites
; clear unlocked levels
xor a
ld [wLastUnlockedLevelsCount], a
ld a, $ff
ld [wLastUnlockedLevels], a
; handle overworld exit
ld a, [wExitOverworldReason] ld a, [wExitOverworldReason]
cp CLEARED_LEVEL cp CLEARED_LEVEL
jr nz, .save_and_return jr nz, .save_and_return
; if CLEARED_LEVEL:
; show post-level screen, clear level, unlock levels, advance ToD, request appropriate LSM events
farcall ClearedLevelScreen farcall ClearedLevelScreen
call AdvanceTimeOfDay call AdvanceTimeOfDay
ld hl, wLevelSelectionMenuEntryEventQueue ld hl, wLevelSelectionMenuEntryEventQueue
set LSMEVENT_ANIMATE_TIME_OF_DAY, [hl] set LSMEVENT_ANIMATE_TIME_OF_DAY, [hl]
ld a, [wNumTempUnlockedLevels] ld a, [wLastUnlockedLevelsCount]
and a and a
jr z, .save_and_return jr z, .save_and_return
set LSMEVENT_SHOW_UNLOCKED_LEVELS, [hl] set LSMEVENT_SHOW_UNLOCKED_LEVELS, [hl]

View File

@ -23,14 +23,18 @@ LevelSelectionMenu::
bit LSMEVENT_SHOW_UNLOCKED_LEVELS, a bit LSMEVENT_SHOW_UNLOCKED_LEVELS, a
jr z, .load_default_landmark jr z, .load_default_landmark
ld hl, wTempUnlockedLevels ld a, [wLastUnlockedLevelsCount]
and a
jr z, .load_default_landmark
ld hl, wLastUnlockedLevels
.show_unlocked_levels_loop .show_unlocked_levels_loop
ld a, [hli] ld a, [hli]
cp $ff cp $ff
jr z, .load_default_landmark jr z, .load_default_landmark
push hl push hl
; perform level-to-landmark lookup of wTempUnlockedLevels[i] in $ff-terminated LandmarkToLevelTable. ; perform level-to-landmark lookup of wLastUnlockedLevels[i] in $ff-terminated LandmarkToLevelTable.
; stop at the first match and load it to wLevelSelectionMenuCurrentLandmark. ; stop at the first match and load it to wLevelSelectionMenuCurrentLandmark.
ld hl, LandmarkToLevelTable ld hl, LandmarkToLevelTable
ld c, 0 ld c, 0

Binary file not shown.

Before

Width:  |  Height:  |  Size: 390 B

After

Width:  |  Height:  |  Size: 391 B

View File

@ -711,13 +711,6 @@ wOverworldMapBlocks:: ds 1300
wOverworldMapBlocksEnd:: wOverworldMapBlocksEnd::
SECTION UNION "Overworld Map", WRAM0
; temporary list of unlocked levels during post-level screen
wNumTempUnlockedLevels:: db
wTempUnlockedLevels:: ds NUM_LEVELS
SECTION UNION "Overworld Map", WRAM0 SECTION UNION "Overworld Map", WRAM0
; GB Printer data ; GB Printer data
@ -2548,6 +2541,10 @@ wDefaultLevelSelectionMenuLandmark:: db
wCurOverworldMiscPal:: db wCurOverworldMiscPal:: db
wLevelSelectionMenuEntryEventQueue:: flag_array NUM_LSM_EVENTS wLevelSelectionMenuEntryEventQueue:: flag_array NUM_LSM_EVENTS
; list of unlocked levels during post-level screen
wLastUnlockedLevelsCount:: db
wLastUnlockedLevels:: ds MAX_UNLOCK_LEVELS_AT_ONCE + 1
wPlayerDataEnd:: wPlayerDataEnd::
wCurMapData:: wCurMapData::