diff --git a/graphics/battle_interface/dynamax_trigger.png b/graphics/battle_interface/dynamax_trigger.png new file mode 100644 index 0000000000..18f3a84cff Binary files /dev/null and b/graphics/battle_interface/dynamax_trigger.png differ diff --git a/include/battle.h b/include/battle.h index 91aa7b3f24..f2b9fb04a5 100644 --- a/include/battle.h +++ b/include/battle.h @@ -526,6 +526,7 @@ struct ZMoveData struct DynamaxData { bool8 playerSelect; + u8 triggerSpriteId; bool8 toDynamax[MAX_BATTLERS_COUNT]; bool8 alreadyDynamaxed[NUM_BATTLE_SIDES]; bool8 dynamaxed[MAX_BATTLERS_COUNT]; diff --git a/include/battle_dynamax.h b/include/battle_dynamax.h index 29857d9c40..2fcb0ff402 100644 --- a/include/battle_dynamax.h +++ b/include/battle_dynamax.h @@ -69,5 +69,10 @@ const u8 *GetMaxMoveName(u16 move); void ChooseDamageNonTypesString(u8 type); u32 GetMaxMoveStatusEffect(u16 move); u16 SetMaxMoveEffect(u16 move); +void ChangeDynamaxTriggerSprite(u8 spriteId, u8 animId); +void CreateDynamaxTriggerSprite(u8, bool8); +void HideDynamaxTriggerSprite(void); +bool32 IsDynamaxTriggerSpriteActive(void); +void DestroyDynamaxTriggerSprite(void); #endif diff --git a/include/battle_interface.h b/include/battle_interface.h index e0f30b3097..f222c56e9d 100644 --- a/include/battle_interface.h +++ b/include/battle_interface.h @@ -53,11 +53,16 @@ enum #define TAG_ALPHA_INDICATOR_TILE 0xD779 #define TAG_OMEGA_INDICATOR_TILE 0xD77A #define TAG_ZMOVE_TRIGGER_TILE 0xD77B +#define TAG_DYNAMAX_TRIGGER_TILE 0xD77C +#define TAG_DYNAMAX_INDICATOR_TILE 0xD77D #define TAG_MEGA_TRIGGER_PAL 0xD777 #define TAG_MEGA_INDICATOR_PAL 0xD778 #define TAG_ALPHA_OMEGA_INDICATOR_PAL 0xD779 // Alpha and Omega indicators use the same palette as each of them only uses 4 different colors. #define TAG_ZMOVE_TRIGGER_PAL 0xD77B +#define TAG_DYNAMAX_TRIGGER_PAL 0xD77C +#define TAG_DYNAMAX_INDICATOR_PAL 0xD77D + enum { diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 6619eaff77..2824944896 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -543,7 +543,7 @@ static void HandleInputShowEntireFieldTargets(void) BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[gActiveBattler] | RET_DYNAMAX | (gMultiUsePlayerCursor << 8)); else BtlController_EmitTwoReturnValues(BUFFER_B, 10, gMoveSelectionCursor[gActiveBattler] | (gMultiUsePlayerCursor << 8)); - HideMegaTriggerSprite(); + HideTriggerSprites(); PlayerBufferExecCompleted(); } else if (JOY_NEW(B_BUTTON) || gPlayerDpadHoldFrames > 59) @@ -824,6 +824,7 @@ static void HandleInputChooseMove(void) gBattleStruct->dynamax.playerSelect ^= 1; MoveSelectionDisplayMoveNames(); MoveSelectionCreateCursorAt(gMoveSelectionCursor[gActiveBattler], 0); + ChangeDynamaxTriggerSprite(gBattleStruct->dynamax.triggerSpriteId, gBattleStruct->dynamax.playerSelect); PlaySE(SE_SELECT); } } @@ -2892,6 +2893,10 @@ static void PlayerHandleChooseMove(void) CreateMegaTriggerSprite(gActiveBattler, 0); if (!IsZMoveTriggerSpriteActive()) gBattleStruct->zmove.triggerSpriteId = 0xFF; + if (!IsDynamaxTriggerSpriteActive()) + gBattleStruct->dynamax.triggerSpriteId = 0xFF; + if (CanDynamax(gActiveBattler)) // TODO: handle Dynamax + Mega + Z-Move + CreateDynamaxTriggerSprite(gActiveBattler, 0); GetUsableZMoves(gActiveBattler, moveInfo->moves); gBattleStruct->zmove.viable = IsZMoveUsable(gActiveBattler, gMoveSelectionCursor[gActiveBattler]); diff --git a/src/battle_dynamax.c b/src/battle_dynamax.c index 10f4fd32d6..589e8fd983 100644 --- a/src/battle_dynamax.c +++ b/src/battle_dynamax.c @@ -2,11 +2,14 @@ #include "battle.h" #include "battle_anim.h" #include "battle_controllers.h" +#include "battle_interface.h" #include "battle_scripts.h" #include "battle_script_commands.h" #include "data.h" +#include "graphics.h" #include "pokemon.h" #include "random.h" +#include "sprite.h" #include "string_util.h" #include "util.h" #include "constants/abilities.h" @@ -614,3 +617,185 @@ u16 SetMaxMoveEffect(u16 move) } return effect; } + +// Sprite Data +static const u8 ALIGNED(4) sDynamaxTriggerGfx[] = INCBIN_U8("graphics/battle_interface/dynamax_trigger.4bpp"); +static const u16 sDynamaxTriggerPal[] = INCBIN_U16("graphics/battle_interface/dynamax_trigger.gbapal"); + +static const struct SpriteSheet sSpriteSheet_DynamaxTrigger = +{ + sDynamaxTriggerGfx, sizeof(sDynamaxTriggerGfx), TAG_DYNAMAX_TRIGGER_TILE +}; +static const struct SpritePalette sSpritePalette_DynamaxTrigger = +{ + sDynamaxTriggerPal, TAG_DYNAMAX_TRIGGER_PAL +}; + +static const struct OamData sOamData_DynamaxTrigger = +{ + .y = 0, + .affineMode = 0, + .objMode = 0, + .mosaic = 0, + .bpp = 0, + .shape = ST_OAM_SQUARE, + .x = 0, + .matrixNum = 0, + .size = 2, + .tileNum = 0, + .priority = 1, + .paletteNum = 0, + .affineParam = 0, +}; + +static const union AnimCmd sSpriteAnim_DynamaxTriggerOff[] = +{ + ANIMCMD_FRAME(0, 0), + ANIMCMD_END +}; + +static const union AnimCmd sSpriteAnim_DynamaxTriggerOn[] = +{ + ANIMCMD_FRAME(16, 0), + ANIMCMD_END +}; + +static const union AnimCmd *const sSpriteAnimTable_DynamaxTrigger[] = +{ + sSpriteAnim_DynamaxTriggerOff, + sSpriteAnim_DynamaxTriggerOn, +}; + +static void SpriteCb_DynamaxTrigger(struct Sprite *sprite); +static const struct SpriteTemplate sSpriteTemplate_DynamaxTrigger = +{ + .tileTag = TAG_DYNAMAX_TRIGGER_TILE, + .paletteTag = TAG_DYNAMAX_TRIGGER_PAL, + .oam = &sOamData_DynamaxTrigger, + .anims = sSpriteAnimTable_DynamaxTrigger, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCb_DynamaxTrigger +}; + +// Dynamax Evolution Trigger icon functions. +void ChangeDynamaxTriggerSprite(u8 spriteId, u8 animId) +{ + StartSpriteAnim(&gSprites[spriteId], animId); +} + +#define SINGLES_DYNAMAX_TRIGGER_POS_X_OPTIMAL (30) +#define SINGLES_DYNAMAX_TRIGGER_POS_X_PRIORITY (31) +#define SINGLES_DYNAMAX_TRIGGER_POS_X_SLIDE (15) +#define SINGLES_DYNAMAX_TRIGGER_POS_Y_DIFF (-11) + +#define DOUBLES_DYNAMAX_TRIGGER_POS_X_OPTIMAL (30) +#define DOUBLES_DYNAMAX_TRIGGER_POS_X_PRIORITY (31) +#define DOUBLES_DYNAMAX_TRIGGER_POS_X_SLIDE (15) +#define DOUBLES_DYNAMAX_TRIGGER_POS_Y_DIFF (-4) + +#define tBattler data[0] +#define tHide data[1] + +void CreateDynamaxTriggerSprite(u8 battlerId, u8 palId) +{ + LoadSpritePalette(&sSpritePalette_DynamaxTrigger); + if (GetSpriteTileStartByTag(TAG_DYNAMAX_TRIGGER_TILE) == 0xFFFF) + LoadSpriteSheet(&sSpriteSheet_DynamaxTrigger); + if (gBattleStruct->dynamax.triggerSpriteId == 0xFF) + { + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + gBattleStruct->dynamax.triggerSpriteId = CreateSprite(&sSpriteTemplate_DynamaxTrigger, + gSprites[gHealthboxSpriteIds[battlerId]].x - DOUBLES_DYNAMAX_TRIGGER_POS_X_SLIDE, + gSprites[gHealthboxSpriteIds[battlerId]].y - DOUBLES_DYNAMAX_TRIGGER_POS_Y_DIFF, 0); + else + gBattleStruct->dynamax.triggerSpriteId = CreateSprite(&sSpriteTemplate_DynamaxTrigger, + gSprites[gHealthboxSpriteIds[battlerId]].x - SINGLES_DYNAMAX_TRIGGER_POS_X_SLIDE, + gSprites[gHealthboxSpriteIds[battlerId]].y - SINGLES_DYNAMAX_TRIGGER_POS_Y_DIFF, 0); + } + gSprites[gBattleStruct->dynamax.triggerSpriteId].tBattler = battlerId; + gSprites[gBattleStruct->dynamax.triggerSpriteId].tHide = FALSE; + + ChangeDynamaxTriggerSprite(gBattleStruct->dynamax.triggerSpriteId, palId); +} + +static void SpriteCb_DynamaxTrigger(struct Sprite *sprite) +{ + s32 xSlide, xPriority, xOptimal; + s32 yDiff; + + if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) + { + xSlide = DOUBLES_DYNAMAX_TRIGGER_POS_X_SLIDE; + xPriority = DOUBLES_DYNAMAX_TRIGGER_POS_X_PRIORITY; + xOptimal = DOUBLES_DYNAMAX_TRIGGER_POS_X_OPTIMAL; + yDiff = DOUBLES_DYNAMAX_TRIGGER_POS_Y_DIFF; + } + else + { + xSlide = SINGLES_DYNAMAX_TRIGGER_POS_X_SLIDE; + xPriority = SINGLES_DYNAMAX_TRIGGER_POS_X_PRIORITY; + xOptimal = SINGLES_DYNAMAX_TRIGGER_POS_X_OPTIMAL; + yDiff = SINGLES_DYNAMAX_TRIGGER_POS_Y_DIFF; + } + + if (sprite->tHide) + { + if (sprite->x != gSprites[gHealthboxSpriteIds[sprite->tBattler]].x - xSlide) + sprite->x++; + + if (sprite->x >= gSprites[gHealthboxSpriteIds[sprite->tBattler]].x - xPriority) + sprite->oam.priority = 2; + else + sprite->oam.priority = 1; + + sprite->y = gSprites[gHealthboxSpriteIds[sprite->tBattler]].y - yDiff; + sprite->y2 = gSprites[gHealthboxSpriteIds[sprite->tBattler]].y2 - yDiff; + if (sprite->x == gSprites[gHealthboxSpriteIds[sprite->tBattler]].x - xSlide) + DestroyDynamaxTriggerSprite(); + } + else + { + if (sprite->x != gSprites[gHealthboxSpriteIds[sprite->tBattler]].x - xOptimal) + sprite->x--; + + if (sprite->x >= gSprites[gHealthboxSpriteIds[sprite->tBattler]].x - xPriority) + sprite->oam.priority = 2; + else + sprite->oam.priority = 1; + + sprite->y = gSprites[gHealthboxSpriteIds[sprite->tBattler]].y - yDiff; + sprite->y2 = gSprites[gHealthboxSpriteIds[sprite->tBattler]].y2 - yDiff; + } +} + +bool32 IsDynamaxTriggerSpriteActive(void) +{ + if (GetSpriteTileStartByTag(TAG_DYNAMAX_TRIGGER_TILE) == 0xFFFF) + return FALSE; + else if (IndexOfSpritePaletteTag(TAG_DYNAMAX_TRIGGER_PAL) != 0xFF) + return TRUE; + else + return FALSE; +} + +void HideDynamaxTriggerSprite(void) +{ + if (gBattleStruct->dynamax.triggerSpriteId != 0xFF) + { + ChangeDynamaxTriggerSprite(gBattleStruct->dynamax.triggerSpriteId, 0); + gSprites[gBattleStruct->dynamax.triggerSpriteId].tHide = TRUE; + } +} + +void DestroyDynamaxTriggerSprite(void) +{ + FreeSpritePaletteByTag(TAG_DYNAMAX_TRIGGER_PAL); + FreeSpriteTilesByTag(TAG_DYNAMAX_TRIGGER_TILE); + if (gBattleStruct->dynamax.triggerSpriteId != 0xFF) + DestroySprite(&gSprites[gBattleStruct->dynamax.triggerSpriteId]); + gBattleStruct->dynamax.triggerSpriteId = 0xFF; +} + +#undef tBattler +#undef tHide diff --git a/src/battle_interface.c b/src/battle_interface.c index 35c0e60c63..8bbd26764b 100644 --- a/src/battle_interface.c +++ b/src/battle_interface.c @@ -1413,6 +1413,7 @@ void HideTriggerSprites(void) { HideMegaTriggerSprite(); HideZMoveTriggerSprite(); + HideDynamaxTriggerSprite(); } void DestroyMegaTriggerSprite(void)