Path: blob/master/SonicMania/Objects/FBZ/FBZStorm.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: FBZStorm Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89ObjectFBZStorm *FBZStorm;1011void FBZStorm_Update(void)12{13RSDK_THIS(FBZStorm);1415StateMachine_Run(self->state);1617self->velocity.x = -0x40000;18foreach_active(Current, current)19{20int32 strength = -0x10000 * current->strength;21if (strength < self->velocity.x)22self->velocity.x = strength;23}2425for (int32 p = 0; p < Player->playerCount; ++p) {26if (!RSDK_GET_ENTITY(p, Player)->sidekick) {27self->screenPosX[p] = ScreenInfo[p].position.x;2829int32 velX = ((self->screenPosX[p] << 14) - (ScreenInfo[p].position.x << 14)) + self->velocity.x;30self->stormAngle[p] = RSDK.ATan2(self->velocity.y, -velX) << 1;3132Vector2 *pos = &FBZStorm->raindropPositions[0x40 * p];3334for (int32 i = 0; i < 0x40; ++i) {35pos->x += velX;36pos->y += self->velocity.y;3738if (pos->x < -0x1000000)39pos->x += 0x2000000;4041if (pos->y < -0xA00000)42pos->y += 0x1400000;4344if (pos->x > 0x1000000)45pos->x -= 0x2000000;4647if (pos->y > 0xA00000)48pos->y -= 0x1400000;4950++pos;51}52}53}5455// BGStorm layer56if (RSDK.GetTileLayer(3)->drawGroup[0] < DRAWGROUP_COUNT) {57self->enabled = true;58if (self->blendAmount < 0x100) {59self->blendAmount += 8;60RSDK.SetLimitedFade(0, FBZStorm->outsideBank, 2, self->blendAmount, 0x80, 0x100);61}62}63else {64self->enabled = false;65if (self->blendAmount > 0) {66self->blendAmount -= 8;67RSDK.SetLimitedFade(0, FBZStorm->outsideBank, 2, self->blendAmount, 0x80, 0x100);68}69}70}7172void FBZStorm_LateUpdate(void) {}7374void FBZStorm_StaticUpdate(void)75{76bool32 enabled = false;77foreach_all(FBZStorm, storm)78{79if (storm->enabled)80enabled = true;81}8283if (!enabled || RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu)->classID == PauseMenu->classID) {84if (FBZStorm->playingRainSfx) {85RSDK.StopSfx(FBZStorm->sfxRain);86FBZStorm->playingRainSfx = false;87}88}89}9091void FBZStorm_Draw(void)92{93RSDK_THIS(FBZStorm);94RSDKScreenInfo *screen = &ScreenInfo[SceneInfo->currentScreenID];9596int32 centerX = screen->center.x << 16;97int32 centerY = screen->center.y << 16;98self->rotation = self->stormAngle[SceneInfo->currentScreenID];99100Vector2 *raindropPos = &FBZStorm->raindropPositions[0x40 * SceneInfo->currentScreenID];101for (int32 i = 0; i < 0x40; ++i) {102Vector2 drawPos;103drawPos.x = centerX + raindropPos->x;104drawPos.y = centerY + raindropPos->y;105RSDK.DrawSprite(&self->animator, &drawPos, true);106++raindropPos;107}108}109110void FBZStorm_Create(void *data)111{112RSDK_THIS(FBZStorm);113114if (!SceneInfo->inEditor) {115self->active = ACTIVE_NORMAL;116self->drawGroup = Zone->objectDrawGroup[1];117self->drawFX = FX_ROTATE;118self->inkEffect = INK_ALPHA;119self->velocity.x = -0x40000;120self->velocity.y = 0xC0000;121self->state = FBZStorm_State_WaitForActive;122123for (int32 p = 0; p < Player->playerCount; ++p) {124for (int32 i = 0; i < 0x40; ++i) {125FBZStorm->raindropPositions[i].x = RSDK.Rand(-0x1000000, 0x1000000);126FBZStorm->raindropPositions[i].y = RSDK.Rand(-0x800000, 0x800000);127}128}129130RSDK.SetSpriteAnimation(FBZStorm->aniFrames, 0, &self->animator, true, 0);131}132}133134void FBZStorm_StageLoad(void)135{136FBZStorm->active = ACTIVE_ALWAYS;137138FBZStorm->aniFrames = RSDK.LoadSpriteAnimation("FBZ/Storm.bin", SCOPE_STAGE);139140FBZStorm->sfxRain = RSDK.GetSfx("FBZ/Rain.wav");141FBZStorm->sfxThunder = RSDK.GetSfx("FBZ/Thunder.wav");142}143144void FBZStorm_State_WaitForActive(void)145{146RSDK_THIS(FBZStorm);147148if (self->enabled) {149if (RSDK.GetEntityCount(Current->classID, true) > 0)150self->state = FBZStorm_State_StormStart;151}152}153154void FBZStorm_State_StormStart(void)155{156RSDK_THIS(FBZStorm);157158self->visible = true;159if (self->alpha >= 0x80) {160FBZStorm->outsideBank = 4;161self->inkEffect = INK_BLEND;162self->state = FBZStorm_State_Storming;163}164else {165self->alpha += 4;166}167168bool32 enabled = false;169foreach_all(FBZStorm, storm)170{171if (storm->enabled)172enabled = true;173}174175if (FBZStorm->playingRainSfx) {176if (!enabled || RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu)->classID == PauseMenu->classID) {177RSDK.StopSfx(FBZStorm->sfxRain);178FBZStorm->playingRainSfx = false;179}180}181else {182RSDK.PlaySfx(FBZStorm->sfxRain, true, 0xFF);183FBZStorm->playingRainSfx = true;184}185}186187void FBZStorm_State_StormFinish(void)188{189RSDK_THIS(FBZStorm);190191if (self->alpha <= 0) {192self->visible = false;193if (FBZStorm->playingRainSfx) {194RSDK.StopSfx(FBZStorm->sfxRain);195}196self->state = FBZStorm_State_WaitForActive;197}198else {199self->alpha -= 4;200}201}202203void FBZStorm_State_Storming(void)204{205RSDK_THIS(FBZStorm);206207if (self->thunderTimer <= 0) {208self->state = FBZStorm_State_Thunder;209}210else {211self->thunderTimer--;212if (!self->enabled) {213self->inkEffect = INK_ALPHA;214self->state = FBZStorm_State_StormFinish;215}216}217}218219void FBZStorm_State_Thunder(void)220{221RSDK_THIS(FBZStorm);222223RSDK.SetLimitedFade(0, 2, 3, FBZStorm->thunderFade[self->thunderTimer], 0x80, 0x100);224225if (!self->thunderTimer)226RSDK.PlaySfx(FBZStorm->sfxThunder, false, 255);227228if (++self->thunderTimer == 20) {229self->thunderTimer = RSDK.Rand(180, 320);230self->state = FBZStorm_State_Storming;231}232}233234#if GAME_INCLUDE_EDITOR235void FBZStorm_EditorDraw(void) {}236237void FBZStorm_EditorLoad(void) {}238#endif239240void FBZStorm_Serialize(void) {}241242243