Level selection menu: fading animations (#12) (#14)

This commit is contained in:
xCrystal 2023-08-27 13:11:42 +02:00
parent 4855dd9b70
commit 4dec74b770
8 changed files with 161 additions and 54 deletions

View File

@ -124,3 +124,10 @@ DEF CGB_DEFAULT EQU $ff
const PREDEFPAL_GAMEFREAK_LOGO_OB
const PREDEFPAL_GAMEFREAK_LOGO_BG
DEF NUM_PREDEF_PALS EQU const_value
; RGBFadeEffectJumptable indexes (see engine/gfx/rgb_fade.asm:DoRGBFadeEffect)
const_def
const RGBFADE_TO_BLACK_6BGP
const RGBFADE_TO_LIGHTER_6BGP
const RGBFADE_TO_WHITE_6BGP_2OBP
DEF NUM_RGB_FADE_EFFECTS EQU const_value

View File

@ -4,7 +4,7 @@ LoadCGBLayout:
ld a, b
cp CGB_DEFAULT
jr nz, .not_default
ld a, [wDefaultSGBLayout]
ld a, [wDefaultCGBLayout]
.not_default
cp CGB_PARTY_MENU_HP_BARS
jp z, CGB_ApplyPartyMenuHPPals
@ -24,6 +24,7 @@ LoadCGBLayout:
ret
CGBLayoutJumptable:
; entries correspond to CGB_* constants (see constants/cgb_pal_constants.asm)
table_width 2, CGBLayoutJumptable
dw _CGB_BattleGrayscale
dw _CGB_BattleColors
@ -104,7 +105,7 @@ _CGB_BattleColors:
pop hl
call LoadPalette_White_Col1_Col2_Black ; PAL_BATTLE_OB_PLAYER
ld a, CGB_BATTLE_COLORS
ld [wDefaultSGBLayout], a
ld [wDefaultCGBLayout], a
call ApplyPals
_CGB_FinishBattleScreenLayout:
call InitPartyMenuBGPal7
@ -506,7 +507,7 @@ _CGB_Diploma:
_CGB_MapPals:
call LoadMapPals
ld a, CGB_MAPPALS
ld [wDefaultSGBLayout], a
ld [wDefaultCGBLayout], a
ret
_CGB_PartyMenu:
@ -564,7 +565,7 @@ _CGB_GSTitleScreen:
ld a, BANK(wOBPals1)
call FarCopyWRAM
ld a, CGB_DIPLOMA
ld [wDefaultSGBLayout], a
ld [wDefaultCGBLayout], a
call ApplyPals
ld a, TRUE
ldh [hCGBPalUpdate], a
@ -581,6 +582,7 @@ _CGB_LevelSelectionMenu:
ld bc, 2 palettes
ld a, BANK(wOBPals1)
call FarCopyWRAM
; load daytime and gender-based background pals
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
@ -598,30 +600,8 @@ _CGB_LevelSelectionMenu:
ld bc, 6 palettes
ld a, BANK(wBGPals1)
call FarCopyWRAM
; assign attrs based on tile ids according to LevelSelectionMenuAttrmap
hlcoord 0, 0
decoord 0, 0, wAttrmap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
.loop
push hl
ld a, [hl] ; tile id
ld hl, LevelSelectionMenuAttrmap
add l
ld l, a
ld a, h
adc 0
ld h, a
ld a, [hl] ; attr value
ld [de], a
pop hl
inc hl
inc de
dec bc
ld a, b
or c
jr nz, .loop
; apply and commit pals and attrmap
call ApplyAttrmap
; apply and commit pals
call ApplyPals
ld a, TRUE
ldh [hCGBPalUpdate], a

View File

@ -822,5 +822,4 @@ LevelSelectionMenuFemalePals:
INCLUDE "gfx/level_selection_menu/background_female.pal"
assert_table_length NUM_DAYTIMES
LevelSelectionMenuAttrmap:
INCLUDE "gfx/level_selection_menu/attrmap.asm"
INCLUDE "engine/gfx/rgb_fade.asm"

View File

@ -247,4 +247,101 @@ BlackRGB:
RGB 00, 00, 00
WhiteRGB:
RGB 31, 31, 31
RGB 31, 31, 31
_DoRGBFadeEffect::
ldh a, [rSVBK]
push af
ld a, BANK(wBGPals2) ; BANK(wOBPals2)
ldh [rSVBK], a
ld l, b
ld h, 0
add hl, hl
ld de, RGBFadeEffectJumptable
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld de, .done
push de
jp hl
.done:
pop af
ldh [rSVBK], a
ret
RGBFadeEffectJumptable:
; entries correspond to RGBFADE_* constants (see constants/cgb_pal_constants.asm)
table_width 2, RGBFadeEffectJumptable
dw _RGBFadeToBlack_6BGP
dw _RGBFadeToLighter_6BGP
dw _RGBFadeToWhite_6BGP_2OBP
assert_table_length NUM_RGB_FADE_EFFECTS
_RGBFadeToBlack_6BGP:
ld c, 32 / 2
.loop
push bc
; fade BGP to black
ld de, wBGPals2
ld c, 6 * NUM_PAL_COLORS
call FadeStepColorsToBlack
; commit pals
ld a, TRUE
ldh [hCGBPalUpdate], a
call DelayFrame
pop bc
dec c
jr nz, .loop
ret
_RGBFadeToLighter_6BGP:
ld c, 32 / 2
.loop
push bc
; fade BGP to lighter (towards wBGPals1)
ld de, wBGPals2
ld hl, wBGPals1
ld c, 6 * NUM_PAL_COLORS
call FadeStepColorsToLighter
; commit pals
ld a, TRUE
ldh [hCGBPalUpdate], a
call DelayFrame
pop bc
dec c
jr nz, .loop
ret
_RGBFadeToWhite_6BGP_2OBP:
ld c, 32 / 2
.loop
push bc
; fade BGP to white
ld de, wBGPals2
ld c, 6 * NUM_PAL_COLORS
call FadeStepColorsToWhite
; fade OBP to white
ld de, wOBPals2
ld c, 2 * NUM_PAL_COLORS
call FadeStepColorsToWhite
; commit pals
ld a, TRUE
ldh [hCGBPalUpdate], a
call DelayFrame
pop bc
dec c
jr nz, .loop
ret

View File

@ -300,7 +300,6 @@ LoadOrRegenerateLuckyIDNumber:
jp CloseSRAM
Continue:
farcall LevelSelectionMenu
farcall TryLoadSaveFile
jr c, .FailToLoad
call LoadStandardMenuHeader

View File

@ -26,11 +26,13 @@ LevelSelectionMenu::
ld [wLevelSelectionMenuStandingStill], a
call LevelSelectionMenu_InitTilemap
ld b, CGB_LEVEL_SELECTION_MENU
call GetCGBLayout ; apply and commit attrmap (takes 4 frames) and pals
call SetPalettes
call LevelSelectionMenu_InitAttrmap
call WaitBGMap2
xor a
ldh [hBGMapMode], a
ld b, CGB_LEVEL_SELECTION_MENU
call GetCGBLayout ; apply and commit pals
call SetPalettes
ld de, MUSIC_GAME_CORNER
call PlayMusic
@ -122,8 +124,6 @@ LevelSelectionMenu::
call PlaySFX
call LevelSelectionMenu_Delay10Frames
call .EnterLevelFadeOut
ld c, 10
call DelayFrames
ld a, $8
ld [wMusicFade], a
ld a, LOW(MUSIC_NONE)
@ -154,7 +154,8 @@ LevelSelectionMenu::
ret
.EnterLevelFadeOut:
ret
ld b, RGBFADE_TO_WHITE_6BGP_2OBP
jp DoRGBFadeEffect
.exit
call LevelSelectionMenu_Delay10Frames
@ -196,7 +197,7 @@ LevelSelectionMenu_InitTilemap:
.loop
ld a, [de]
cp $ff ; tilemaps are $ff-terminated
jp z, WaitBGMap ; commit tilemap (4 frames)
ret z
ld a, [de]
ld [hli], a
inc de
@ -208,6 +209,31 @@ LevelSelectionMenu_InitTilemap:
dw LevelSelectionMenuPage3Tilemap
dw LevelSelectionMenuPage4Tilemap
LevelSelectionMenu_InitAttrmap:
; assign attrs based on tile ids according to LevelSelectionMenuAttrmap
hlcoord 0, 0
decoord 0, 0, wAttrmap
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
.loop
push hl
ld a, [hl] ; tile id
ld hl, LevelSelectionMenuAttrmap
add l
ld l, a
ld a, h
adc 0
ld h, a
ld a, [hl] ; attr value
ld [de], a
pop hl
inc hl
inc de
dec bc
ld a, b
or c
jr nz, .loop
ret
LevelSelectionMenu_InitPlayerSprite:
; initialize the anim struct of the player's sprite.
; because ClearSpriteAnims was called before, it's always loaded to wSpriteAnim1
@ -397,10 +423,6 @@ DEF PAGE_EDGE_UP EQU $10
DEF PAGE_EDGE_LEFT EQU $08
DEF PAGE_EDGE_RIGHT EQU $a8
DEF PAGE_CHANGE_FADE_FRAMES EQU 16
DEF PAGE_CHANGE_NON_FADE_FRAMES EQU 13
; total frame delay of page change is 16 + 13 + 16 = 45 frames
MACRO page_change_event
; SPRITE_ANIM_SEQ_* to match, Match object's X or Y, X/Y coordinate, Action if both SPRITE_ANIM_SEQ_* and X/Y match
db \1, \2, \3
@ -447,12 +469,10 @@ ENDM
call LevelSelectionMenu_GetNewPage
ld [wLevelSelectionMenuCurrentPage], a
call LevelSelectionMenu_InitTilemap
ld b, CGB_LEVEL_SELECTION_MENU
call GetCGBLayout
call LevelSelectionMenu_InitAttrmap
call WaitBGMap2
xor a
ldh [hBGMapMode], a
ld c, PAGE_CHANGE_NON_FADE_FRAMES
call DelayFrames
call .PageChangeFadeIn
; adjust steps left for the "duplicate" movement of the player leaving and entering a page
ld hl, wLevelSelectionMenuMovementStepsLeft
@ -462,14 +482,12 @@ ENDM
ret
.PageChangeFadeOut:
ld c, PAGE_CHANGE_FADE_FRAMES
call DelayFrames
ret
ld b, RGBFADE_TO_BLACK_6BGP
jp DoRGBFadeEffect
.PageChangeFadeIn:
ld c, PAGE_CHANGE_FADE_FRAMES
call DelayFrames
ret
ld b, RGBFADE_TO_LIGHTER_6BGP
jp DoRGBFadeEffect
LevelSelectionMenu_GetLandmarkPage:
; Return page number (a) of landmark a.
@ -760,5 +778,8 @@ INCBIN "gfx/level_selection_menu/page_3.tilemap"
LevelSelectionMenuPage4Tilemap:
INCBIN "gfx/level_selection_menu/page_4.tilemap"
LevelSelectionMenuAttrmap:
INCLUDE "gfx/level_selection_menu/attrmap.asm"
LevelSelectionMenuDirectionalArrowsGFX:
INCBIN "gfx/level_selection_menu/directional_arrows.2bpp"

View File

@ -62,3 +62,7 @@ IncGradGBPalTable_05:: dc 2,1,0,0, 2,1,0,0, 2,1,0,0
IncGradGBPalTable_06:: dc 1,0,0,0, 1,0,0,0, 1,0,0,0
IncGradGBPalTable_07:: dc 0,0,0,0, 0,0,0,0, 0,0,0,0
DoRGBFadeEffect::
farcall _DoRGBFadeEffect
ret

View File

@ -944,7 +944,7 @@ wCreditsPos:: dw
wCreditsTimer:: db
ENDU
wDefaultSGBLayout:: db
wDefaultCGBLayout:: db
wPlayerHPPal:: db
wEnemyHPPal:: db