From 222b46896ccc1ac0e91f866665bb0f1970ad9c46 Mon Sep 17 00:00:00 2001 From: xCrystal Date: Sat, 19 Aug 2023 19:45:43 +0200 Subject: [PATCH] Level selection menu: init screen and bg layout, and preliminary landmarks data (#12) --- data/level_selection_menu.asm | 31 ++++++++ engine/menus/level_selection_menu.asm | 105 ++++++++++++++++++++++++++ ram/wram.asm | 7 ++ 3 files changed, 143 insertions(+) create mode 100755 data/level_selection_menu.asm diff --git a/data/level_selection_menu.asm b/data/level_selection_menu.asm new file mode 100755 index 000000000..93fb8aa01 --- /dev/null +++ b/data/level_selection_menu.asm @@ -0,0 +1,31 @@ +; TILE_WIDTH represents the top/left border tile, $8/$10 represent the OAM screen position offsets, and 10 are custom offsets +DEF LEVELSELECTIONMENU_LANDMARK_OFFSET_X EQU TILE_WIDTH + $8 + 10 +DEF LEVELSELECTIONMENU_LANDMARK_OFFSET_Y EQU TILE_WIDTH + $10 + 10 + +MACRO level_selection_menu_landmark +; page number, xcoord (in tiles), ycoord (in tiles), ptr to name, spawn point (SPAWN_*) + db \1 + db LEVELSELECTIONMENU_LANDMARK_OFFSET_X + \2 * TILE_WIDTH + db LEVELSELECTIONMENU_LANDMARK_OFFSET_Y + \3 * TILE_WIDTH + dw \4 + db \5 +ENDM + +LevelSelectionMenu_Landmarks: +.landmark1 + level_selection_menu_landmark 0, 16, 11, DefaultLandmarkName, SPAWN_LEVEL_1 +.landmark2 + level_selection_menu_landmark 0, 11, 9, DefaultLandmarkName, SPAWN_LEVEL_1 + level_selection_menu_landmark 0, 9, 11, DefaultLandmarkName, SPAWN_LEVEL_1 + level_selection_menu_landmark 1, 16, 11, DefaultLandmarkName, SPAWN_LEVEL_1 + level_selection_menu_landmark 2, 9, 5, DefaultLandmarkName, SPAWN_LEVEL_1 + +LevelSelectionMenu_PageGrid: + db -1, -1, -1, -1 + db -1, 2, 3, -1 + db -1, 0, 1, -1 + db -1, -1, -1, -1 + +DEF LEVELSELECTIONMENU_PAGE_GRID_WIDTH EQU 4 + +DefaultLandmarkName: db "LANDMARK NAME@" diff --git a/engine/menus/level_selection_menu.asm b/engine/menus/level_selection_menu.asm index 704ca2fe3..9f935b8e8 100755 --- a/engine/menus/level_selection_menu.asm +++ b/engine/menus/level_selection_menu.asm @@ -1,3 +1,108 @@ +LevelSelectionMenu:: + ldh a, [hInMenu] + push af + xor a + ldh [hInMenu], a + xor a + ld [wVramState], a + + call ClearBGPalettes + call ClearTilemap + call ClearSprites + ld de, MUSIC_NONE + call PlayMusic + call DelayFrame + call DisableLCD + call LevelSelectionMenu_LoadGFX + farcall ClearSpriteAnims + ld a, LCDC_DEFAULT + ldh [rLCDC], a + + xor a + ld [wLevelSelectionMenuCurrentLandmark], a + call LevelSelectionMenu_GetLandmarkPage + ld [wLevelSelectionMenuCurrentPage], a + + call LevelSelectionMenu_InitTilemap + ld b, CGB_LEVEL_SELECTION_MENU + call GetCGBLayout + call SetPalettes + + ld de, MUSIC_GAME_CORNER + call PlayMusic +.loop + call DelayFrame + jr .loop + + pop af + ldh [hInMenu], a + ret + +LevelSelectionMenu_LoadGFX: + ld hl, LevelSelectionMenuGFX + ld de, vTiles2 + call Decompress + farcall GetPlayerIcon + ld h, d + ld l, e + ld a, b + ld de, vTiles0 + ld bc, 24 tiles + call FarCopyBytes + ret + +LevelSelectionMenu_InitTilemap: +; init tilemap of page at wLevelSelectionMenuCurrentPage + ld hl, .Tilemaps + ld bc, 2 + ld a, [wLevelSelectionMenuCurrentPage] + call AddNTimes + ld e, [hl] + inc hl + ld d, [hl] + hlcoord 0, 0 +.loop + ld a, [de] + cp $ff ; tilemaps are $ff-terminated + jp z, WaitBGMap2 ; takes 8 frames to commit tilemap and attrmap + ld a, [de] + ld [hli], a + inc de + jr .loop + +.Tilemaps: + dw LevelSelectionMenuPage1Tilemap + dw LevelSelectionMenuPage2Tilemap + dw LevelSelectionMenuPage3Tilemap + dw LevelSelectionMenuPage4Tilemap + +LevelSelectionMenu_GetLandmarkPage: +; Return page number (a) of landmark a. + push hl + ld hl, LevelSelectionMenu_Landmarks + ld bc, LevelSelectionMenu_Landmarks.landmark2 - LevelSelectionMenu_Landmarks.landmark1 + call AddNTimes + ld a, [hl] + pop hl + ret + +LevelSelectionMenu_GetLandmarkCoords: +; Return coordinates (d, e) of landmark e. + push hl + push bc + ld hl, LevelSelectionMenu_Landmarks + $1 + ld bc, LevelSelectionMenu_Landmarks.landmark2 - LevelSelectionMenu_Landmarks.landmark1 + ld a, e + call AddNTimes + ld a, [hli] + ld e, a + ld d, [hl] + pop bc + pop hl + ret + +INCLUDE "data/level_selection_menu.asm" + LevelSelectionMenuGFX: INCBIN "gfx/level_selection_menu/background.2bpp.lz" diff --git a/ram/wram.asm b/ram/wram.asm index 486580036..c1be5614a 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1531,6 +1531,13 @@ wDebugColorIsShiny:: db wDebugColorCurTMHM:: db +SECTION UNION "Miscellaneous WRAM 1", WRAMX + +; level selection menu +wLevelSelectionMenuCurrentPage:: db +wLevelSelectionMenuCurrentLandmark:: db + + SECTION UNION "Miscellaneous WRAM 1", WRAMX ; Every previous SECTION UNION takes up 60 or fewer bytes,