Path: blob/master/SonicMania/Objects/SSZ/MSFactory.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: MSFactory Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectMSFactory *MSFactory;1011void MSFactory_Update(void)12{13RSDK_THIS(MSFactory);1415StateMachine_Run(self->state);16}1718void MSFactory_LateUpdate(void) {}1920void MSFactory_StaticUpdate(void) {}2122void MSFactory_Draw(void)23{24RSDK_THIS(MSFactory);2526self->animator.frameID = 0;27RSDK.DrawSprite(&self->animator, &self->drawPos, false);2829self->animator.frameID = 1;30RSDK.DrawSprite(&self->animator, NULL, false);31}3233void MSFactory_Create(void *data)34{35RSDK_THIS(MSFactory);3637if (!SceneInfo->inEditor) {38self->visible = false;39self->drawGroup = Zone->objectDrawGroup[0];40self->drawPos = self->position;41self->active = ACTIVE_BOUNDS;42self->updateRange.x = 0x800000;43self->updateRange.y = 0x800000;4445self->state = MSFactory_State_SetupFactory;46RSDK.SetSpriteAnimation(MSFactory->aniFrames, 0, &self->animator, true, 1);47}48}4950void MSFactory_StageLoad(void)51{52MSFactory->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSFactory.bin", SCOPE_STAGE);5354MSFactory->sfxMachineActivate = RSDK.GetSfx("Stage/MachineActivate.wav");55MSFactory->sfxHullClose = RSDK.GetSfx("Stage/HullClose.wav");56}5758void MSFactory_State_SetupFactory(void)59{60RSDK_THIS(MSFactory);6162EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);6364if (player1->position.y < self->position.y + 0x100000 && player1->position.y > self->position.y - 0x1000000) {65Zone->playerBoundActiveL[0] = true;66Zone->playerBoundActiveR[0] = true;6768Zone->cameraBoundsL[0] = (self->position.x >> 16) - ScreenInfo->center.x;69Zone->cameraBoundsR[0] = (self->position.x >> 16) + ScreenInfo->center.x;70Zone->cameraBoundsT[0] = (self->position.y >> 16) - ScreenInfo->size.y + 44;71Zone->cameraBoundsB[0] = (self->position.y >> 16) + 44;7273self->state = MSFactory_State_SetupMetalSonic;74}75}7677void MSFactory_State_SetupMetalSonic(void)78{79RSDK_THIS(MSFactory);80EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);8182if (player1->position.x > self->position.x && player1->position.y < self->position.y + 0x300000) {83foreach_active(MetalSonic, metal)84{85if (!RSDK.CheckOnScreen(metal, NULL)) {86metal->position.x = self->position.x;87metal->position.y = self->position.y;88metal->position.x -= 0x1000000;89}90}9192self->state = StateMachine_None;93}94}9596void MSFactory_State_OpeningDoor(void)97{98RSDK_THIS(MSFactory);99100self->position.y += 0x20000;101102if (!self->timer)103RSDK.PlaySfx(MSFactory->sfxMachineActivate, false, 255);104105if (++self->timer == 24) {106self->timer = 0;107self->state = MSFactory_State_CreateSilverSonic;108}109}110111void MSFactory_State_CreateSilverSonic(void)112{113RSDK_THIS(MSFactory);114115if (++self->timer == 8) {116foreach_active(MetalSonic, metal)117{118if (metal && metal->state != MetalSonic_State_PanelExplosion)119CREATE_ENTITY(SilverSonic, NULL, self->drawPos.x, self->drawPos.y + 0x80000);120121foreach_break;122}123}124125if (self->timer == 60) {126self->timer = 0;127self->state = MSFactory_State_CloseDoor;128}129}130131void MSFactory_State_CloseDoor(void)132{133RSDK_THIS(MSFactory);134135self->position.y -= 0x20000;136if (++self->timer == 24) {137Camera_ShakeScreen(0, 0, 2);138139self->timer = 0;140self->visible = false;141self->state = StateMachine_None;142143RSDK.PlaySfx(MSFactory->sfxHullClose, false, 255);144}145}146147#if GAME_INCLUDE_EDITOR148void MSFactory_EditorDraw(void)149{150RSDK_THIS(MSFactory);151RSDK.SetSpriteAnimation(MSFactory->aniFrames, 0, &self->animator, false, 1);152153self->animator.frameID = 0;154RSDK.DrawSprite(&self->animator, NULL, false);155156self->animator.frameID = 1;157RSDK.DrawSprite(&self->animator, NULL, false);158159if (showGizmos()) {160RSDK_DRAWING_OVERLAY(true);161162DrawHelpers_DrawArenaBounds(-WIDE_SCR_XCENTER, -SCREEN_YSIZE + 44, WIDE_SCR_XCENTER, 44, 1 | 2 | 4 | 8, 0x00C0F0);163164RSDK_DRAWING_OVERLAY(false);165}166}167168void MSFactory_EditorLoad(void) { MSFactory->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSFactory.bin", SCOPE_STAGE); }169#endif170171void MSFactory_Serialize(void) {}172173174