From db7d9c70639c21fc9d2482f53c42621ae51ba50d Mon Sep 17 00:00:00 2001 From: xCrystal Date: Mon, 25 Sep 2023 21:57:47 +0200 Subject: [PATCH] Board menu: die roll input and animation (#11) --- charmap.asm | 1 + constants/gfx_constants.asm | 12 ++++--- constants/wram_constants.asm | 1 + data/sprites/secondary_sprites.asm | 32 ++++++++++++++++++ engine/board/menu.asm | 51 ++++++++++++++++++++++++++++- engine/gfx/load_board_gfx.asm | 7 ++++ engine/overworld/events.asm | 1 - engine/overworld/map_objects.asm | 32 ++++++++++++++++-- gfx/board/die_roll.png | Bin 0 -> 579 bytes ram/hram.asm | 1 - ram/wram.asm | 5 +++ 11 files changed, 134 insertions(+), 9 deletions(-) create mode 100755 gfx/board/die_roll.png diff --git a/charmap.asm b/charmap.asm index 2cfe7086c..2b4d57d6f 100644 --- a/charmap.asm +++ b/charmap.asm @@ -188,3 +188,4 @@ DEF BOARD_MENU_BG_FIRST_TILE EQU "A" ; Object tile locations (vTiles0) DEF SECONDARY_SPRITES_FIRST_TILE EQU $20 DEF BOARD_MENU_OAM_FIRST_TILE EQU SECONDARY_SPRITES_FIRST_TILE +DEF DIE_ROLL_OAM_FIRST_TILE EQU BOARD_MENU_OAM_FIRST_TILE + 45 ; BOARD_MENU_ITEM_SIZE * NUM_BOARD_MENU_ITEMS diff --git a/constants/gfx_constants.asm b/constants/gfx_constants.asm index ae84f528c..cafed0baa 100644 --- a/constants/gfx_constants.asm +++ b/constants/gfx_constants.asm @@ -59,11 +59,15 @@ DEF SPRITE_GFX_LIST_CAPACITY EQU 1 + WALKING_SPRITE_GFX_LIST_CAPACITY + STILL_SP const ANIM_MON_EGG1 const ANIM_MON_EGG2 -BOARD_MENU_ITEM_WIDTH EQU 3 -BOARD_MENU_ITEM_HEIGHT EQU 3 -BOARD_MENU_ITEM_SIZE EQU BOARD_MENU_ITEM_WIDTH * BOARD_MENU_ITEM_HEIGHT - ; LoadHUD indexes (see engine/gfx/hud.asm) const_def 1 const HUD_OVERWORLD ; 1 DEF NUM_HUD_TYPES EQU const_value - 1 + +; board menu graphics +BOARD_MENU_ITEM_WIDTH EQU 3 +BOARD_MENU_ITEM_HEIGHT EQU 3 +BOARD_MENU_ITEM_SIZE EQU BOARD_MENU_ITEM_WIDTH * BOARD_MENU_ITEM_HEIGHT +DIE_WIDTH EQU 2 +DIE_HEIGHT EQU 2 +DIE_SIZE EQU DIE_WIDTH * DIE_HEIGHT diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm index b3faed109..c1648ad1e 100644 --- a/constants/wram_constants.asm +++ b/constants/wram_constants.asm @@ -9,6 +9,7 @@ DEF AUTO_INPUT EQU $ff ; wDisplaySecondarySprites const_def const SECONDARYSPRITES_BOARD_MENU_F ; 0 + const SECONDARYSPRITES_DIE_ROLL_F ; 1 ; wCurDexMode:: const_def diff --git a/data/sprites/secondary_sprites.asm b/data/sprites/secondary_sprites.asm index 4ef9e7bf8..5bc16a89c 100755 --- a/data/sprites/secondary_sprites.asm +++ b/data/sprites/secondary_sprites.asm @@ -49,3 +49,35 @@ BoardMenuOAM: dbsprite 16, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 42, PAL_OW_MISC dbsprite 17, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 43, PAL_OW_MISC dbsprite 18, 18, 4, 0, BOARD_MENU_OAM_FIRST_TILE + 44, PAL_OW_MISC + +DieRollOAM: +; 1 + dbsprite 9, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE, PAL_OW_MISC + dbsprite 10, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 1, PAL_OW_MISC + dbsprite 9, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 20, PAL_OW_MISC + dbsprite 10, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 21, PAL_OW_MISC +; 2 + dbsprite 9, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 2, PAL_OW_MISC + dbsprite 10, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 3, PAL_OW_MISC + dbsprite 9, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 22, PAL_OW_MISC + dbsprite 10, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 23, PAL_OW_MISC +; 3 + dbsprite 9, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 4, PAL_OW_MISC + dbsprite 10, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 5, PAL_OW_MISC + dbsprite 9, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 24, PAL_OW_MISC + dbsprite 10, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 25, PAL_OW_MISC +; 4 + dbsprite 9, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 6, PAL_OW_MISC + dbsprite 10, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 7, PAL_OW_MISC + dbsprite 9, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 26, PAL_OW_MISC + dbsprite 10, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 27, PAL_OW_MISC +; 5 + dbsprite 9, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 8, PAL_OW_MISC + dbsprite 10, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 9, PAL_OW_MISC + dbsprite 9, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 28, PAL_OW_MISC + dbsprite 10, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 29, PAL_OW_MISC +; 6 + dbsprite 9, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 10, PAL_OW_MISC + dbsprite 10, 7, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 11, PAL_OW_MISC + dbsprite 9, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 30, PAL_OW_MISC + dbsprite 10, 8, 0, 0, DIE_ROLL_OAM_FIRST_TILE + 31, PAL_OW_MISC diff --git a/engine/board/menu.asm b/engine/board/menu.asm index f0c2390f9..b51e34e75 100755 --- a/engine/board/menu.asm +++ b/engine/board/menu.asm @@ -11,7 +11,9 @@ BoardMenuScript:: end .Die: - closetext + callasm BoardMenu_Die + iffalse BoardMenuScript + callasm BoardMenu_BreakDieAnimation end .Party: @@ -180,6 +182,50 @@ GetBoardMenuSelection: xor a ret ; nc +BoardMenu_Die: +DIE_MAX_NUMBER EQU 6 + ld hl, wDisplaySecondarySprites + set SECONDARYSPRITES_DIE_ROLL_F, [hl] + ld a, 1 + ld [wDieRoll], a + call HDMATransferTilemapAndAttrmap_OpenAndCloseMenu ; + call CloseText ; closetext + +.rotate_die_loop + call IsSFXPlaying + ld de, SFX_KINESIS + call c, PlaySFX + call Random +.sample_die_loop + sub DIE_MAX_NUMBER + jr nc, .sample_die_loop + add DIE_MAX_NUMBER + add $1 + ld [wDieRoll], a + farcall _UpdateSprites + call GetJoypad + ldh a, [hJoyPressed] + bit B_BUTTON_F, a + jr nz, .back_to_menu + bit A_BUTTON_F, a + jr nz, .confirm_roll + call DelayFrame + jr .rotate_die_loop + +.back_to_menu + call PlayClickSFX + ld hl, wDisplaySecondarySprites + res SECONDARYSPRITES_DIE_ROLL_F, [hl] + xor a ; FALSE + ld [wScriptVar], a + ret + +.confirm_roll + call PlayClickSFX + ld a, TRUE + ld [wScriptVar], a + ret + BoardMenu_Party: ld a, [wPartyCount] and a @@ -201,6 +247,9 @@ BoardMenu_Party: ldh [hMenuReturn], a ret +BoardMenu_BreakDieAnimation: + ret + BoardMenu_Pack: call BoardMenu_OpenSubmenu farcall Pack diff --git a/engine/gfx/load_board_gfx.asm b/engine/gfx/load_board_gfx.asm index c76de68e2..808d6271b 100755 --- a/engine/gfx/load_board_gfx.asm +++ b/engine/gfx/load_board_gfx.asm @@ -7,6 +7,10 @@ LoadBoardMenuGFX:: ld hl, vTiles0 + BOARD_MENU_OAM_FIRST_TILE * LEN_2BPP_TILE lb bc, BANK(.BoardMenuOAMGFX), BOARD_MENU_ITEM_SIZE * NUM_BOARD_MENU_ITEMS call Get2bppViaHDMA + ld de, .DieRollOAMGFX + ld hl, vTiles0 + DIE_ROLL_OAM_FIRST_TILE * LEN_2BPP_TILE + lb bc, BANK(.BoardMenuOAMGFX), DIE_SIZE * 10 + call Get2bppViaHDMA ret .BoardMenuGFX: @@ -20,3 +24,6 @@ INCBIN "gfx/board/menu_pack.2bpp" INCBIN "gfx/board/menu_pokegear.2bpp" INCBIN "gfx/board/menu_exit.2bpp" assert_table_length NUM_BOARD_MENU_ITEMS + +.DieRollOAMGFX: +INCBIN "gfx/board/die_roll.2bpp" \ No newline at end of file diff --git a/engine/overworld/events.asm b/engine/overworld/events.asm index 2c4fb4615..3e6fd25b3 100644 --- a/engine/overworld/events.asm +++ b/engine/overworld/events.asm @@ -807,7 +807,6 @@ PlayerMovementPointers: CheckMenuOW: xor a ldh [hMenuReturn], a - ldh [hUnusedByte], a ldh a, [hJoyPressed] bit SELECT_F, a diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 76935b596..2728c4afc 100644 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -3074,10 +3074,12 @@ InitSprites: InitSecondarySprites: ld a, [wDisplaySecondarySprites] bit SECONDARYSPRITES_BOARD_MENU_F, a - call nz, .InitBoardMenuSprites + call nz, InitBoardMenuSprites + bit SECONDARYSPRITES_DIE_ROLL_F, a + call nz, InitRollDieSprites ret -.InitBoardMenuSprites: +InitBoardMenuSprites: push af ld hl, BoardMenuOAM @@ -3102,4 +3104,30 @@ InitSecondarySprites: pop af ret +InitRollDieSprites: + push af + + ld hl, DieRollOAM + ld a, [wDieRoll] + dec a + ld bc, DIE_SIZE * SPRITEOAMSTRUCT_LENGTH + call AddNTimes +; find the beginning of free space in OAM, and assure there's space for a DIE_SIZE object + ldh a, [hUsedSpriteIndex] + cp (NUM_SPRITE_OAM_STRUCTS * SPRITEOAMSTRUCT_LENGTH) - (DIE_SIZE * SPRITEOAMSTRUCT_LENGTH) + 1 + jr nc, .oam_full +; copy the sprite data (DIE_SIZE objects) of that item to the available space in OAM + ld e, a + ld d, HIGH(wShadowOAM) + ld bc, DIE_SIZE * SPRITEOAMSTRUCT_LENGTH + call CopyBytes + + ldh a, [hUsedSpriteIndex] + add (DIE_SIZE * SPRITEOAMSTRUCT_LENGTH) + ldh [hUsedSpriteIndex], a + +.oam_full + pop af + ret + INCLUDE "data/sprites/secondary_sprites.asm" diff --git a/gfx/board/die_roll.png b/gfx/board/die_roll.png new file mode 100755 index 0000000000000000000000000000000000000000..256ed21aaf767a4ea3b8bfab89d7212f8f5650c9 GIT binary patch literal 579 zcmV-J0=)f+P)000mO1^@s6kp*;E00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj532;bRa{vGmbN~PnbOGLGA9w%&0oX}IK~!i%?V8X!0wR<3Kv`GnW$ z7%5+mff^sk@!I;2&JS9A*)y>?e1BNKM$k!0frn%$iiM%5QnZhsA!>YLtsm(6Yj{Qd zN9J$w<(!wqi8i1N^ohuuZv`>*4p2j_-%wZ6o1|3KDYsb4yw8e+b@mfvIN!-qcy-eyWbW z^K;%oXdY|xGaj3e{w_Np3(hU#Uf^cs%c%qF_pTj#+>TGMiO{Kf_bCOgr5V{YM>TS5 z{%@_H*Xy21#rf(#L~GoCzyGHJHRxD?j<(>w`yk~Hv45p00j~S*TbZV*`vIA98>bik RhRXl|002ovPDHLkV1g?J5@`Sc literal 0 HcmV?d00001 diff --git a/ram/hram.asm b/ram/hram.asm index 22b07f59b..57710930b 100644 --- a/ram/hram.asm +++ b/ram/hram.asm @@ -12,7 +12,6 @@ hVBlank:: db hMapEntryMethod:: db hMenuReturn:: db -hUnusedByte:: db hJoypadReleased:: db hJoypadPressed:: db diff --git a/ram/wram.asm b/ram/wram.asm index d3b36ef22..b58b2c4e3 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -2240,6 +2240,11 @@ wBugContestSecsRemaining:: db wMapStatusEnd:: +wTurnData:: +wDieRoll:: db +wSpacesLeft:: db +wTurnDataEnd:: + wGameData:: wPlayerData:: wPlayerID:: dw