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_OB
const PREDEFPAL_GAMEFREAK_LOGO_BG const PREDEFPAL_GAMEFREAK_LOGO_BG
DEF NUM_PREDEF_PALS EQU const_value 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 ld a, b
cp CGB_DEFAULT cp CGB_DEFAULT
jr nz, .not_default jr nz, .not_default
ld a, [wDefaultSGBLayout] ld a, [wDefaultCGBLayout]
.not_default .not_default
cp CGB_PARTY_MENU_HP_BARS cp CGB_PARTY_MENU_HP_BARS
jp z, CGB_ApplyPartyMenuHPPals jp z, CGB_ApplyPartyMenuHPPals
@ -24,6 +24,7 @@ LoadCGBLayout:
ret ret
CGBLayoutJumptable: CGBLayoutJumptable:
; entries correspond to CGB_* constants (see constants/cgb_pal_constants.asm)
table_width 2, CGBLayoutJumptable table_width 2, CGBLayoutJumptable
dw _CGB_BattleGrayscale dw _CGB_BattleGrayscale
dw _CGB_BattleColors dw _CGB_BattleColors
@ -104,7 +105,7 @@ _CGB_BattleColors:
pop hl pop hl
call LoadPalette_White_Col1_Col2_Black ; PAL_BATTLE_OB_PLAYER call LoadPalette_White_Col1_Col2_Black ; PAL_BATTLE_OB_PLAYER
ld a, CGB_BATTLE_COLORS ld a, CGB_BATTLE_COLORS
ld [wDefaultSGBLayout], a ld [wDefaultCGBLayout], a
call ApplyPals call ApplyPals
_CGB_FinishBattleScreenLayout: _CGB_FinishBattleScreenLayout:
call InitPartyMenuBGPal7 call InitPartyMenuBGPal7
@ -506,7 +507,7 @@ _CGB_Diploma:
_CGB_MapPals: _CGB_MapPals:
call LoadMapPals call LoadMapPals
ld a, CGB_MAPPALS ld a, CGB_MAPPALS
ld [wDefaultSGBLayout], a ld [wDefaultCGBLayout], a
ret ret
_CGB_PartyMenu: _CGB_PartyMenu:
@ -564,7 +565,7 @@ _CGB_GSTitleScreen:
ld a, BANK(wOBPals1) ld a, BANK(wOBPals1)
call FarCopyWRAM call FarCopyWRAM
ld a, CGB_DIPLOMA ld a, CGB_DIPLOMA
ld [wDefaultSGBLayout], a ld [wDefaultCGBLayout], a
call ApplyPals call ApplyPals
ld a, TRUE ld a, TRUE
ldh [hCGBPalUpdate], a ldh [hCGBPalUpdate], a
@ -581,6 +582,7 @@ _CGB_LevelSelectionMenu:
ld bc, 2 palettes ld bc, 2 palettes
ld a, BANK(wOBPals1) ld a, BANK(wOBPals1)
call FarCopyWRAM call FarCopyWRAM
; load daytime and gender-based background pals ; load daytime and gender-based background pals
ld a, [wPlayerGender] ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a bit PLAYERGENDER_FEMALE_F, a
@ -598,30 +600,8 @@ _CGB_LevelSelectionMenu:
ld bc, 6 palettes ld bc, 6 palettes
ld a, BANK(wBGPals1) ld a, BANK(wBGPals1)
call FarCopyWRAM call FarCopyWRAM
; assign attrs based on tile ids according to LevelSelectionMenuAttrmap
hlcoord 0, 0 ; apply and commit pals
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
call ApplyPals call ApplyPals
ld a, TRUE ld a, TRUE
ldh [hCGBPalUpdate], a ldh [hCGBPalUpdate], a

View File

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

View File

@ -248,3 +248,100 @@ BlackRGB:
WhiteRGB: 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 jp CloseSRAM
Continue: Continue:
farcall LevelSelectionMenu
farcall TryLoadSaveFile farcall TryLoadSaveFile
jr c, .FailToLoad jr c, .FailToLoad
call LoadStandardMenuHeader call LoadStandardMenuHeader

View File

