pokeemerald/src/evolution_graphics.c

648 lines
19 KiB
C
Raw Normal View History

2017-10-27 14:59:55 +02:00
#include "global.h"
2017-10-27 15:49:14 +02:00
#include "evolution_graphics.h"
2017-10-27 14:59:55 +02:00
#include "sprite.h"
#include "trig.h"
#include "random.h"
2017-10-27 14:59:55 +02:00
#include "decompress.h"
#include "task.h"
#include "sound.h"
2017-12-11 19:27:51 +01:00
#include "constants/songs.h"
2017-10-27 14:59:55 +02:00
#include "palette.h"
2019-04-04 23:05:46 +02:00
#include "constants/rgb.h"
2017-10-27 14:59:55 +02:00
2021-02-03 21:04:25 +01:00
static void SpriteCB_Sparkle_Dummy(struct Sprite* sprite);
static void Task_Sparkles_SpiralUpward_Init(u8 taskId);
static void Task_Sparkles_SpiralUpward(u8 taskId);
static void Task_Sparkles_SpiralUpward_End(u8 taskId);
static void Task_Sparkles_ArcDown_Init(u8 taskId);
static void Task_Sparkles_ArcDown(u8 taskId);
static void Task_Sparkles_ArcDown_End(u8 taskId);
static void Task_Sparkles_CircleInward_Init(u8 taskId);
static void Task_Sparkles_CircleInward(u8 taskId);
static void Task_Sparkles_CircleInward_End(u8 taskId);
static void Task_Sparkles_SprayAndFlash_Init(u8 taskId);
static void Task_Sparkles_SprayAndFlash(u8 taskId);
static void Task_Sparkles_SprayAndFlashTrade_Init(u8 taskId);
static void Task_Sparkles_SprayAndFlashTrade(u8 taskId);
static void Task_Sparkles_SprayAndFlash_End(u8 taskId);
static void Task_CycleEvolutionMonSprite_Init(u8 taskId);
static void Task_CycleEvolutionMonSprite_TryEnd(u8 taskId);
static void Task_CycleEvolutionMonSprite_UpdateSize(u8 taskId);
static void EndOnPreEvoMon(u8 taskId);
static void EndOnPostEvoMon(u8 taskId);
#define TAG_SPARKLE 1001
static const u16 sEvoSparkle_Pal[] = INCBIN_U16("graphics/misc/evo_sparkle.gbapal");
static const u32 sEvoSparkle_Gfx[] = INCBIN_U32("graphics/misc/evo_sparkle.4bpp.lz");
2017-10-27 15:49:14 +02:00
static const struct CompressedSpriteSheet sEvoSparkleSpriteSheets[] =
{
2021-02-03 21:04:25 +01:00
{sEvoSparkle_Gfx, 0x20, TAG_SPARKLE},
2017-10-27 15:49:14 +02:00
{NULL, 0, 0}
};
static const struct SpritePalette sEvoSparkleSpritePals[] =
{
2021-02-03 21:04:25 +01:00
{sEvoSparkle_Pal, TAG_SPARKLE},
2017-10-27 15:49:14 +02:00
{NULL, 0}
};
static const struct OamData sOamData_EvoSparkle =
{
2021-04-15 08:04:01 +02:00
.y = DISPLAY_HEIGHT,
.affineMode = ST_OAM_AFFINE_OFF,
.objMode = ST_OAM_OBJ_NORMAL,
2017-10-27 15:49:14 +02:00
.mosaic = 0,
.bpp = ST_OAM_4BPP,
.shape = SPRITE_SHAPE(8x8),
2017-10-27 15:49:14 +02:00
.x = 0,
.matrixNum = 0,
.size = SPRITE_SIZE(8x8),
2017-10-27 15:49:14 +02:00
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sSpriteAnim_EvoSparkle[] =
{
ANIMCMD_FRAME(0, 8),
ANIMCMD_END
};
static const union AnimCmd *const sSpriteAnimTable_EvoSparkle[] =
{
sSpriteAnim_EvoSparkle,
};
static const struct SpriteTemplate sEvoSparkleSpriteTemplate =
{
2021-02-03 21:04:25 +01:00
.tileTag = TAG_SPARKLE,
.paletteTag = TAG_SPARKLE,
2017-10-27 15:49:14 +02:00
.oam = &sOamData_EvoSparkle,
.anims = sSpriteAnimTable_EvoSparkle,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
2021-02-03 21:04:25 +01:00
.callback = SpriteCB_Sparkle_Dummy
2017-10-27 15:49:14 +02:00
};
2017-10-31 19:28:43 +01:00
static const s16 sEvoSparkleMatrices[] =
2017-10-27 14:59:55 +02:00
{
0x3C0, 0x380, 0x340, 0x300, 0x2C0, 0x280, 0x240, 0x200, 0x1C0,
0x180, 0x140, 0x100, -4, 0x10, -3, 0x30, -2, 0x50,
-1, 0x70, 0x1, 0x70, 0x2, 0x50, 0x3, 0x30, 0x4, 0x10
};
2021-02-03 21:04:25 +01:00
static void SpriteCB_Sparkle_Dummy(struct Sprite *sprite)
2017-10-27 14:59:55 +02:00
{
}
2017-10-27 15:49:14 +02:00
static void SetEvoSparklesMatrices(void)
2017-10-27 14:59:55 +02:00
{
u16 i;
for (i = 0; i < 12; i++)
{
2017-10-31 19:28:43 +01:00
SetOamMatrix(20 + i, sEvoSparkleMatrices[i], 0, 0, sEvoSparkleMatrices[i]);
2017-10-27 14:59:55 +02:00
}
}
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
static void SpriteCB_Sparkle_SpiralUpward(struct Sprite* sprite)
2017-10-27 15:49:14 +02:00
{
2021-07-07 15:11:52 +02:00
if (sprite->y > 8)
2017-10-27 15:49:14 +02:00
{
u8 matrixNum;
2021-07-07 15:11:52 +02:00
sprite->y = 88 - (sprite->data[7] * sprite->data[7]) / 80;
sprite->y2 = Sin((u8)(sprite->data[6]), sprite->data[5]) / 4;
sprite->x2 = Cos((u8)(sprite->data[6]), sprite->data[5]);
2017-12-02 21:44:50 +01:00
sprite->data[6] += 4;
if (sprite->data[7] & 1)
sprite->data[5]--;
sprite->data[7]++;
2021-07-07 15:11:52 +02:00
if (sprite->y2 > 0)
2017-10-27 15:49:14 +02:00
sprite->subpriority = 1;
else
sprite->subpriority = 20;
2017-12-02 21:44:50 +01:00
matrixNum = sprite->data[5] / 4 + 20;
2017-10-27 15:49:14 +02:00
if (matrixNum > 31)
matrixNum = 31;
sprite->oam.matrixNum = matrixNum;
}
else
DestroySprite(sprite);
}
2021-02-03 21:04:25 +01:00
static void CreateSparkle_SpiralUpward(u8 arg0)
2017-10-27 15:49:14 +02:00
{
u8 spriteID = CreateSprite(&sEvoSparkleSpriteTemplate, 120, 88, 0);
if (spriteID != MAX_SPRITES)
{
2017-12-02 21:44:50 +01:00
gSprites[spriteID].data[5] = 48;
gSprites[spriteID].data[6] = arg0;
gSprites[spriteID].data[7] = 0;
gSprites[spriteID].oam.affineMode = ST_OAM_AFFINE_NORMAL;
2017-10-27 15:49:14 +02:00
gSprites[spriteID].oam.matrixNum = 31;
2021-02-03 21:04:25 +01:00
gSprites[spriteID].callback = SpriteCB_Sparkle_SpiralUpward;
2017-10-27 15:49:14 +02:00
}
}
2021-02-03 21:04:25 +01:00
static void SpriteCB_Sparkle_ArcDown(struct Sprite* sprite)
2017-10-27 15:49:14 +02:00
{
2021-07-07 15:11:52 +02:00
if (sprite->y < 88)
2017-10-27 15:49:14 +02:00
{
2021-07-07 15:11:52 +02:00
sprite->y = 8 + (sprite->data[7] * sprite->data[7]) / 5;
sprite->y2 = Sin((u8)(sprite->data[6]), sprite->data[5]) / 4;
sprite->x2 = Cos((u8)(sprite->data[6]), sprite->data[5]);
2017-12-02 21:44:50 +01:00
sprite->data[5] = 8 + Sin((u8)(sprite->data[7] * 4), 40);
sprite->data[7]++;
2017-10-27 15:49:14 +02:00
}
else
DestroySprite(sprite);
}
2021-02-03 21:04:25 +01:00
static void CreateSparkle_ArcDown(u8 arg0)
2017-10-27 15:49:14 +02:00
{
u8 spriteID = CreateSprite(&sEvoSparkleSpriteTemplate, 120, 8, 0);
if (spriteID != MAX_SPRITES)
{
2017-12-02 21:44:50 +01:00
gSprites[spriteID].data[5] = 8;
gSprites[spriteID].data[6] = arg0;
gSprites[spriteID].data[7] = 0;
gSprites[spriteID].oam.affineMode = ST_OAM_AFFINE_NORMAL;
2017-10-27 15:49:14 +02:00
gSprites[spriteID].oam.matrixNum = 25;
gSprites[spriteID].subpriority = 1;
2021-02-03 21:04:25 +01:00
gSprites[spriteID].callback = SpriteCB_Sparkle_ArcDown;
2017-10-27 15:49:14 +02:00
}
}
2021-02-03 21:04:25 +01:00
static void SpriteCB_Sparkle_CircleInward(struct Sprite* sprite)
2017-10-27 15:49:14 +02:00
{
2017-12-02 21:44:50 +01:00
if (sprite->data[5] > 8)
2017-10-27 15:49:14 +02:00
{
2021-07-07 15:11:52 +02:00
sprite->y2 = Sin((u8)(sprite->data[6]), sprite->data[5]);
sprite->x2 = Cos((u8)(sprite->data[6]), sprite->data[5]);
2017-12-02 21:44:50 +01:00
sprite->data[5] -= sprite->data[3];
sprite->data[6] += 4;
2017-10-27 15:49:14 +02:00
}
else
DestroySprite(sprite);
}
2021-02-03 21:04:25 +01:00
static void CreateSparkle_CircleInward(u8 arg0, u8 arg1)
2017-10-27 15:49:14 +02:00
{
u8 spriteID = CreateSprite(&sEvoSparkleSpriteTemplate, 120, 56, 0);
if (spriteID != MAX_SPRITES)
{
2017-12-02 21:44:50 +01:00
gSprites[spriteID].data[3] = arg1;
gSprites[spriteID].data[5] = 120;
gSprites[spriteID].data[6] = arg0;
gSprites[spriteID].data[7] = 0;
gSprites[spriteID].oam.affineMode = ST_OAM_AFFINE_NORMAL;
2017-10-27 15:49:14 +02:00
gSprites[spriteID].oam.matrixNum = 31;
gSprites[spriteID].subpriority = 1;
2021-02-03 21:04:25 +01:00
gSprites[spriteID].callback = SpriteCB_Sparkle_CircleInward;
2017-10-27 15:49:14 +02:00
}
}
2021-02-03 21:04:25 +01:00
static void SpriteCB_Sparkle_Spray(struct Sprite* sprite)
2017-10-27 15:49:14 +02:00
{
2017-12-02 21:44:50 +01:00
if (!(sprite->data[7] & 3))
2021-07-07 15:11:52 +02:00
sprite->y++;
2017-12-02 21:44:50 +01:00
if (sprite->data[6] < 128)
2017-10-27 15:49:14 +02:00
{
u8 matrixNum;
2021-07-07 15:11:52 +02:00
sprite->y2 = -Sin((u8)(sprite->data[6]), sprite->data[5]);
sprite->x = 120 + (sprite->data[3] * sprite->data[7]) / 3;
2017-12-02 21:44:50 +01:00
sprite->data[6]++;
matrixNum = 31 - (sprite->data[6] * 12 / 128);
if (sprite->data[6] > 64)
2017-10-27 15:49:14 +02:00
sprite->subpriority = 1;
else
{
sprite->invisible = FALSE;
2017-10-27 15:49:14 +02:00
sprite->subpriority = 20;
2017-12-02 21:44:50 +01:00
if (sprite->data[6] > 112 && sprite->data[6] & 1)
sprite->invisible = TRUE;
2017-10-27 15:49:14 +02:00
}
if (matrixNum < 20)
matrixNum = 20;
sprite->oam.matrixNum = matrixNum;
2017-12-02 21:44:50 +01:00
sprite->data[7]++;
2017-10-27 15:49:14 +02:00
}
else
DestroySprite(sprite);
}
2021-02-03 21:04:25 +01:00
static void CreateSparkle_Spray(u8 id)
2017-10-27 15:49:14 +02:00
{
u8 spriteID = CreateSprite(&sEvoSparkleSpriteTemplate, 120, 56, 0);
if (spriteID != MAX_SPRITES)
{
2017-12-02 21:44:50 +01:00
gSprites[spriteID].data[3] = 3 - (Random() % 7);
gSprites[spriteID].data[5] = 48 + (Random() & 0x3F);
gSprites[spriteID].data[7] = 0;
gSprites[spriteID].oam.affineMode = ST_OAM_AFFINE_NORMAL;
2017-10-27 15:49:14 +02:00
gSprites[spriteID].oam.matrixNum = 31;
gSprites[spriteID].subpriority = 20;
2021-02-03 21:04:25 +01:00
gSprites[spriteID].callback = SpriteCB_Sparkle_Spray;
2017-10-27 15:49:14 +02:00
}
}
void LoadEvoSparkleSpriteAndPal(void)
{
2018-12-17 23:00:08 +01:00
LoadCompressedSpriteSheetUsingHeap(&sEvoSparkleSpriteSheets[0]);
2017-10-27 15:49:14 +02:00
LoadSpritePalettes(sEvoSparkleSpritePals);
}
2021-02-03 21:04:25 +01:00
#define tPalNum data[1]
#define tTimer data[15]
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
u8 EvolutionSparkles_SpiralUpward(u16 palNum)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
u8 taskId = CreateTask(Task_Sparkles_SpiralUpward_Init, 0);
gTasks[taskId].tPalNum = palNum;
return taskId;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SpiralUpward_Init(u8 taskId)
2017-10-27 15:49:14 +02:00
{
SetEvoSparklesMatrices();
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer = 0;
BeginNormalPaletteFade(3 << gTasks[taskId].tPalNum, 0xA, 0, 0x10, RGB_WHITE);
gTasks[taskId].func = Task_Sparkles_SpiralUpward;
PlaySE(SE_M_MEGA_KICK); // 'Charging up' sound for the sparkles as they spiral upwards
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SpiralUpward(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 64)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (!(gTasks[taskId].tTimer & 7))
2017-10-27 15:49:14 +02:00
{
u8 i;
for (i = 0; i < 4; i++)
2021-02-03 21:04:25 +01:00
CreateSparkle_SpiralUpward((0x78 & gTasks[taskId].tTimer) * 2 + i * 64);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer++;
2017-10-27 15:49:14 +02:00
}
else
{
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer = 96;
gTasks[taskId].func = Task_Sparkles_SpiralUpward_End;
2017-10-27 15:49:14 +02:00
}
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SpiralUpward_End(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer != 0)
gTasks[taskId].tTimer--;
2017-10-27 15:49:14 +02:00
else
2021-02-03 21:04:25 +01:00
DestroyTask(taskId);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
u8 EvolutionSparkles_ArcDown(void)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
return CreateTask(Task_Sparkles_ArcDown_Init, 0);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_ArcDown_Init(u8 taskId)
2017-10-27 15:49:14 +02:00
{
SetEvoSparklesMatrices();
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer = 0;
gTasks[taskId].func = Task_Sparkles_ArcDown;
2020-08-21 00:02:00 +02:00
PlaySE(SE_M_BUBBLE_BEAM2);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_ArcDown(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 96)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 6)
2017-10-27 15:49:14 +02:00
{
u8 i;
for (i = 0; i < 9; i++)
2021-02-03 21:04:25 +01:00
CreateSparkle_ArcDown(i * 16);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer++;
2017-10-27 15:49:14 +02:00
}
else
2021-02-03 21:04:25 +01:00
gTasks[taskId].func = Task_Sparkles_ArcDown_End;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_ArcDown_End(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
DestroyTask(taskId);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
u8 EvolutionSparkles_CircleInward(void)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
return CreateTask(Task_Sparkles_CircleInward_Init, 0);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_CircleInward_Init(u8 taskId)
2017-10-27 15:49:14 +02:00
{
SetEvoSparklesMatrices();
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer = 0;
gTasks[taskId].func = Task_Sparkles_CircleInward;
2020-08-21 00:02:00 +02:00
PlaySE(SE_SHINY);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_CircleInward(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 48)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer == 0)
2017-10-27 15:49:14 +02:00
{
u8 i;
for (i = 0; i < 16; i++)
2021-02-03 21:04:25 +01:00
CreateSparkle_CircleInward(i * 16, 4);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer == 32)
2017-10-27 15:49:14 +02:00
{
u8 i;
for (i = 0; i < 16; i++)
2021-02-03 21:04:25 +01:00
CreateSparkle_CircleInward(i * 16, 8);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer++;
2017-10-27 15:49:14 +02:00
}
else
2021-02-03 21:04:25 +01:00
gTasks[taskId].func = Task_Sparkles_CircleInward_End;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_CircleInward_End(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
DestroyTask(taskId);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
#define tSpecies data[2] // Never read
u8 EvolutionSparkles_SprayAndFlash(u16 species)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
u8 taskId = CreateTask(Task_Sparkles_SprayAndFlash_Init, 0);
gTasks[taskId].tSpecies = species;
return taskId;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SprayAndFlash_Init(u8 taskId)
2017-10-27 15:49:14 +02:00
{
SetEvoSparklesMatrices();
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer = 0;
2017-10-27 15:49:14 +02:00
CpuSet(&gPlttBufferFaded[0x20], &gPlttBufferUnfaded[0x20], 0x30);
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFF9041C, 0, 0, 0x10, RGB_WHITE); // was 0xFFF9001C in R/S
2021-02-03 21:04:25 +01:00
gTasks[taskId].func = Task_Sparkles_SprayAndFlash;
2020-08-21 00:02:00 +02:00
PlaySE(SE_M_PETAL_DANCE);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SprayAndFlash(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 128)
2017-10-27 15:49:14 +02:00
{
u8 i;
2021-02-03 21:04:25 +01:00
switch (gTasks[taskId].tTimer)
2017-10-27 15:49:14 +02:00
{
default:
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 50)
CreateSparkle_Spray(Random() & 7);
2017-10-27 15:49:14 +02:00
break;
case 0:
for (i = 0; i < 8; i++)
2021-02-03 21:04:25 +01:00
CreateSparkle_Spray(i);
2017-10-27 15:49:14 +02:00
break;
case 32:
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFFF041C, 0x10, 0x10, 0, RGB_WHITE); // was 0xFFF9001C in R/S
2017-10-27 15:49:14 +02:00
break;
}
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer++;
2017-10-27 15:49:14 +02:00
}
else
2021-02-03 21:04:25 +01:00
gTasks[taskId].func = Task_Sparkles_SprayAndFlash_End;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SprayAndFlash_End(u8 taskId)
2017-10-27 15:49:14 +02:00
{
if (!gPaletteFade.active)
2021-02-03 21:04:25 +01:00
DestroyTask(taskId);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
// Separate from EvolutionSparkles_SprayAndFlash for difference in fade color
u8 EvolutionSparkles_SprayAndFlash_Trade(u16 species)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
u8 taskId = CreateTask(Task_Sparkles_SprayAndFlashTrade_Init, 0);
gTasks[taskId].tSpecies = species;
return taskId;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SprayAndFlashTrade_Init(u8 taskId)
2017-10-27 15:49:14 +02:00
{
SetEvoSparklesMatrices();
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer = 0;
2017-10-27 15:49:14 +02:00
CpuSet(&gPlttBufferFaded[0x20], &gPlttBufferUnfaded[0x20], 0x30);
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFF90400, 0, 0, 0x10, RGB_WHITE); // was 0xFFFF0001 in R/S
2021-02-03 21:04:25 +01:00
gTasks[taskId].func = Task_Sparkles_SprayAndFlashTrade;
2020-08-21 00:02:00 +02:00
PlaySE(SE_M_PETAL_DANCE);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_Sparkles_SprayAndFlashTrade(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 128)
2017-10-27 15:49:14 +02:00
{
u8 i;
2021-02-03 21:04:25 +01:00
switch (gTasks[taskId].tTimer)
2017-10-27 15:49:14 +02:00
{
default:
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tTimer < 50)
CreateSparkle_Spray(Random() & 7);
2017-10-27 15:49:14 +02:00
break;
case 0:
for (i = 0; i < 8; i++)
2021-02-03 21:04:25 +01:00
CreateSparkle_Spray(i);
2017-10-27 15:49:14 +02:00
break;
case 32:
2019-04-04 23:05:46 +02:00
BeginNormalPaletteFade(0xFFFF0400, 0x10, 0x10, 0, RGB_WHITE); // was 0xFFFF0001 in R/S
2017-10-27 15:49:14 +02:00
break;
}
2021-02-03 21:04:25 +01:00
gTasks[taskId].tTimer++;
2017-10-27 15:49:14 +02:00
}
else
2021-02-03 21:04:25 +01:00
gTasks[taskId].func = Task_Sparkles_SprayAndFlash_End;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
#undef tTimer
#undef tSpecies
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
static void SpriteCB_EvolutionMonSprite(struct Sprite* sprite)
2017-10-27 15:49:14 +02:00
{
}
2021-02-03 21:04:25 +01:00
#define tPreEvoSpriteId data[1]
#define tPostEvoSpriteId data[2]
#define tPreEvoScale data[3]
#define tPostEvoScale data[4]
#define tShowingPostEvo data[5]
#define tScaleSpeed data[6]
2017-10-27 15:49:14 +02:00
#define tEvoStopped data[8]
2021-02-03 21:04:25 +01:00
#define MATRIX_PRE_EVO 30
#define MATRIX_POST_EVO 31
#define MON_MAX_SCALE 256
#define MON_MIN_SCALE 16
// Alternately grow/shrink the pre-evolution and post-evolution mon sprites
u8 CycleEvolutionMonSprite(u8 preEvoSpriteId, u8 postEvoSpriteId)
2017-10-27 15:49:14 +02:00
{
u16 i;
u16 stack[16];
2021-02-03 21:04:25 +01:00
u8 taskId;
2017-10-27 15:49:14 +02:00
s32 toDiv;
2021-02-03 21:04:25 +01:00
for (i = 0; i < ARRAY_COUNT(stack); i++)
2017-10-27 15:49:14 +02:00
stack[i] = 0x7FFF;
2021-02-03 21:04:25 +01:00
taskId = CreateTask(Task_CycleEvolutionMonSprite_Init, 0);
gTasks[taskId].tPreEvoSpriteId = preEvoSpriteId;
gTasks[taskId].tPostEvoSpriteId = postEvoSpriteId;
gTasks[taskId].tPreEvoScale = MON_MAX_SCALE;
gTasks[taskId].tPostEvoScale = MON_MIN_SCALE;
2017-10-27 15:49:14 +02:00
toDiv = 65536;
2021-02-03 21:04:25 +01:00
SetOamMatrix(MATRIX_PRE_EVO, MON_MAX_SCALE, 0, 0, MON_MAX_SCALE);
SetOamMatrix(MATRIX_POST_EVO, toDiv / gTasks[taskId].tPostEvoScale, 0, 0, toDiv / gTasks[taskId].tPostEvoScale);
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
gSprites[preEvoSpriteId].callback = SpriteCB_EvolutionMonSprite;
gSprites[preEvoSpriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
gSprites[preEvoSpriteId].oam.matrixNum = MATRIX_PRE_EVO;
gSprites[preEvoSpriteId].invisible = FALSE;
CpuSet(stack, &gPlttBufferFaded[0x100 + (gSprites[preEvoSpriteId].oam.paletteNum * 16)], 16);
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
gSprites[postEvoSpriteId].callback = SpriteCB_EvolutionMonSprite;
gSprites[postEvoSpriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
gSprites[postEvoSpriteId].oam.matrixNum = MATRIX_POST_EVO;
gSprites[postEvoSpriteId].invisible = FALSE;
CpuSet(stack, &gPlttBufferFaded[0x100 + (gSprites[postEvoSpriteId].oam.paletteNum * 16)], 16);
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
gTasks[taskId].tEvoStopped = FALSE;
return taskId;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void Task_CycleEvolutionMonSprite_Init(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
gTasks[taskId].tShowingPostEvo = FALSE;
gTasks[taskId].tScaleSpeed = 8;
gTasks[taskId].func = Task_CycleEvolutionMonSprite_TryEnd;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
// Try to end sprite cycling
// If evo hasn't stopped or growth/shrink speed hasn't been maxed out, start another cycle
static void Task_CycleEvolutionMonSprite_TryEnd(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tEvoStopped)
EndOnPreEvoMon(taskId);
else if (gTasks[taskId].tScaleSpeed == 128)
EndOnPostEvoMon(taskId);
2017-10-27 15:49:14 +02:00
else
{
2021-02-03 21:04:25 +01:00
gTasks[taskId].tScaleSpeed += 2;
gTasks[taskId].tShowingPostEvo ^= 1;
gTasks[taskId].func = Task_CycleEvolutionMonSprite_UpdateSize;
2017-10-27 15:49:14 +02:00
}
}
2021-02-03 21:04:25 +01:00
static void Task_CycleEvolutionMonSprite_UpdateSize(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
if (gTasks[taskId].tEvoStopped)
gTasks[taskId].func = EndOnPreEvoMon;
2017-10-27 15:49:14 +02:00
else
{
u16 oamMatrixArg;
2021-02-03 21:04:25 +01:00
u8 numSpritesFinished = 0;
if (!gTasks[taskId].tShowingPostEvo)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
// Set pre-evo sprite growth
if (gTasks[taskId].tPreEvoScale < MON_MAX_SCALE - gTasks[taskId].tScaleSpeed)
gTasks[taskId].tPreEvoScale += gTasks[taskId].tScaleSpeed;
2017-10-27 15:49:14 +02:00
else
{
2021-02-03 21:04:25 +01:00
gTasks[taskId].tPreEvoScale = MON_MAX_SCALE;
numSpritesFinished++;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
// Set post-evo sprite shrink
if (gTasks[taskId].tPostEvoScale > MON_MIN_SCALE + gTasks[taskId].tScaleSpeed)
gTasks[taskId].tPostEvoScale -= gTasks[taskId].tScaleSpeed;
2017-10-27 15:49:14 +02:00
else
{
2021-02-03 21:04:25 +01:00
gTasks[taskId].tPostEvoScale = MON_MIN_SCALE;
numSpritesFinished++;
2017-10-27 15:49:14 +02:00
}
}
else
{
2021-02-03 21:04:25 +01:00
// Set post-evo sprite growth
if (gTasks[taskId].tPostEvoScale < MON_MAX_SCALE - gTasks[taskId].tScaleSpeed)
gTasks[taskId].tPostEvoScale += gTasks[taskId].tScaleSpeed;
2017-10-27 15:49:14 +02:00
else
{
2021-02-03 21:04:25 +01:00
gTasks[taskId].tPostEvoScale = MON_MAX_SCALE;
numSpritesFinished++;
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
// Set pre-evo sprite shrink
if (gTasks[taskId].tPreEvoScale > MON_MIN_SCALE + gTasks[taskId].tScaleSpeed)
gTasks[taskId].tPreEvoScale -= gTasks[taskId].tScaleSpeed;
2017-10-27 15:49:14 +02:00
else
{
2021-02-03 21:04:25 +01:00
gTasks[taskId].tPreEvoScale = MON_MIN_SCALE;
numSpritesFinished++;
2017-10-27 15:49:14 +02:00
}
}
2021-02-03 21:04:25 +01:00
// Grow/shrink pre-evo sprite
oamMatrixArg = 65536 / gTasks[taskId].tPreEvoScale;
SetOamMatrix(MATRIX_PRE_EVO, oamMatrixArg, 0, 0, oamMatrixArg);
// Grow/shrink post-evo sprite
oamMatrixArg = 65536 / gTasks[taskId].tPostEvoScale;
SetOamMatrix(MATRIX_POST_EVO, oamMatrixArg, 0, 0, oamMatrixArg);
// Both sprites have reached their size extreme
if (numSpritesFinished == 2)
gTasks[taskId].func = Task_CycleEvolutionMonSprite_TryEnd;
2017-10-27 15:49:14 +02:00
}
}
2021-02-03 21:04:25 +01:00
static void EndOnPostEvoMon(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
gSprites[gTasks[taskId].tPreEvoSpriteId].oam.affineMode = ST_OAM_AFFINE_OFF;
gSprites[gTasks[taskId].tPreEvoSpriteId].oam.matrixNum = 0;
gSprites[gTasks[taskId].tPreEvoSpriteId].invisible = TRUE;
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
gSprites[gTasks[taskId].tPostEvoSpriteId].oam.affineMode = ST_OAM_AFFINE_OFF;
gSprites[gTasks[taskId].tPostEvoSpriteId].oam.matrixNum = 0;
gSprites[gTasks[taskId].tPostEvoSpriteId].invisible = FALSE;
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
DestroyTask(taskId);
2017-10-27 15:49:14 +02:00
}
2021-02-03 21:04:25 +01:00
static void EndOnPreEvoMon(u8 taskId)
2017-10-27 15:49:14 +02:00
{
2021-02-03 21:04:25 +01:00
gSprites[gTasks[taskId].tPreEvoSpriteId].oam.affineMode = ST_OAM_AFFINE_OFF;
gSprites[gTasks[taskId].tPreEvoSpriteId].oam.matrixNum = 0;
gSprites[gTasks[taskId].tPreEvoSpriteId].invisible = FALSE;
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
gSprites[gTasks[taskId].tPostEvoSpriteId].oam.affineMode = ST_OAM_AFFINE_OFF;
gSprites[gTasks[taskId].tPostEvoSpriteId].oam.matrixNum = 0;
gSprites[gTasks[taskId].tPostEvoSpriteId].invisible = TRUE;
2017-10-27 15:49:14 +02:00
2021-02-03 21:04:25 +01:00
DestroyTask(taskId);
2017-10-27 15:49:14 +02:00
}