Path: blob/master/SonicMania/Objects/Global/Announcer.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: Announcer Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectAnnouncer *Announcer;1011void Announcer_Update(void)12{13RSDK_THIS(Announcer);14StateMachine_Run(self->state);15}1617void Announcer_LateUpdate(void) {}1819void Announcer_StaticUpdate(void) {}2021void Announcer_Draw(void)22{23RSDK_THIS(Announcer);24StateMachine_Run(self->stateDraw);25}2627void Announcer_Create(void *data)28{29RSDK_THIS(Announcer);3031self->active = ACTIVE_NORMAL;32self->drawGroup = 13;33self->visible = true;34self->drawFX = FX_FLIP | FX_SCALE;35self->isPermanent = true;36self->updateRange.x = TO_FIXED(128);37self->updateRange.y = TO_FIXED(128);38}3940void Announcer_StageLoad(void)41{42Announcer->finishedCountdown = false;4344if (RSDK.CheckSceneFolder("Menu")) {45#if !MANIA_USE_PLUS46Announcer->sfxNewRecordTop = RSDK.GetSfx("VO/NewRecordTop.wav");47Announcer->sfxNewRecordMid = RSDK.GetSfx("VO/NewRecordMid.wav");48#endif49Announcer->sfxSonic = RSDK.GetSfx("VO/Sonic.wav");50Announcer->sfxTails = RSDK.GetSfx("VO/Tails.wav");51Announcer->sfxKnuckles = RSDK.GetSfx("VO/Knuckles.wav");52#if MANIA_USE_PLUS53Announcer->sfxMighty = RSDK.GetSfx("VO/Mighty.wav");54Announcer->sfxRay = RSDK.GetSfx("VO/Ray.wav");55#endif56Announcer->sfxTheWinnerIs = RSDK.GetSfx("VO/TheWinnerIs.wav");57Announcer->sfxPlayer1 = RSDK.GetSfx("VO/Player1.wav");58Announcer->sfxPlayer2 = RSDK.GetSfx("VO/Player2.wav");59#if MANIA_USE_PLUS60Announcer->sfxPlayer3 = RSDK.GetSfx("VO/Player3.wav");61Announcer->sfxPlayer4 = RSDK.GetSfx("VO/Player4.wav");62#endif63Announcer->sfxSonicWins = RSDK.GetSfx("VO/SonicWins.wav");64Announcer->sfxTailsWins = RSDK.GetSfx("VO/TailsWins.wav");65Announcer->sfxKnuxWins = RSDK.GetSfx("VO/KnuxWins.wav");66#if MANIA_USE_PLUS67Announcer->sfxMightyWins = RSDK.GetSfx("VO/MightyWins.wav");68Announcer->sfxRayWins = RSDK.GetSfx("VO/RayWins.wav");69Announcer->sfxDrawRound = RSDK.GetSfx("VO/ItsADraw.wav");70Announcer->sfxDrawSet = RSDK.GetSfx("VO/ItsADraw_Set.wav");71LogHelpers_Print("sfxDrawRound = %d", Announcer->sfxDrawRound);72LogHelpers_Print("sfxDrawSet = %d", Announcer->sfxDrawSet);73#endif74}75else if (globals->gameMode == MODE_COMPETITION) {76Announcer->aniFrames = RSDK.LoadSpriteAnimation("Global/Announcer.bin", SCOPE_STAGE);7778Announcer->sfxThree = RSDK.GetSfx("VO/Three.wav");79Announcer->sfxTwo = RSDK.GetSfx("VO/Two.wav");80Announcer->sfxOne = RSDK.GetSfx("VO/One.wav");81Announcer->sfxGo = RSDK.GetSfx("VO/Go.wav");82Announcer->sfxGoal = RSDK.GetSfx("VO/Goal.wav");83}84else if (globals->gameMode == MODE_TIMEATTACK) {85Announcer->aniFrames = RSDK.LoadSpriteAnimation("Global/Announcer.bin", SCOPE_STAGE);8687#if MANIA_USE_PLUS88Announcer->sfxNewRecordTop = RSDK.GetSfx("VO/NewRecordTop.wav");89Announcer->sfxNewRecordMid = RSDK.GetSfx("VO/NewRecordMid.wav");90#endif91Announcer->sfxGoal = RSDK.GetSfx("VO/Goal.wav");92}93}9495void Announcer_StartCountdown(void)96{97Announcer->finishedCountdown = false;98EntityAnnouncer *announcer = CREATE_ENTITY(Announcer, NULL, 0, 0);99announcer->state = Announcer_State_Countdown;100announcer->stateDraw = Announcer_Draw_Countdown;101announcer->playerID = 3;102announcer->scale.x = 0x200;103announcer->scale.y = 0x200;104}105void Announcer_AnnounceGoal(int32 screen)106{107EntityAnnouncer *announcer = CREATE_ENTITY(Announcer, NULL, 0, 0);108announcer->state = Announcer_State_Finished;109announcer->stateDraw = Announcer_Draw_Finished;110announcer->screen = screen;111RSDK.SetSpriteAnimation(Announcer->aniFrames, 0, &announcer->animator, true, 0);112RSDK.PlaySfx(Announcer->sfxGoal, false, 255);113}114void Announcer_Draw_Countdown(void)115{116RSDK_THIS(Announcer);117118Vector2 drawPos;119drawPos.y = (ScreenInfo->center.y - 32) << 16;120drawPos.x = ScreenInfo->center.x << 16;121drawPos.x += self->drawOffset.x;122drawPos.y += self->drawOffset.y;123RSDK.DrawSprite(&self->animator, &drawPos, true);124125if (self->playerID > 0) {126self->inkEffect = INK_NONE;127EntityCompetitionSession *session = CompetitionSession_GetSession();128129int32 frame = 0;130switch (session->playerID[SceneInfo->currentScreenID]) {131default:132case ID_SONIC: frame = 0; break;133case ID_TAILS: frame = 1; break;134case ID_KNUCKLES: frame = 2; break;135#if MANIA_USE_PLUS136case ID_MIGHTY: frame = 3; break;137case ID_RAY: frame = 4; break;138#endif139}140RSDK.SetSpriteAnimation(Announcer->aniFrames, 2, &self->playerIconAnimator, true, frame);141142drawPos.x = ScreenInfo->center.x << 16;143drawPos.y = (ScreenInfo->center.y + 48) << 16;144RSDK.DrawSprite(&self->playerIconAnimator, &drawPos, true);145self->inkEffect = INK_ALPHA;146}147}148void Announcer_Draw_Finished(void)149{150RSDK_THIS(Announcer);151152Vector2 drawPos;153if (SceneInfo->currentScreenID == self->screen) {154drawPos.x = ScreenInfo->center.x << 16;155drawPos.y = (ScreenInfo->center.y - 32) << 16;156drawPos.x += self->drawOffset.x;157drawPos.y += self->drawOffset.y;158RSDK.DrawSprite(&self->animator, &drawPos, true);159}160}161void Announcer_State_Countdown(void)162{163RSDK_THIS(Announcer);164165self->inkEffect = INK_ALPHA;166if (self->playerID <= 0) {167if (self->timer >= 60) {168destroyEntity(self);169}170else {171if (!self->timer) {172RSDK.PlaySfx(Announcer->sfxGo, false, 255);173RSDK.SetSpriteAnimation(Announcer->aniFrames, 1, &self->animator, true, 3);174}175176int32 timer = 0;177if (self->timer - 15 > 0)178timer = (self->timer - 15) << 9;179self->alpha = 0x200 - timer / 45;180181self->timer++;182}183}184else {185if (self->timer >= 45) {186self->timer = 0;187188self->playerID--;189if (!self->playerID) {190Announcer->finishedCountdown = true;191SceneInfo->timeEnabled = true;192}193}194else {195if (!self->timer) {196switch (self->playerID) {197default: break;198199case 1:200RSDK.PlaySfx(Announcer->sfxOne, false, 255);201RSDK.SetSpriteAnimation(Announcer->aniFrames, 1, &self->animator, true, 2);202break;203204case 2:205RSDK.PlaySfx(Announcer->sfxTwo, false, 255);206RSDK.SetSpriteAnimation(Announcer->aniFrames, 1, &self->animator, true, 1);207break;208209case 3:210RSDK.PlaySfx(Announcer->sfxThree, false, 255);211RSDK.SetSpriteAnimation(Announcer->aniFrames, 1, &self->animator, true, 0);212break;213}214}215self->drawOffset.x = 0;216self->drawOffset.y = 0;217self->alpha = 0x200 - (self->timer << 9) / 45;218self->timer++;219}220}221}222void Announcer_State_Finished(void)223{224RSDK_THIS(Announcer);225226self->scale.x = 0x200;227self->scale.y = 0x200;228if (self->timer >= 16) {229if (self->timer >= 76) {230if (self->timer >= 92) {231destroyEntity(self);232}233else {234self->visible = true;235MathHelpers_Lerp(&self->drawOffset, ((self->timer - 76) << 8) / 16, 0, 0, ScreenInfo->size.x << 16, 0);236++self->timer;237}238}239else {240++self->timer;241self->drawOffset.x = 0;242self->drawOffset.y = 0;243}244}245else {246self->visible = true;247int32 t = 16 * self->timer;248int32 xOffset = -TO_FIXED(1) * ScreenInfo->size.x;249if (t > 0) {250if (t < 256)251self->drawOffset.x = xOffset + t * (-xOffset >> 8);252else253self->drawOffset.x = 0;254self->drawOffset.y = 0;255}256else {257self->drawOffset.x = xOffset;258self->drawOffset.y = 0;259}260++self->timer;261}262}263void Announcer_State_AnnounceWinner(void)264{265RSDK_THIS(Announcer);266267if (self->timer >= 150) {268switch (self->playerID) {269case 0: RSDK.PlaySfx(Announcer->sfxPlayer1, false, 255); break;270case 1: RSDK.PlaySfx(Announcer->sfxPlayer2, false, 255); break;271#if MANIA_USE_PLUS272case 2: RSDK.PlaySfx(Announcer->sfxPlayer3, false, 255); break;273case 3: RSDK.PlaySfx(Announcer->sfxPlayer4, false, 255); break;274#endif275default: break;276}277destroyEntity(self);278}279else {280if (self->timer == 30)281RSDK.PlaySfx(Announcer->sfxTheWinnerIs, false, 255);282283++self->timer;284}285}286void Announcer_State_AnnounceDraw(void)287{288RSDK_THIS(Announcer);289290if (self->timer < 30) {291self->timer++;292}293else {294if (self->playerID == 0)295RSDK.PlaySfx(Announcer->sfxDrawRound, false, 255);296else if (self->playerID == 1)297RSDK.PlaySfx(Announcer->sfxDrawSet, false, 255);298299destroyEntity(self);300}301}302void Announcer_State_AnnounceWinPlayer(void)303{304RSDK_THIS(Announcer);305306if (self->timer >= 30) {307switch (self->playerID) {308case ID_SONIC: RSDK.PlaySfx(Announcer->sfxSonicWins, false, 255); break;309case ID_TAILS: RSDK.PlaySfx(Announcer->sfxTailsWins, false, 255); break;310case ID_KNUCKLES: RSDK.PlaySfx(Announcer->sfxKnuxWins, false, 255); break;311#if MANIA_USE_PLUS312case ID_MIGHTY: RSDK.PlaySfx(Announcer->sfxMightyWins, false, 255); break;313case ID_RAY: RSDK.PlaySfx(Announcer->sfxRayWins, false, 255); break;314#endif315default: break;316}317318destroyEntity(self);319}320else {321self->timer++;322}323}324325#if GAME_INCLUDE_EDITOR326void Announcer_EditorDraw(void) {}327328void Announcer_EditorLoad(void) {}329#endif330331void Announcer_Serialize(void) {}332333334