Level selection menu: begin main loop, and landmark transitions (movements) data (#12)

This commit is contained in:
xCrystal 2023-08-20 19:53:33 +02:00
parent 84d5bdb55d
commit daf9e41557
3 changed files with 169 additions and 14 deletions

View File

@ -13,12 +13,12 @@ ENDM
LevelSelectionMenu_Landmarks:
.landmark1
level_selection_menu_landmark 0, 16, 11, .Level1LandmarkName, SPAWN_LEVEL_1
level_selection_menu_landmark 0, 16, 11, .Level1LandmarkName, SPAWN_LEVEL_1 ; LANDMARK_LEVEL_1
.landmark2
level_selection_menu_landmark 0, 11, 9, .Level2LandmarkName, SPAWN_LEVEL_1
level_selection_menu_landmark 0, 9, 11, .Level3LandmarkName, SPAWN_LEVEL_1
level_selection_menu_landmark 1, 16, 11, .Level4LandmarkName, SPAWN_LEVEL_1
level_selection_menu_landmark 2, 9, 5, .Level5LandmarkName, SPAWN_LEVEL_1
level_selection_menu_landmark 0, 11, 9, .Level2LandmarkName, SPAWN_LEVEL_1 ; LANDMARK_LEVEL_2
level_selection_menu_landmark 0, 9, 11, .Level3LandmarkName, SPAWN_LEVEL_1 ; LANDMARK_LEVEL_3
level_selection_menu_landmark 1, 16, 11, .Level4LandmarkName, SPAWN_LEVEL_1 ; LANDMARK_LEVEL_4
level_selection_menu_landmark 2, 9, 5, .Level5LandmarkName, SPAWN_LEVEL_1 ; LANDMARK_LEVEL_5
.Level1LandmarkName: db "LEVEL 1@"
.Level2LandmarkName: db "LEVEL 2@"
@ -26,6 +26,51 @@ LevelSelectionMenu_Landmarks:
.Level4LandmarkName: db "LEVEL 4@"
.Level5LandmarkName: db "LEVEL 5@"
MACRO level_selection_menu_landmark_transition
; any number of (direction, num_steps (in tiles)) pairs
if (\2 != FALSE)
rept ((_NARG + -1) / 2) ; repeat once for each (direction, num_steps) pair
db (\1 << 6) | (\2 * TILE_WIDTH)
shift
shift
endr
db \1
endc
db -1
ENDM
LevelSelectionMenu_LandmarkTransitions:
; LANDMARK_LEVEL_1
level_selection_menu_landmark_transition DOWN, FALSE
level_selection_menu_landmark_transition UP, FALSE
level_selection_menu_landmark_transition LEFT, 5, UP, 2, LANDMARK_LEVEL_2
level_selection_menu_landmark_transition RIGHT, FALSE
; LANDMARK_LEVEL_2
level_selection_menu_landmark_transition DOWN, 2, RIGHT, 5, LANDMARK_LEVEL_1
level_selection_menu_landmark_transition UP, 3, LEFT, 2, DOWN, 5, LANDMARK_LEVEL_3
level_selection_menu_landmark_transition LEFT, FALSE
level_selection_menu_landmark_transition RIGHT, FALSE
; LANDMARK_LEVEL_3
level_selection_menu_landmark_transition DOWN, 6, LANDMARK_LEVEL_5
level_selection_menu_landmark_transition UP, 5, RIGHT, 2, DOWN, 3, LANDMARK_LEVEL_2
level_selection_menu_landmark_transition LEFT, 7, LEFT, 2, LANDMARK_LEVEL_4
level_selection_menu_landmark_transition RIGHT, 7, LANDMARK_LEVEL_1
; LANDMARK_LEVEL_4
level_selection_menu_landmark_transition DOWN, FALSE
level_selection_menu_landmark_transition UP, FALSE
level_selection_menu_landmark_transition LEFT, FALSE
level_selection_menu_landmark_transition RIGHT, 7, RIGHT, 2, LANDMARK_LEVEL_3
; LANDMARK_LEVEL_5
level_selection_menu_landmark_transition DOWN, FALSE
level_selection_menu_landmark_transition UP, 6, LANDMARK_LEVEL_3
level_selection_menu_landmark_transition LEFT, FALSE
level_selection_menu_landmark_transition RIGHT, FALSE
LevelSelectionMenu_PageGrid:
db -1, -1, -1, -1
db -1, 2, 3, -1

View File

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

View File

@ -1,9 +1,6 @@
LevelSelectionMenu::
ldh a, [hInMenu]
push af
xor a
ldh [hInMenu], a
xor a
ld [wVramState], a
call ClearBGPalettes
@ -29,16 +26,85 @@ LevelSelectionMenu::
ld b, CGB_LEVEL_SELECTION_MENU
call GetCGBLayout ; apply and commit attrmap (takes 4 frames) and pals
call SetPalettes
call LevelSelectionMenu_InitPlayerSprite
ld de, MUSIC_GAME_CORNER
call PlayMusic
.loop
call DelayFrame
jr .loop
call DelayFrame ; wait for pal update
pop af
ldh [hInMenu], a
ld a, [wLevelSelectionMenuCurrentLandmark]
call LevelSelectionMenu_InitPlayerSprite
.main_loop
farcall PlaySpriteAnimations
call DelayFrame
call JoyTextDelay
ld hl, hJoyPressed
ld a, [hl]
bit A_BUTTON_F, a
jp nz, .enter_level
bit B_BUTTON_F, a
jp nz, .exit
ld hl, hJoyLast
ld a, [hl]
bit D_DOWN_F, a
jr nz, .pressed_down
bit D_UP_F, a
jr nz, .pressed_up
bit D_LEFT_F, a
jr nz, .pressed_left
bit D_RIGHT_F, a
jr nz, .pressed_right
jr .main_loop
.pressed_down
.pressed_up
.pressed_left
.pressed_right
jr .main_loop
.enter_level
call LevelSelectionMenu_Delay10Frames
ld de, SFX_WARP_TO
call PlaySFX
call LevelSelectionMenu_Delay10Frames
call .EnterLevelFadeOut
ld c, 10
call DelayFrames
ld a, $8
ld [wMusicFade], a
ld a, LOW(MUSIC_NONE)
ld [wMusicFadeID], a
ld a, HIGH(MUSIC_NONE)
ld [wMusicFadeID + 1], a
call ClearBGPalettes
call ClearTilemap
call ClearSprites
ld c, 20
call DelayFrames
ld a, [wLevelSelectionMenuCurrentLandmark]
ld [wDefaultSpawnpoint], a
call LevelSelectionMenu_GetLandmarkSpawnPoint
ld a, MAPSETUP_WARP
ld [hMapEntryMethod], a
xor a
ld [wDontPlayMapMusicOnReload], a ; play map music
ld [wLinkMode], a
ld a, PLAYER_NORMAL
ld [wPlayerState], a ; this may need to be set on a per-level basis (e.g. if specific level starts with player in surf state)
ld hl, wGameTimerPaused
set GAME_TIMER_PAUSED_F, [hl] ; start game timer counter
farcall OverworldLoop
ret
.EnterLevelFadeOut:
ret
.exit
call LevelSelectionMenu_Delay10Frames
call ClearBGPalettes
call ClearTilemap
call ClearSprites
ret
LevelSelectionMenu_LoadGFX:
@ -80,6 +146,28 @@ LevelSelectionMenu_InitTilemap:
dw LevelSelectionMenuPage4Tilemap
LevelSelectionMenu_InitPlayerSprite:
push af
depixel 0, 0
ld b, SPRITE_ANIM_INDEX_LEVEL_SELECTION_MENU_MALE_WALK_DOWN
ld a, [wPlayerGender]
bit PLAYERGENDER_FEMALE_F, a
jr z, .got_gender
ld b, SPRITE_ANIM_INDEX_LEVEL_SELECTION_MENU_FEMALE_WALK_DOWN
.got_gender
ld a, b
call InitSpriteAnimStruct
ld hl, SPRITEANIMSTRUCT_TILE_ID
add hl, bc
ld [hl], $00
pop af
ld e, a
call LevelSelectionMenu_GetLandmarkCoords
ld hl, SPRITEANIMSTRUCT_XCOORD
add hl, bc
ld [hl], e
ld hl, SPRITEANIMSTRUCT_YCOORD
add hl, bc
ld [hl], d
ret
LevelSelectionMenu_GetLandmarkPage:
@ -135,6 +223,27 @@ LevelSelectionMenu_GetLandmarkName::
pop hl
ret
LevelSelectionMenu_GetLandmarkSpawnPoint:
; Return SPAWN_* (a) of landmark a.
push hl
ld hl, LevelSelectionMenu_Landmarks + $5
ld bc, LevelSelectionMenu_Landmarks.landmark2 - LevelSelectionMenu_Landmarks.landmark1
call AddNTimes
ld a, [hl]
pop hl
ret
LevelSelectionMenu_Delay10Frames:
; Delay 10 frames while playing sprite anims
ld a, 10
.loop
push af
farcall PlaySpriteAnimations
call DelayFrame
pop af
dec a
jr nz, .loop
ret
INCLUDE "data/level_selection_menu.asm"