2020-04-08 23:23:32 +02:00
|
|
|
#include "global.h"
|
|
|
|
#include "decompress.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "link_rfu.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "trig.h"
|
2021-03-11 20:16:40 +01:00
|
|
|
#include "minigame_countdown.h"
|
2020-04-08 23:23:32 +02:00
|
|
|
#include "constants/songs.h"
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
/*
|
|
|
|
This file contains two types of '3-2-1 Start' countdowns intended for use by the wireless minigames.
|
|
|
|
|
|
|
|
One is static, where the numbers simply appear and disappear without moving. This version is unused.
|
|
|
|
The other (used) version has the numbers squish and bounce up as they appear.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define TAG_STATIC_COUNTDOWN 0x2000
|
|
|
|
|
|
|
|
enum {
|
|
|
|
STATE_IDLE = 1,
|
|
|
|
STATE_START,
|
|
|
|
STATE_RUN,
|
|
|
|
STATE_END,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FUNC_INIT,
|
|
|
|
FUNC_FREE,
|
|
|
|
FUNC_START,
|
|
|
|
FUNC_RUN,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ANIM_THREE,
|
|
|
|
ANIM_TWO,
|
|
|
|
ANIM_ONE,
|
|
|
|
ANIM_START_LEFT,
|
|
|
|
ANIM_START_MID,
|
|
|
|
ANIM_START_RIGHT,
|
|
|
|
};
|
|
|
|
|
2020-04-08 23:23:32 +02:00
|
|
|
extern const struct OamData gOamData_AffineOff_ObjNormal_32x32;
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static void Task_StaticCountdown(u8 taskId);
|
|
|
|
static void Task_StaticCountdown_Init(u8 taskId);
|
|
|
|
static void Task_StaticCountdown_Free(u8 taskId);
|
|
|
|
static void Task_StaticCountdown_Start(u8 taskId);
|
|
|
|
static void Task_StaticCountdown_Run(u8 taskId);
|
2020-04-08 23:23:32 +02:00
|
|
|
|
2021-03-16 10:40:42 +01:00
|
|
|
static const u16 s321Start_Static_Pal[] = INCBIN_U16("graphics/minigame_countdown/321start_static.gbapal");
|
|
|
|
static const u32 s321Start_Static_Gfx[] = INCBIN_U32("graphics/minigame_countdown/321start_static.4bpp.lz");
|
2020-04-08 23:23:32 +02:00
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const struct CompressedSpriteSheet sSpriteSheet_321Start_Static[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
{s321Start_Static_Gfx, 0xC00, TAG_STATIC_COUNTDOWN},
|
2020-04-08 23:23:32 +02:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const struct SpritePalette sSpritePalette_321Start_Static[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
{s321Start_Static_Pal, TAG_STATIC_COUNTDOWN},
|
2020-04-08 23:23:32 +02:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AnimCmd sAnim_StaticCountdown_Three[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AnimCmd sAnim_StaticCountdown_Two[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(16, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AnimCmd sAnim_StaticCountdown_One[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(32, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AnimCmd sAnim_StaticCountdown_StartLeft[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(64, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AnimCmd sAnim_StaticCountdown_StartMid[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(48, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AnimCmd sAnim_StaticCountdown_StartRight[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(80, 0),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AnimCmd *const sAnims_StaticCountdown[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
[ANIM_THREE] = sAnim_StaticCountdown_Three,
|
|
|
|
[ANIM_TWO] = sAnim_StaticCountdown_Two,
|
|
|
|
[ANIM_ONE] = sAnim_StaticCountdown_One,
|
|
|
|
[ANIM_START_LEFT] = sAnim_StaticCountdown_StartLeft,
|
|
|
|
[ANIM_START_MID] = sAnim_StaticCountdown_StartMid,
|
|
|
|
[ANIM_START_RIGHT] = sAnim_StaticCountdown_StartRight
|
2020-04-08 23:23:32 +02:00
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const struct SpriteTemplate sSpriteTemplate_StaticCountdown[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
.tileTag = TAG_STATIC_COUNTDOWN,
|
|
|
|
.paletteTag = TAG_STATIC_COUNTDOWN,
|
2020-04-08 23:23:32 +02:00
|
|
|
.oam = &gOamData_AffineOff_ObjNormal_32x32,
|
2021-03-11 20:16:40 +01:00
|
|
|
.anims = sAnims_StaticCountdown,
|
2020-04-08 23:23:32 +02:00
|
|
|
.images = NULL,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
|
|
|
.callback = SpriteCallbackDummy,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const TaskFunc sStaticCountdownFuncs[][4] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
[FUNC_INIT] = Task_StaticCountdown_Init,
|
|
|
|
[FUNC_FREE] = Task_StaticCountdown_Free,
|
|
|
|
[FUNC_START] = Task_StaticCountdown_Start,
|
|
|
|
[FUNC_RUN] = Task_StaticCountdown_Run
|
2020-04-08 23:23:32 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
#define tState data[0]
|
|
|
|
#define tFuncSetId data[1] // These 4 data elements are indexes into
|
|
|
|
#define tSpriteTemplateId data[2] // arrays that only have 1 element with
|
|
|
|
#define tSpriteSheetId data[3] // data. As such their only legal value
|
|
|
|
#define tSpritePalId data[4] // is 0. Unclear why they were used.
|
|
|
|
#define tInterval data[5]
|
|
|
|
#define tPriority data[6]
|
|
|
|
#define tSubpriority data[7]
|
|
|
|
#define tNumSprites data[8]
|
|
|
|
#define tX data[9]
|
|
|
|
#define tY data[10]
|
|
|
|
#define tPrevTime data[10] // Re-used
|
|
|
|
#define tTimer data[11]
|
|
|
|
#define tLinkTimer data[12]
|
|
|
|
// 13-15 hold sprite ids
|
|
|
|
// tSpriteIds(0) is used for the number sprites, and the leftmost part of 'Start'
|
|
|
|
// tSpriteIds(1) is used for the middle part of 'Start'
|
|
|
|
// tSpriteIds(2) is used for for the rightmost part of 'Start'
|
|
|
|
#define tSpriteIds(i) data[13 + i]
|
|
|
|
|
|
|
|
#define sInterval data[1] // Never read
|
|
|
|
#define sAnimNum data[2]
|
|
|
|
#define sTaskId data[3]
|
|
|
|
#define sId data[4] // Never read
|
|
|
|
#define sNumberSpriteId data[5] // Never read
|
2020-04-08 23:23:32 +02:00
|
|
|
|
|
|
|
// Unused
|
2021-03-11 20:16:40 +01:00
|
|
|
static u32 CreateStaticCountdownTask(u8 funcSetId, u8 taskPriority)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
u8 taskId = CreateTask(Task_StaticCountdown, taskPriority);
|
2020-04-08 23:23:32 +02:00
|
|
|
struct Task *task = &gTasks[taskId];
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
task->tState = STATE_IDLE;
|
|
|
|
task->tFuncSetId = funcSetId;
|
|
|
|
sStaticCountdownFuncs[funcSetId][FUNC_INIT](taskId);
|
2020-04-08 23:23:32 +02:00
|
|
|
return taskId;
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static bool32 StartStaticCountdown(void)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
u8 taskId = FindTaskIdByFunc(Task_StaticCountdown);
|
2021-02-20 05:22:26 +01:00
|
|
|
if (taskId == TASK_NONE)
|
2020-04-08 23:23:32 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
gTasks[taskId].tState = STATE_START;
|
2020-04-08 23:23:32 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static bool32 IsStaticCountdownRunning(void)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
return FuncIsActiveTask(Task_StaticCountdown);
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static void Task_StaticCountdown(u8 taskId)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
switch (tState)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// STATE_IDLE does nothing; wait until started
|
|
|
|
case STATE_START:
|
|
|
|
sStaticCountdownFuncs[tFuncSetId][FUNC_START](taskId);
|
|
|
|
tState = STATE_RUN;
|
2020-04-08 23:23:32 +02:00
|
|
|
break;
|
2021-03-11 20:16:40 +01:00
|
|
|
case STATE_RUN:
|
|
|
|
sStaticCountdownFuncs[tFuncSetId][FUNC_RUN](taskId);
|
2020-04-08 23:23:32 +02:00
|
|
|
break;
|
2021-03-11 20:16:40 +01:00
|
|
|
case STATE_END:
|
|
|
|
sStaticCountdownFuncs[tFuncSetId][FUNC_FREE](taskId);
|
2020-04-08 23:23:32 +02:00
|
|
|
DestroyTask(taskId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static void StaticCountdown_CreateSprites(u8 taskId, s16 *data)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
u8 i;
|
|
|
|
struct Sprite *sprite;
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
LoadCompressedSpriteSheet(&sSpriteSheet_321Start_Static[tSpriteSheetId]);
|
|
|
|
LoadSpritePalette(&sSpritePalette_321Start_Static[tSpritePalId]);
|
|
|
|
for (i = 0; i < tNumSprites; i++)
|
|
|
|
tSpriteIds(i) = CreateSprite(&sSpriteTemplate_StaticCountdown[tSpriteTemplateId], tX, tY, tSubpriority);
|
|
|
|
for (i = 0; i < tNumSprites; i++)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
sprite = &gSprites[tSpriteIds(i)];
|
|
|
|
sprite->oam.priority = tPriority;
|
2020-04-08 23:23:32 +02:00
|
|
|
sprite->invisible = TRUE;
|
2021-03-11 20:16:40 +01:00
|
|
|
sprite->sInterval = tInterval;
|
|
|
|
sprite->sTaskId = taskId;
|
|
|
|
sprite->sId = i;
|
|
|
|
sprite->sNumberSpriteId = tSpriteIds(0);
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static void Task_StaticCountdown_Init(u8 taskId)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
2021-03-11 20:16:40 +01:00
|
|
|
tSpriteTemplateId = 0;
|
|
|
|
tSpriteSheetId = 0;
|
|
|
|
tSpritePalId = 0;
|
|
|
|
tInterval = 60;
|
|
|
|
tPriority = 0;
|
|
|
|
tSubpriority = 0;
|
|
|
|
tNumSprites = 3;
|
|
|
|
tX = 120;
|
|
|
|
tY = 88;
|
|
|
|
StaticCountdown_CreateSprites(taskId, data);
|
|
|
|
|
|
|
|
StartSpriteAnim(&gSprites[tSpriteIds(1)], ANIM_START_MID);
|
2021-07-07 15:11:52 +02:00
|
|
|
gSprites[tSpriteIds(1)].x2 = -32;
|
2021-03-11 20:16:40 +01:00
|
|
|
|
|
|
|
StartSpriteAnim(&gSprites[tSpriteIds(2)], ANIM_START_RIGHT);
|
2021-07-07 15:11:52 +02:00
|
|
|
gSprites[tSpriteIds(2)].x2 = 32;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static void Task_StaticCountdown_Free(u8 taskId)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
u8 i = 0;
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
for (i = 0; i < tNumSprites; i++)
|
|
|
|
DestroySprite(&gSprites[tSpriteIds(i)]);
|
|
|
|
FreeSpriteTilesByTag(sSpriteSheet_321Start_Static[tSpriteSheetId].tag);
|
|
|
|
FreeSpritePaletteByTag(sSpritePalette_321Start_Static[tSpritePalId].tag);
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static void SpriteCB_StaticCountdown(struct Sprite *sprite)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
s16 *data = gTasks[sprite->sTaskId].data;
|
2020-04-08 23:23:32 +02:00
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
if (tTimer % tInterval != 0)
|
2020-04-08 23:23:32 +02:00
|
|
|
return;
|
2021-03-11 20:16:40 +01:00
|
|
|
if (tTimer == tPrevTime)
|
2020-04-08 23:23:32 +02:00
|
|
|
return;
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
tPrevTime = tTimer;
|
|
|
|
switch (sprite->sAnimNum)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
case ANIM_THREE:
|
2020-04-08 23:23:32 +02:00
|
|
|
sprite->invisible = FALSE;
|
2021-03-11 20:16:40 +01:00
|
|
|
case ANIM_TWO:
|
|
|
|
case ANIM_ONE:
|
|
|
|
// Set sprite to a number
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_1);
|
2021-03-11 20:16:40 +01:00
|
|
|
StartSpriteAnim(sprite, sprite->sAnimNum);
|
2020-04-08 23:23:32 +02:00
|
|
|
break;
|
2021-03-11 20:16:40 +01:00
|
|
|
case ANIM_START_LEFT:
|
|
|
|
// Set sprite to 'Start'
|
2020-04-08 23:23:32 +02:00
|
|
|
PlaySE(SE_PIN);
|
2021-03-11 20:16:40 +01:00
|
|
|
StartSpriteAnim(sprite, sprite->sAnimNum);
|
|
|
|
gSprites[tSpriteIds(1)].invisible = FALSE;
|
|
|
|
gSprites[tSpriteIds(2)].invisible = FALSE;
|
2020-04-08 23:23:32 +02:00
|
|
|
break;
|
2021-03-11 20:16:40 +01:00
|
|
|
case ANIM_START_LEFT + 1: // End
|
|
|
|
// Hide countdown
|
2020-04-08 23:23:32 +02:00
|
|
|
sprite->invisible = TRUE;
|
2021-03-11 20:16:40 +01:00
|
|
|
gSprites[tSpriteIds(1)].invisible = TRUE;
|
|
|
|
gSprites[tSpriteIds(2)].invisible = TRUE;
|
|
|
|
tState = STATE_END;
|
2020-04-08 23:23:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-03-11 20:16:40 +01:00
|
|
|
sprite->sAnimNum++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static void Task_StaticCountdown_Start(u8 taskId)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_1);
|
2021-03-11 20:16:40 +01:00
|
|
|
gSprites[tSpriteIds(0)].callback = SpriteCB_StaticCountdown;
|
|
|
|
gSprites[tSpriteIds(0)].invisible = FALSE;
|
|
|
|
gTasks[taskId].tState = STATE_RUN;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
// Increment timer for progressing the countdown.
|
|
|
|
// If the player is the link leader, increment a
|
|
|
|
// separate timer and send it to group members for
|
|
|
|
// them to read and use.
|
|
|
|
static void Task_StaticCountdown_Run(u8 taskId)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
u16 packet[RFU_PACKET_SIZE];
|
2020-04-08 23:23:32 +02:00
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
if (gReceivedRemoteLinkPlayers != 0)
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Read link timer
|
|
|
|
if (gRecvCmds[0][1] == LINKCMD_COUNTDOWN)
|
|
|
|
tTimer = gRecvCmds[0][2];
|
|
|
|
|
2020-04-08 23:23:32 +02:00
|
|
|
if (GetMultiplayerId() == 0)
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Player is link leader.
|
|
|
|
// Send timer to group members
|
|
|
|
tLinkTimer++;
|
2020-04-08 23:23:32 +02:00
|
|
|
memset(packet, 0, sizeof(packet));
|
2021-03-11 20:16:40 +01:00
|
|
|
packet[0] = LINKCMD_COUNTDOWN;
|
|
|
|
packet[1] = tLinkTimer;
|
2020-08-24 20:52:33 +02:00
|
|
|
Rfu_SendPacket(packet);
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Local, just increment own timer
|
|
|
|
tTimer++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
#undef tState
|
|
|
|
#undef tFuncSetId
|
|
|
|
#undef tSpriteTemplateId
|
|
|
|
#undef tSpriteSheetId
|
|
|
|
#undef tSpritePalId
|
|
|
|
#undef tInterval
|
|
|
|
#undef tPriority
|
|
|
|
#undef tSubpriority
|
|
|
|
#undef tNumSprites
|
|
|
|
#undef tX
|
|
|
|
#undef tY
|
|
|
|
#undef tPrevTime
|
|
|
|
#undef tTimer
|
|
|
|
#undef tLinkTimer
|
|
|
|
#undef tSpriteIds
|
|
|
|
#undef sInterval
|
|
|
|
#undef sAnimNum
|
|
|
|
#undef sTaskId
|
|
|
|
#undef sId
|
|
|
|
#undef sNumberSpriteId
|
|
|
|
|
|
|
|
/*
|
|
|
|
The countdown that actually gets used by
|
|
|
|
the wireless minigames starts here
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void Task_MinigameCountdown(u8 taskId);
|
|
|
|
static bool32 RunMinigameCountdownDigitsAnim(u8 spriteId);
|
|
|
|
static bool32 IsStartGraphicAnimRunning(u8 spriteId);
|
|
|
|
static void Load321StartGfx(u16 tileTag, u16 palTag);
|
|
|
|
static u8 CreateNumberSprite(u16 tileTag, u16 palTag, s16 x, s16 y, u8 subpriority);
|
|
|
|
static void CreateStartSprite(u16 tileTag, u16 palTag, s16 x, s16 y, u8 subpriority, s16 *spriteId1, s16 *spriteId2);
|
|
|
|
static void InitStartGraphic(u8 spriteId1, u8 spriteId2, u8 spriteId3);
|
|
|
|
static void SpriteCB_Start(struct Sprite *sprite);
|
|
|
|
|
2021-03-16 10:40:42 +01:00
|
|
|
static const u16 s321Start_Pal[] = INCBIN_U16("graphics/minigame_countdown/321start.gbapal");
|
|
|
|
static const u32 s321Start_Gfx[] = INCBIN_U32("graphics/minigame_countdown/321start.4bpp.lz");
|
2021-03-11 20:16:40 +01:00
|
|
|
|
2020-04-08 23:23:32 +02:00
|
|
|
#define tState data[0]
|
|
|
|
#define tTilesTag data[2]
|
|
|
|
#define tPalTag data[3]
|
|
|
|
#define tX data[4]
|
|
|
|
#define tY data[5]
|
|
|
|
#define tSubpriority data[6]
|
|
|
|
#define tSpriteId1 data[7]
|
|
|
|
#define tSpriteId2 data[8]
|
|
|
|
#define tSpriteId3 data[9]
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
void StartMinigameCountdown(u16 tilesTag, u16 palTag, s16 x, s16 y, u8 subpriority)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
u8 taskId = CreateTask(Task_MinigameCountdown, 80);
|
|
|
|
gTasks[taskId].tTilesTag = tilesTag;
|
|
|
|
gTasks[taskId].tPalTag = palTag;
|
|
|
|
gTasks[taskId].tX = x;
|
|
|
|
gTasks[taskId].tY = y;
|
|
|
|
gTasks[taskId].tSubpriority = subpriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool32 IsMinigameCountdownRunning(void)
|
|
|
|
{
|
|
|
|
return FuncIsActiveTask(Task_MinigameCountdown);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Task_MinigameCountdown(u8 taskId)
|
|
|
|
{
|
|
|
|
s16 *data = gTasks[taskId].data;
|
|
|
|
|
|
|
|
switch (tState)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
Load321StartGfx(tTilesTag, tPalTag);
|
|
|
|
tSpriteId1 = CreateNumberSprite(tTilesTag, tPalTag, tX, tY, tSubpriority);
|
|
|
|
CreateStartSprite(tTilesTag, tPalTag, tX, tY, tSubpriority, &tSpriteId2, &tSpriteId3);
|
|
|
|
tState++;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (!RunMinigameCountdownDigitsAnim(tSpriteId1))
|
|
|
|
{
|
|
|
|
InitStartGraphic(tSpriteId1, tSpriteId2, tSpriteId3);
|
|
|
|
FreeSpriteOamMatrix(&gSprites[tSpriteId1]);
|
|
|
|
DestroySprite(&gSprites[tSpriteId1]);
|
|
|
|
tState++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (!IsStartGraphicAnimRunning(tSpriteId2))
|
|
|
|
{
|
|
|
|
DestroySprite(&gSprites[tSpriteId2]);
|
|
|
|
DestroySprite(&gSprites[tSpriteId3]);
|
|
|
|
FreeSpriteTilesByTag(tTilesTag);
|
|
|
|
FreeSpritePaletteByTag(tPalTag);
|
|
|
|
DestroyTask(taskId);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
#define sState data[0]
|
|
|
|
#define sTimer data[2]
|
|
|
|
#define sAnimNum data[4]
|
|
|
|
|
2020-04-08 23:23:32 +02:00
|
|
|
static bool32 RunMinigameCountdownDigitsAnim(u8 spriteId)
|
|
|
|
{
|
|
|
|
struct Sprite *sprite = &gSprites[spriteId];
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
switch (sprite->sState)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
case 0:
|
2021-11-01 23:06:15 +01:00
|
|
|
SetSpriteMatrixAnchor(sprite, NO_ANCHOR, 26);
|
2021-03-11 20:16:40 +01:00
|
|
|
sprite->sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
// fallthrough
|
|
|
|
case 1:
|
2021-03-11 20:16:40 +01:00
|
|
|
if (sprite->sTimer == 0)
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_2);
|
2021-08-25 00:59:32 +02:00
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
if (++sprite->sTimer >= 20)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Ready for jump
|
|
|
|
sprite->sTimer = 0;
|
2020-04-08 23:23:32 +02:00
|
|
|
StartSpriteAffineAnim(sprite, 1);
|
2021-03-11 20:16:40 +01:00
|
|
|
sprite->sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (sprite->affineAnimEnded)
|
2021-03-11 20:16:40 +01:00
|
|
|
sprite->sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2021-03-11 20:16:40 +01:00
|
|
|
if (++sprite->sTimer >= 4)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Start jump
|
|
|
|
sprite->sTimer = 0;
|
|
|
|
sprite->sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
StartSpriteAffineAnim(sprite, 2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
2021-03-11 20:16:40 +01:00
|
|
|
// Moving up from jump
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y -= 4;
|
2021-03-11 20:16:40 +01:00
|
|
|
if (++sprite->sTimer >= 8)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
if (sprite->sAnimNum < 2)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Swap to the next number
|
|
|
|
StartSpriteAnim(sprite, sprite->sAnimNum + 1);
|
|
|
|
sprite->sTimer = 0;
|
|
|
|
sprite->sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// End
|
|
|
|
sprite->sState = 7;
|
2020-04-08 23:23:32 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
2021-03-11 20:16:40 +01:00
|
|
|
// Falling after jump
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y += 4;
|
2021-03-11 20:16:40 +01:00
|
|
|
if (++sprite->sTimer >= 8)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Land from jump
|
|
|
|
sprite->sTimer = 0;
|
2020-04-08 23:23:32 +02:00
|
|
|
StartSpriteAffineAnim(sprite, 3);
|
2021-03-11 20:16:40 +01:00
|
|
|
sprite->sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (sprite->affineAnimEnded)
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
// Restart for next number
|
|
|
|
sprite->sAnimNum++;
|
|
|
|
sprite->sState = 1;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
#undef sState
|
|
|
|
#undef sTimer
|
|
|
|
#undef sAnimNum
|
|
|
|
|
2020-04-08 23:23:32 +02:00
|
|
|
// First argument is unused.
|
|
|
|
static void InitStartGraphic(u8 spriteId1, u8 spriteId2, u8 spriteId3)
|
|
|
|
{
|
2021-07-07 15:11:52 +02:00
|
|
|
gSprites[spriteId2].y2 = -40;
|
|
|
|
gSprites[spriteId3].y2 = -40;
|
2020-04-08 23:23:32 +02:00
|
|
|
gSprites[spriteId2].invisible = FALSE;
|
|
|
|
gSprites[spriteId3].invisible = FALSE;
|
|
|
|
gSprites[spriteId2].callback = SpriteCB_Start;
|
|
|
|
gSprites[spriteId3].callback = SpriteCB_Start;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool32 IsStartGraphicAnimRunning(u8 spriteId)
|
|
|
|
{
|
|
|
|
return gSprites[spriteId].callback == SpriteCB_Start;
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
#define sState data[0]
|
|
|
|
#define sTimer data[1]
|
|
|
|
#define sYSpeed data[4]
|
|
|
|
#define sY data[5]
|
|
|
|
|
2020-04-08 23:23:32 +02:00
|
|
|
static void SpriteCB_Start(struct Sprite *sprite)
|
|
|
|
{
|
|
|
|
int y;
|
|
|
|
s16 *data = sprite->data;
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
switch (sState)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
case 0:
|
2021-03-11 20:16:40 +01:00
|
|
|
sYSpeed = 64;
|
2021-07-07 15:11:52 +02:00
|
|
|
sY = sprite->y2 << 4;
|
2021-03-11 20:16:40 +01:00
|
|
|
sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
case 1:
|
2021-03-11 20:16:40 +01:00
|
|
|
sY += sYSpeed;
|
|
|
|
sYSpeed++;
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = sY >> 4;
|
|
|
|
if (sprite->y2 >= 0)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_2);
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = 0;
|
2021-03-11 20:16:40 +01:00
|
|
|
sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2021-03-11 20:16:40 +01:00
|
|
|
sTimer += 12;
|
|
|
|
if (sTimer >= 128)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_2);
|
2021-03-11 20:16:40 +01:00
|
|
|
sTimer = 0;
|
|
|
|
sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
2021-03-11 20:16:40 +01:00
|
|
|
y = gSineTable[sTimer];
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = -(y >> 4);
|
2020-04-08 23:23:32 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2021-03-11 20:16:40 +01:00
|
|
|
sTimer += 16;
|
|
|
|
if (sTimer >= 128)
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
2020-08-21 00:02:00 +02:00
|
|
|
PlaySE(SE_BALL_BOUNCE_2);
|
2021-03-11 20:16:40 +01:00
|
|
|
sTimer = 0;
|
|
|
|
sState++;
|
2020-04-08 23:23:32 +02:00
|
|
|
}
|
2021-07-07 15:11:52 +02:00
|
|
|
sprite->y2 = -(gSineTable[sTimer] >> 5);
|
2020-04-08 23:23:32 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2021-03-11 20:16:40 +01:00
|
|
|
if (++sTimer > 40)
|
2020-04-08 23:23:32 +02:00
|
|
|
sprite->callback = SpriteCallbackDummy;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
#undef sState
|
|
|
|
#undef sTimer
|
|
|
|
#undef sYSpeed
|
|
|
|
#undef sY
|
|
|
|
|
2020-04-08 23:23:32 +02:00
|
|
|
static void Load321StartGfx(u16 tileTag, u16 palTag)
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
struct CompressedSpriteSheet spriteSheet = {s321Start_Gfx, 0xE00, 0};
|
|
|
|
struct SpritePalette spritePalette = {s321Start_Pal, 0};
|
2020-04-08 23:23:32 +02:00
|
|
|
|
|
|
|
spriteSheet.tag = tileTag;
|
|
|
|
spritePalette.tag = palTag;
|
|
|
|
|
|
|
|
LoadCompressedSpriteSheet(&spriteSheet);
|
|
|
|
LoadSpritePalette(&spritePalette);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct OamData sOamData_Numbers =
|
|
|
|
{
|
|
|
|
.y = 0,
|
|
|
|
.affineMode = ST_OAM_AFFINE_DOUBLE,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
|
|
|
.mosaic = 0,
|
|
|
|
.bpp = ST_OAM_4BPP,
|
|
|
|
.shape = SPRITE_SHAPE(32x32),
|
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
|
|
|
.size = SPRITE_SIZE(32x32),
|
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 0,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct OamData sOamData_Start =
|
|
|
|
{
|
|
|
|
.y = 0,
|
|
|
|
.affineMode = ST_OAM_AFFINE_OFF,
|
|
|
|
.objMode = ST_OAM_OBJ_NORMAL,
|
|
|
|
.mosaic = 0,
|
|
|
|
.bpp = ST_OAM_4BPP,
|
|
|
|
.shape = SPRITE_SHAPE(64x32),
|
|
|
|
.x = 0,
|
|
|
|
.matrixNum = 0,
|
|
|
|
.size = SPRITE_SIZE(64x32),
|
|
|
|
.tileNum = 0,
|
|
|
|
.priority = 0,
|
|
|
|
.paletteNum = 0,
|
|
|
|
.affineParam = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sAnim_Numbers_Three[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(0, 1),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sAnim_Numbers_Two[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(16, 1),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sAnim_Numbers_One[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(32, 1),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd *const sAnimTable_Numbers[] =
|
|
|
|
{
|
|
|
|
sAnim_Numbers_Three,
|
|
|
|
sAnim_Numbers_Two,
|
|
|
|
sAnim_Numbers_One
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sAnim_StartLeft[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(48, 1),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd sAnim_StartRight[] =
|
|
|
|
{
|
|
|
|
ANIMCMD_FRAME(80, 1),
|
|
|
|
ANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AnimCmd *const sAnimTable_Start[] =
|
|
|
|
{
|
|
|
|
sAnim_StartLeft,
|
|
|
|
sAnim_StartRight
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AffineAnimCmd sAffineAnim_Numbers_Normal[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
AFFINEANIMCMD_FRAME(256, 256, 0, 0),
|
|
|
|
AFFINEANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AffineAnimCmd sAffineAnim_Numbers_Squash[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
AFFINEANIMCMD_FRAME(256, 256, 0, 0),
|
|
|
|
AFFINEANIMCMD_FRAME(16, -16, 0, 8),
|
|
|
|
AFFINEANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AffineAnimCmd sAffineAnim_Numbers_Stretch[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
AFFINEANIMCMD_FRAME(-18, 18, 0, 8),
|
|
|
|
AFFINEANIMCMD_END
|
|
|
|
};
|
|
|
|
|
2021-03-11 20:16:40 +01:00
|
|
|
static const union AffineAnimCmd sAffineAnim_Numbers_Land[] =
|
2020-04-08 23:23:32 +02:00
|
|
|
{
|
|
|
|
AFFINEANIMCMD_FRAME( 6, -6, 0, 8),
|
|
|
|
AFFINEANIMCMD_FRAME( -4, 4, 0, 8),
|
|
|
|
AFFINEANIMCMD_FRAME(256, 256, 0, 0),
|
|
|
|
AFFINEANIMCMD_END
|
|
|
|
};
|
|
|
|
|
|
|
|
static const union AffineAnimCmd *const sAffineAnimTable_Numbers[] =
|
|
|
|
{
|
2021-03-11 20:16:40 +01:00
|
|
|
sAffineAnim_Numbers_Normal,
|
|
|
|
sAffineAnim_Numbers_Squash, // Push down before the jump
|
|
|
|
sAffineAnim_Numbers_Stretch, // Stretch up for the jump
|
|
|
|
sAffineAnim_Numbers_Land // Land after the jump
|
2020-04-08 23:23:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static u8 CreateNumberSprite(u16 tileTag, u16 palTag, s16 x, s16 y, u8 subpriority)
|
|
|
|
{
|
|
|
|
struct SpriteTemplate spriteTemplate =
|
|
|
|
{
|
|
|
|
.oam = &sOamData_Numbers,
|
|
|
|
.anims = sAnimTable_Numbers,
|
|
|
|
.affineAnims = sAffineAnimTable_Numbers,
|
|
|
|
.callback = SpriteCallbackDummy,
|
|
|
|
};
|
|
|
|
|
|
|
|
spriteTemplate.tileTag = tileTag;
|
|
|
|
spriteTemplate.paletteTag = palTag;
|
|
|
|
return CreateSprite(&spriteTemplate, x, y, subpriority);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CreateStartSprite(u16 tileTag, u16 palTag, s16 x, s16 y, u8 subpriority, s16 *spriteId1, s16 *spriteId2)
|
|
|
|
{
|
|
|
|
struct SpriteTemplate spriteTemplate =
|
|
|
|
{
|
|
|
|
.oam = &sOamData_Start,
|
|
|
|
.anims = sAnimTable_Start,
|
|
|
|
.affineAnims = gDummySpriteAffineAnimTable,
|
|
|
|
.callback = SpriteCallbackDummy,
|
|
|
|
};
|
|
|
|
|
|
|
|
spriteTemplate.tileTag = tileTag;
|
|
|
|
spriteTemplate.paletteTag = palTag;
|
|
|
|
*spriteId1 = CreateSprite(&spriteTemplate, x - 32, y, subpriority);
|
|
|
|
*spriteId2 = CreateSprite(&spriteTemplate, x + 32, y, subpriority);
|
|
|
|
|
|
|
|
gSprites[*spriteId1].invisible = TRUE;
|
|
|
|
gSprites[*spriteId2].invisible = TRUE;
|
|
|
|
StartSpriteAnim(&gSprites[*spriteId2], 1);
|
|
|
|
}
|