Path: blob/master/SonicMania/Objects/Credits/TryAgain.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: TryAgain Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectTryAgain *TryAgain;1011void TryAgain_Update(void)12{13RSDK_THIS(TryAgain);1415StateMachine_Run(self->state);16}1718void TryAgain_LateUpdate(void) {}1920void TryAgain_StaticUpdate(void) {}2122void TryAgain_Draw(void)23{24RSDK_THIS(TryAgain);2526RSDK.SetActivePalette(0, 0, ScreenInfo->size.y);27RSDK.SetClipBounds(0, 0, 0, ScreenInfo->size.x, (self->position.y >> 16));2829RSDK.DrawSprite(&self->eggmanAnimator, &self->eggmanPos, false);30RSDK.DrawSprite(&self->rubyAnimator, &self->rubyPos, false);3132RSDK.SetClipBounds(0, 0, 0, ScreenInfo->size.x, ScreenInfo->size.y);33RSDK.DrawSprite(&self->debrisAnimator, NULL, false);3435RSDK.SetActivePalette(1, 0, ScreenInfo->size.y);36}3738void TryAgain_Create(void *data)39{40RSDK_THIS(TryAgain);4142if (!SceneInfo->inEditor) {43self->eggmanPos.x = self->position.x;44self->eggmanPos.y = self->position.y + 0x100000;45self->rubyPos.x = self->eggmanPos.x - 0x340000;46self->rubyPos.y = self->eggmanPos.y;4748self->visible = true;49self->drawGroup = 1;50self->active = ACTIVE_BOUNDS;51self->updateRange.x = 0x800000;52self->updateRange.y = 0x800000;5354self->state = TryAgain_State_Init;55RSDK.SetSpriteAnimation(TryAgain->aniFrames, 0, &self->debrisAnimator, true, 0);56RSDK.SetSpriteAnimation(TryAgain->aniFrames, 2, &self->eggmanAnimator, true, 0);57RSDK.SetSpriteAnimation(TryAgain->aniFrames, 4, &self->rubyAnimator, true, 0);58}59}6061void TryAgain_StageLoad(void)62{63TryAgain->aniFrames = RSDK.LoadSpriteAnimation("Credits/TryAgain.bin", SCOPE_STAGE);6465RSDK.CopyPalette(0, 0, 1, 0, 128);66}6768void TryAgain_State_Init(void)69{70RSDK_THIS(TryAgain);7172if (++self->timer == 60) {73self->timer = 0;74self->eggmanVelocityY = -0x5C000;7576#if MANIA_USE_PLUS77Music_PlayTrack(TRACK_STAGE);78#endif79self->state = TryAgain_State_EnterEggman;80}81}8283void TryAgain_State_EnterEggman(void)84{85RSDK_THIS(TryAgain);8687self->eggmanVelocityY += 0x3800;88int32 targetPos = self->position.y - 0x340000;89self->eggmanPos.y += self->eggmanVelocityY;9091if (self->eggmanPos.y <= targetPos || self->eggmanVelocityY <= 0) {92self->rubyPos.y = self->eggmanPos.y;93}94else {95self->eggmanVelocityY = 0;96self->eggmanPos.y = targetPos;97self->rubyPos.y = targetPos;98self->state = TryAgain_State_EggmanLaugh;99}100}101102void TryAgain_State_EggmanLaugh(void)103{104RSDK_THIS(TryAgain);105106if (self->timer > (MANIA_USE_PLUS ? 15 : 30))107RSDK.ProcessAnimation(&self->eggmanAnimator);108109if (++self->timer == 120) {110self->timer = 0;111RSDK.SetSpriteAnimation(TryAgain->aniFrames, 3, &self->eggmanAnimator, true, 2);112self->state = TryAgain_State_Stinger;113}114}115116void TryAgain_State_Stinger(void)117{118RSDK_THIS(TryAgain);119120RSDK.ProcessAnimation(&self->eggmanAnimator);121122if (self->eggmanAnimator.frameID == 2) {123if (self->eggmanAnimator.timer == 1) {124self->rubyVelocity.x = 0x22000;125self->rubyVelocity.y = -0x58000;126}127}128else if (self->eggmanAnimator.frameID == 7 && self->eggmanAnimator.timer == 1) {129self->rubyVelocity.x = -0x22000;130self->rubyVelocity.y = -0x58000;131}132133self->rubyVelocity.y += 0x3800;134self->rubyPos.x += self->rubyVelocity.x;135self->rubyPos.y += self->rubyVelocity.y;136137if (self->rubyPos.y <= self->eggmanPos.y + 0x80000) {138if (self->rubyPos.y < self->position.y)139RSDK.ProcessAnimation(&self->rubyAnimator);140}141else {142self->rubyPos.y = self->eggmanPos.y + 0x80000;143self->rubyVelocity.x = 0;144self->rubyVelocity.y = 0;145RSDK.SetSpriteAnimation(TryAgain->aniFrames, 4, &self->rubyAnimator, true, 0);146}147148++self->timer;149if (ControllerInfo->keyA.press || ControllerInfo->keyStart.press)150self->timer = 600;151152if (self->timer == 600) {153#if MANIA_USE_PLUS154PhantomRuby_PlaySfx(RUBYSFX_ATTACK4);155EntityFXFade *fxFade = CREATE_ENTITY(FXFade, INT_TO_VOID(0xFFFFFF), self->position.x, self->position.y);156fxFade->speedIn = 24;157fxFade->speedOut = 24;158fxFade->fadeOutBlack = true;159#else160EntityFXFade *fxFade = CREATE_ENTITY(FXFade, INT_TO_VOID(0x000000), self->position.x, self->position.y);161fxFade->speedIn = 12;162fxFade->wait = 240;163#endif164}165166if (self->timer >= (MANIA_USE_PLUS ? 740 : 680)) {167#if MANIA_USE_PLUS168if (API.CheckDLC(DLC_PLUS))169RSDK.SetScene("Presentation", "Game Summary");170else171#endif172RSDK.SetScene("Presentation", "Menu");173174RSDK.LoadScene();175}176}177178#if GAME_INCLUDE_EDITOR179void TryAgain_EditorDraw(void) {}180181void TryAgain_EditorLoad(void) {}182#endif183184void TryAgain_Serialize(void) {}185186187