2024-01-16 09:08:19 -08:00
|
|
|
ClearedLevelScreen:
|
|
|
|
xor a
|
|
|
|
ldh [hMapAnims], a
|
|
|
|
ldh [hSCY], a
|
|
|
|
ld a, -$4
|
|
|
|
ldh [hSCX], a
|
2024-01-17 05:25:29 -08:00
|
|
|
call DisableLCD
|
2024-01-16 09:08:19 -08:00
|
|
|
call ClearTilemap
|
2024-01-17 05:25:29 -08:00
|
|
|
call ClearBGMap0or2
|
2024-01-16 09:08:19 -08:00
|
|
|
call LoadFrame
|
|
|
|
call LoadStandardFont
|
|
|
|
call ClearMenuAndWindowData
|
|
|
|
ld b, CGB_DIPLOMA
|
|
|
|
call GetCGBLayout
|
2024-02-10 15:16:00 -08:00
|
|
|
call SetDefaultBGPAndOBP
|
2024-01-17 05:25:29 -08:00
|
|
|
call EnableLCD
|
2024-01-16 09:08:19 -08:00
|
|
|
ld hl, .LevelCleared1Text
|
|
|
|
bccoord 3, 1
|
2024-02-10 15:16:00 -08:00
|
|
|
call PrintTextboxTextAt
|
2024-01-16 09:08:19 -08:00
|
|
|
ld hl, .LevelCleared2Text
|
|
|
|
bccoord 3, 3
|
2024-02-10 15:16:00 -08:00
|
|
|
call PrintTextboxTextAt
|
2024-01-16 09:08:19 -08:00
|
|
|
.loop
|
|
|
|
call DelayFrame
|
|
|
|
call GetJoypad
|
|
|
|
ldh a, [hJoyPressed]
|
|
|
|
bit A_BUTTON_F, a
|
|
|
|
jr nz, .exit
|
|
|
|
bit B_BUTTON_F, a
|
|
|
|
jr z, .loop
|
|
|
|
.exit
|
|
|
|
call AddLevelCoinsToBalance
|
2024-01-18 10:22:21 -08:00
|
|
|
call ClearLevel
|
2024-01-28 08:57:11 -08:00
|
|
|
jp UnlockLevels
|
2024-01-16 09:08:19 -08:00
|
|
|
|
|
|
|
.LevelCleared1Text:
|
|
|
|
text " L E V E L"
|
|
|
|
done
|
|
|
|
|
|
|
|
.LevelCleared2Text:
|
|
|
|
text "C L E A R E D"
|
|
|
|
done
|
|
|
|
|
|
|
|
AddLevelCoinsToBalance:
|
|
|
|
; givecoins YOUR_COINS, COINS_FROM_RAM | wCurLevelCoins
|
|
|
|
ld de, wCoins ; YOUR_COINS
|
|
|
|
ld hl, wCurLevelCoins
|
|
|
|
ld bc, hCoinsTemp
|
|
|
|
push bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld [bc], a
|
|
|
|
inc bc
|
|
|
|
ld a, [hli]
|
|
|
|
ld [bc], a
|
|
|
|
inc bc
|
|
|
|
ld a, [hl]
|
|
|
|
ld [bc], a
|
|
|
|
pop bc
|
|
|
|
farcall GiveCoins
|
2024-01-17 05:25:29 -08:00
|
|
|
ret
|
2024-01-18 10:22:21 -08:00
|
|
|
|
|
|
|
ClearLevel:
|
2024-01-22 10:32:19 -08:00
|
|
|
ld a, [wCurSpaceEffect] ; End Space effect byte contains STAGE_*_F
|
2024-01-18 10:22:21 -08:00
|
|
|
call GetClearedLevelsStageAddress
|
|
|
|
ld b, SET_FLAG
|
|
|
|
ld d, 0
|
|
|
|
ld a, [wCurLevel]
|
|
|
|
ld e, a
|
|
|
|
call FlagAction
|
|
|
|
ret
|
|
|
|
|
|
|
|
UnlockLevels:
|
2024-01-21 03:26:13 -08:00
|
|
|
call ComputeLevelsToUnlock
|
|
|
|
jp SaveUnlockedLevels
|
|
|
|
|
|
|
|
ComputeLevelsToUnlock:
|
2024-01-18 10:22:21 -08:00
|
|
|
ld hl, LevelUnlockRequirements
|
|
|
|
ld de, wUnlockedLevels - 1
|
|
|
|
ld b, 0
|
|
|
|
.next_byte
|
|
|
|
ld c, 8
|
|
|
|
inc de
|
|
|
|
ld a, [de]
|
|
|
|
.next_bit
|
|
|
|
srl a
|
|
|
|
push af
|
|
|
|
call nc, .CheckUnlockLevel ; skip if level is already unlocked
|
|
|
|
inc b
|
|
|
|
ld a, b
|
|
|
|
cp NUM_LEVELS
|
2024-01-29 10:52:08 -08:00
|
|
|
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
|
2024-01-18 10:22:21 -08:00
|
|
|
; advance hl to next level in LevelUnlockRequirements
|
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
|
|
|
inc a ; cp $ff
|
|
|
|
jr nz, .loop
|
|
|
|
pop af
|
|
|
|
dec c
|
|
|
|
jr z, .next_byte
|
|
|
|
jr .next_bit
|
|
|
|
|
|
|
|
.done
|
|
|
|
pop af
|
|
|
|
ret
|
|
|
|
|
|
|
|
; check if the LevelUnlockRequirements[b] at hl for unlocking level b are met.
|
|
|
|
; return hl pointing to up to the $ff byte of this LevelUnlockRequirements entry.
|
|
|
|
.CheckUnlockLevel:
|
|
|
|
push de
|
|
|
|
push bc
|
|
|
|
ld a, [hl]
|
|
|
|
cp $ff
|
|
|
|
jr z, .reqs_met ; jump if no specific reqs to unlock this level
|
|
|
|
inc hl
|
|
|
|
cp UNLOCK_WHEN_LEVELS_CLEARED
|
|
|
|
jr z, .check_levels_cleared_loop
|
|
|
|
cp UNLOCK_WHEN_NUMBER_OF_LEVELS_CLEARED
|
2024-01-19 09:00:07 -08:00
|
|
|
jr z, .check_number_of_levels_cleared
|
2024-01-18 10:22:21 -08:00
|
|
|
cp UNLOCK_WHEN_TECHNIQUES_CLEARED
|
2024-01-19 09:00:07 -08:00
|
|
|
jr .check_techniques_cleared
|
2024-01-18 10:22:21 -08:00
|
|
|
|
|
|
|
.check_levels_cleared_loop
|
|
|
|
ld a, [hli] ; which level
|
|
|
|
ld e, a
|
|
|
|
inc a ; cp $ff
|
|
|
|
jr z, .reqs_met ; jump when no more required levels and all passed so far
|
|
|
|
ld a, [hli] ; which stage
|
|
|
|
push hl
|
|
|
|
call GetClearedLevelsStageAddress
|
|
|
|
ld b, CHECK_FLAG
|
|
|
|
ld d, 0
|
|
|
|
call FlagAction
|
|
|
|
pop hl
|
|
|
|
jr z, .reqs_not_met ; if this level is not cleared, requirements aren't met
|
|
|
|
jr .check_levels_cleared_loop ; otherwise check next level in list
|
|
|
|
|
2024-01-19 09:00:07 -08:00
|
|
|
.check_number_of_levels_cleared
|
|
|
|
push hl
|
|
|
|
ld hl, wClearedLevelsStage1
|
|
|
|
ld b, ((NUM_LEVELS + 7) / 8) * 4
|
|
|
|
call CountSetBits
|
|
|
|
pop hl
|
|
|
|
ld a, [hli]
|
|
|
|
cp c
|
|
|
|
jr c, .reqs_met
|
|
|
|
jr z, .reqs_met
|
|
|
|
jr .reqs_not_met
|
|
|
|
|
|
|
|
.check_techniques_cleared
|
|
|
|
ld bc, 0
|
|
|
|
.check_techniques_cleared_loop
|
|
|
|
ld a, [hli]
|
|
|
|
ld e, a
|
|
|
|
push hl
|
|
|
|
ld hl, wUnlockedTechniques
|
|
|
|
add hl, bc
|
|
|
|
and [hl]
|
|
|
|
cp e
|
|
|
|
pop hl
|
|
|
|
jr nz, .reqs_not_met
|
|
|
|
inc c
|
|
|
|
ld a, c
|
|
|
|
cp (NUM_TECHNIQUES + 7) / 8
|
|
|
|
jr nc, .reqs_met
|
|
|
|
jr .check_techniques_cleared_loop
|
|
|
|
|
2024-01-18 10:22:21 -08:00
|
|
|
.reqs_met
|
2024-01-29 10:52:08 -08:00
|
|
|
; add level to wLastUnlockedLevels
|
2024-01-19 09:00:07 -08:00
|
|
|
pop bc ; b = which level
|
|
|
|
push hl
|
2024-01-29 10:52:08 -08:00
|
|
|
ld a, [wLastUnlockedLevelsCount]
|
2024-01-19 09:00:07 -08:00
|
|
|
ld e, a
|
|
|
|
ld d, 0
|
2024-01-29 10:52:08 -08:00
|
|
|
ld hl, wLastUnlockedLevels
|
2024-01-19 09:00:07 -08:00
|
|
|
add hl, de
|
|
|
|
ld [hl], b
|
|
|
|
inc hl
|
|
|
|
ld [hl], $ff
|
|
|
|
inc a
|
2024-01-29 10:52:08 -08:00
|
|
|
ld [wLastUnlockedLevelsCount], a
|
2024-01-19 09:00:07 -08:00
|
|
|
pop hl
|
2024-01-18 10:22:21 -08:00
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
|
|
|
.reqs_not_met
|
|
|
|
pop bc
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
2024-01-21 03:26:13 -08:00
|
|
|
SaveUnlockedLevels:
|
2024-01-29 10:52:08 -08:00
|
|
|
ld hl, wLastUnlockedLevels
|
2024-01-21 03:26:13 -08:00
|
|
|
.loop
|
|
|
|
ld a, [hli]
|
|
|
|
ld e, a
|
|
|
|
inc a ; cp $ff
|
|
|
|
ret z
|
|
|
|
push hl
|
|
|
|
ld b, SET_FLAG
|
|
|
|
call UnlockedLevelsFlagAction
|
|
|
|
pop hl
|
|
|
|
jr .loop
|
|
|
|
|
2024-01-18 10:22:21 -08:00
|
|
|
INCLUDE "data/levels/levels.asm"
|