@ -26,11 +26,13 @@ LevelSelectionMenu::
ld [wLevelSelectionMenuStandingStill], a ld [wLevelSelectionMenuStandingStill], a
call LevelSelectionMenu_InitTilemap call LevelSelectionMenu_InitTilemap
ld b, CGB_LEVEL_SELECTION_MENU call LevelSelectionMenu_InitAttrmap
call GetCGBLayout ; apply and commit attrmap (takes 4 frames) and pals call WaitBGMap2
call SetPalettes
xor a xor a
ldh [hBGMapMode], a ldh [hBGMapMode], a
ld b, CGB_LEVEL_SELECTION_MENU
call GetCGBLayout ; apply and commit pals
call SetPalettes
ld de, MUSIC_GAME_CORNER ld de, MUSIC_GAME_CORNER
call PlayMusic call PlayMusic
@ -122,8 +124,6 @@ LevelSelectionMenu::
call PlaySFX call PlaySFX
call LevelSelectionMenu_Delay10Frames call LevelSelectionMenu_Delay10Frames
call .EnterLevelFadeOut call .EnterLevelFadeOut
ld c, 10
call DelayFrames
ld a, $8 ld a, $8
ld [wMusicFade], a ld [wMusicFade], a
ld a, LOW(MUSIC_NONE) ld a, LOW(MUSIC_NONE)
@ -154,7 +154,8 @@ LevelSelectionMenu::
ret ret
.EnterLevelFadeOut: .EnterLevelFadeOut:
ret ld b, RGBFADE_TO_WHITE_6BGP_2OBP
jp DoRGBFadeEffect
.exit .exit
call LevelSelectionMenu_Delay10Frames call LevelSelectionMenu_Delay10Frames
@ -196,7 +197,7 @@ LevelSelectionMenu_InitTilemap:
.loop .loop
ld a, [de] ld a, [de]
cp $ff ; tilemaps are $ff-terminated cp $ff ; tilemaps are $ff-terminated
jp z, WaitBGMap ; commit tilemap (4 frames) ret z
ld a, [de] ld a, [de]
ld [hli], a ld [hli], a
inc de inc de
@ -208,6 +209,31 @@ LevelSelectionMenu_InitTilemap:
dw LevelSelectionMenuPage3Tilemap dw LevelSelectionMenuPage3Tilemap
dw LevelSelectionMenuPage4Tilemap 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: LevelSelectionMenu_InitPlayerSprite:
; initialize the anim struct of the player's sprite. ; initialize the anim struct of the player's sprite.
; because ClearSpriteAnims was called before, it's always loaded to wSpriteAnim1 ; 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_LEFT EQU $08
DEF PAGE_EDGE_RIGHT EQU $a8 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 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 ; 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 db \1, \2, \3
@ -447,12 +469,10 @@ ENDM
call LevelSelectionMenu_GetNewPage call LevelSelectionMenu_GetNewPage
ld [wLevelSelectionMenuCurrentPage], a ld [wLevelSelectionMenuCurrentPage], a
call LevelSelectionMenu_InitTilemap call LevelSelectionMenu_InitTilemap
ld b, CGB_LEVEL_SELECTION_MENU call LevelSelectionMenu_InitAttrmap
call GetCGBLayout call WaitBGMap2
xor a xor a
ldh [hBGMapMode], a ldh [hBGMapMode], a
ld c, PAGE_CHANGE_NON_FADE_FRAMES
call DelayFrames
call .PageChangeFadeIn call .PageChangeFadeIn
; adjust steps left for the "duplicate" movement of the player leaving and entering a page ; adjust steps left for the "duplicate" movement of the player leaving and entering a page
ld hl, wLevelSelectionMenuMovementStepsLeft ld hl, wLevelSelectionMenuMovementStepsLeft
@ -462,14 +482,12 @@ ENDM
ret ret
.PageChangeFadeOut: .PageChangeFadeOut:
ld c, PAGE_CHANGE_FADE_FRAMES ld b, RGBFADE_TO_BLACK_6BGP
call DelayFrames jp DoRGBFadeEffect
ret
.PageChangeFadeIn: .PageChangeFadeIn:
ld c, PAGE_CHANGE_FADE_FRAMES ld b, RGBFADE_TO_LIGHTER_6BGP
call DelayFrames jp DoRGBFadeEffect
ret
LevelSelectionMenu_GetLandmarkPage: LevelSelectionMenu_GetLandmarkPage:
; Return page number (a) of landmark a. ; Return page number (a) of landmark a.
@ -760,5 +778,8 @@ INCBIN "gfx/level_selection_menu/page_3.tilemap"
LevelSelectionMenuPage4Tilemap: LevelSelectionMenuPage4Tilemap:
INCBIN "gfx/level_selection_menu/page_4.tilemap" INCBIN "gfx/level_selection_menu/page_4.tilemap"
LevelSelectionMenuAttrmap:
INCLUDE "gfx/level_selection_menu/attrmap.asm"
LevelSelectionMenuDirectionalArrowsGFX: LevelSelectionMenuDirectionalArrowsGFX:
INCBIN "gfx/level_selection_menu/directional_arrows.2bpp" 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_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 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 wCreditsTimer:: db
ENDU ENDU
wDefaultSGBLayout:: db wDefaultCGBLayout:: db
wPlayerHPPal:: db wPlayerHPPal:: db
wEnemyHPPal:: db wEnemyHPPal:: db