Path: blob/master/SonicMania/Objects/Cutscene/FXRuby.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: FXRuby Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectFXRuby *FXRuby;1011void FXRuby_Update(void)12{13RSDK_THIS(FXRuby);1415StateMachine_Run(self->state);16}1718void FXRuby_LateUpdate(void) {}1920void FXRuby_StaticUpdate(void)21{22if (Zone) {23foreach_active(FXRuby, fxRuby)24{25RSDK.AddDrawListRef(Zone->hudDrawGroup + 1, RSDK.GetEntitySlot(fxRuby));26foreach_break;27}28}29}3031void FXRuby_Draw(void)32{33RSDK_THIS(FXRuby);3435#if MANIA_USE_PLUS36RSDK.SetTintLookupTable(FXRuby->tintLookupTable);37#endif3839if (self->fadeWhite >= 512 || self->fadeBlack >= 512 || SceneInfo->currentDrawGroup != self->drawGroup) {40if (self->fadeWhite > 0)41RSDK.FillScreen(0xFFF0F0, self->fadeWhite, self->fadeWhite - 256, self->fadeWhite - 256);4243if (self->fadeBlack > 0)44RSDK.FillScreen(0x000000, self->fadeBlack, self->fadeBlack - 128, self->fadeBlack - 256);45}46else {47if (self->outerRadius <= ScreenInfo->size.x) {48if (self->innerRadius)49RSDK.DrawCircleOutline(self->position.x, self->position.y, self->innerRadius, self->outerRadius, 0x000000, 0xFF, INK_TINT, false);50else51RSDK.DrawCircle(self->position.x, self->position.y, self->outerRadius, 0x000000, 0xFF, INK_TINT, false);52}53else {54RSDK.DrawRect(0, 0, ScreenInfo->size.x, ScreenInfo->size.y, 0x000000, 0xFF, INK_TINT, true);55}56}57}5859void FXRuby_Create(void *data)60{61RSDK_THIS(FXRuby);6263if (!SceneInfo->inEditor) {64self->visible = true;65self->active = ACTIVE_NORMAL;66self->drawGroup = Zone ? Zone->objectDrawGroup[1] : (DRAWGROUP_COUNT - 1);6768self->radiusSpeed = 4;6970if (data)71self->state = (Type_StateMachine)data;72else if (!self->waitForTrigger)73self->state = FXRuby_State_Expanding;7475#if !MANIA_USE_PLUS76uint16 *tintLookupTable = RSDK.GetTintLookupTable();77for (int32 c = 0; c < 0x10000; ++c) tintLookupTable[0xFFFF - c] = c;78#endif79}80}8182void FXRuby_StageLoad(void)83{84FXRuby->fgLow = RSDK.GetTileLayer(RSDK.GetTileLayerID("FG Low"));85FXRuby->fgHigh = RSDK.GetTileLayer(RSDK.GetTileLayerID("FG High"));8687for (int32 d = 0; d < 0x200; ++d) FXRuby->deformation[d] = RSDK.Rand(-64, 64);8889#if MANIA_USE_PLUS90for (int32 c = 0; c < 0x10000; ++c) FXRuby->tintLookupTable[0xFFFF - c] = c;91#endif92}9394void FXRuby_SetupLayerDeformation(void)95{96for (int32 l = 0; l < LAYER_COUNT; ++l) {97TileLayer *layer = RSDK.GetTileLayer(l);9899if (layer->width && layer->drawGroup[0] != DRAWGROUP_COUNT) {100for (int32 s = 0; s < layer->scrollInfoCount; ++s) layer->scrollInfo[s].deform = true;101}102}103}104105void FXRuby_HandleLayerDeform(void)106{107RSDK_THIS(FXRuby);108109int32 timer = Zone ? Zone->timer : UIWidgets->timer;110111int32 *deformationData = NULL;112for (int32 l = 0; l < LAYER_COUNT; ++l) {113TileLayer *layer = RSDK.GetTileLayer(l);114if (layer->width && layer->drawGroup[0] != DRAWGROUP_COUNT) {115layer->deformationOffset += 3;116117if (deformationData) {118for (int32 s = 0; s < 0x200; ++s) {119layer->deformationData[s] = deformationData[s];120layer->deformationData[s + 0x200] = deformationData[s + 0x200];121}122}123else {124int32 cnt = 8 * timer;125for (int32 s = 0; s < 0x200; ++s) {126int32 angle = RSDK.Sin256(4 * s);127layer->deformationData[s] = ((self->timer * FXRuby->deformation[cnt-- & 0x1FF]) >> 7) + ((self->timer * angle) >> 7);128layer->deformationData[s + 0x200] = layer->deformationData[s];129}130deformationData = layer->deformationData;131}132}133}134}135136void FXRuby_State_Expanding(void)137{138RSDK_THIS(FXRuby);139140self->outerRadius += self->radiusSpeed;141142if (self->outerRadius > ScreenInfo->size.x) {143self->fullyExpanded = true;144self->state = FXRuby_State_Idle;145}146}147void FXRuby_State_Shrinking(void)148{149RSDK_THIS(FXRuby);150151self->outerRadius -= self->radiusSpeed;152153if (self->outerRadius <= 0) {154self->fullyExpanded = false;155self->state = FXRuby_State_Idle;156}157}158159void FXRuby_State_Idle(void)160{161// do nothin, just chill162}163164void FXRuby_State_IncreaseStageDeform(void)165{166RSDK_THIS(FXRuby);167168FXRuby_HandleLayerDeform();169170if (++self->timer >= self->delay)171self->state = FXRuby_State_DecreaseStageDeform;172}173void FXRuby_State_DecreaseStageDeform(void)174{175RSDK_THIS(FXRuby);176177FXRuby_HandleLayerDeform();178179if (self->timer > 0)180self->timer--;181}182void FXRuby_State_ShrinkAndDestroy(void)183{184RSDK_THIS(FXRuby);185186self->radiusSpeed -= 0x3800;187self->radius += self->radiusSpeed;188self->innerRadius = 0;189self->outerRadius = self->radius >> 16;190191if (self->radius <= 0)192destroyEntity(self);193}194195#if GAME_INCLUDE_EDITOR196void FXRuby_EditorDraw(void) {}197198void FXRuby_EditorLoad(void) {}199#endif200201void FXRuby_Serialize(void)202{203RSDK_EDITABLE_VAR(FXRuby, VAR_ENUM, outerRadius);204RSDK_EDITABLE_VAR(FXRuby, VAR_ENUM, fadeWhite);205RSDK_EDITABLE_VAR(FXRuby, VAR_ENUM, fadeBlack);206RSDK_EDITABLE_VAR(FXRuby, VAR_BOOL, waitForTrigger);207}208209210