Path: blob/master/SonicMania/Objects/GHZ/WaterfallSound.c
338 views
// ---------------------------------------------------------------------1// RSDK Project: Sonic Mania2// Object Description: WaterfallSound Object3// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges4// Decompiled by: Rubberduckycooly & RMGRich5// ---------------------------------------------------------------------67#include "Game.h"89#if MANIA_USE_PLUS10ObjectWaterfallSound *WaterfallSound;1112void WaterfallSound_Update(void) {}1314void WaterfallSound_LateUpdate(void) {}1516void WaterfallSound_StaticUpdate(void) {}1718void WaterfallSound_Draw(void)19{20RSDK_THIS(WaterfallSound);2122RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,23self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);24RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y,25self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);26RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,27self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);28RSDK.DrawLine(self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,29self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);3031if (self->sfxActive)32DrawHelpers_DrawCross(self->sfxPos.x, self->sfxPos.y, 0x200000, 0x200000, 0xFF00FF);33}3435void WaterfallSound_Create(void *data)36{37RSDK_THIS(WaterfallSound);38if (!SceneInfo->inEditor) {39self->updateRange.x = TILE_SIZE * self->size.x;40self->updateRange.y = TILE_SIZE * self->size.y;41self->visible = true;42self->active = ACTIVE_NEVER;43self->sfxPos.x = 0;44self->sfxPos.y = 0;45self->drawGroup = Zone->objectDrawGroup[1];46}47}4849void WaterfallSound_StageLoad(void)50{51if (globals->gameMode != MODE_COMPETITION)52Soundboard_LoadSfx("Stage/WaterfallLoop.wav", 2820, WaterfallSound_SfxCheck_WaterfallLoop, WaterfallSound_SfxUpdate_WaterfallLoop);53}5455bool32 WaterfallSound_SfxCheck_WaterfallLoop(void)56{57int32 worldCenterX = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;58int32 worldCenterY = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;5960WaterfallSound->activeCount = 0;61int32 count = 0;6263foreach_all(WaterfallSound, sound)64{65sound->sfxActive = false;66sound->sfxPos.x = 0;67sound->sfxPos.y = 0;6869Hitbox hitbox;70hitbox.left = -(sound->size.x >> 12);71hitbox.top = -(sound->size.y >> 12);72hitbox.right = sound->size.x >> 12;73hitbox.bottom = sound->size.y >> 12;7475if (MathHelpers_PointInHitbox(sound->position.x, sound->position.y, worldCenterX, worldCenterY, FLIP_NONE, &hitbox)) {76++count;77sound->sfxActive = true;78sound->sfxPos.x = worldCenterX;79sound->sfxPos.y = worldCenterY;80}81else {82if (MathHelpers_Distance(sound->position.x, sound->position.y, worldCenterX, worldCenterY) - 8 * sound->size.y - 8 * sound->size.x83<= 0x2800000) {84if (MathHelpers_ConstrainToBox(&sound->sfxPos, worldCenterX, worldCenterY, sound->position, hitbox)) {85if (MathHelpers_Distance(sound->sfxPos.x, sound->sfxPos.y, worldCenterX, worldCenterY) <= 0x2800000) {86sound->sfxActive = true;87++count;88}89}90}91}92}9394WaterfallSound->activeCount = count;95return WaterfallSound->activeCount > 0;96}97void WaterfallSound_SfxUpdate_WaterfallLoop(int32 sfxID)98{99int32 worldCenterX = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;100int32 worldCenterY = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;101int32 worldLeft = worldCenterX - (ScreenInfo->center.x << 16);102int32 worldRight = worldCenterX + (ScreenInfo->center.x << 16);103104float pan = 0.0f;105float volDivisor = 0.0f;106int32 dist = 0x7FFF0000;107108foreach_all(WaterfallSound, sound)109{110if (sound->sfxActive) {111int16 sqRoot = MIN(MathHelpers_Distance(sound->sfxPos.x, sound->sfxPos.y, worldCenterX, worldCenterY) >> 16, 640);112float volume = (sqRoot / -640.0f) + 1.0f;113float distance = -1.0;114if (sound->sfxPos.x > worldLeft) {115distance = 1.0;116if (sound->sfxPos.x < worldRight) {117distance = (((sound->sfxPos.x - worldCenterX) >> 16) / (float)ScreenInfo->center.x);118}119}120volDivisor += volume;121if (dist >= (sqRoot << 16))122dist = (sqRoot << 16);123pan += volume * distance;124}125}126127float div = FABS(volDivisor);128if (div > 0)129pan /= volDivisor;130131float volume = MIN(dist >> 16, 640);132RSDK.SetChannelAttributes(Soundboard->sfxChannel[sfxID], (volume / -640.0f) + 1.0, CLAMP(pan, -1.0, 1.0), 1.0f);133}134135#if GAME_INCLUDE_EDITOR136void WaterfallSound_EditorDraw(void)137{138RSDK_THIS(WaterfallSound);139140self->updateRange.x = TILE_SIZE * self->size.x;141self->updateRange.y = TILE_SIZE * self->size.y;142143RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,144self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);145RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y,146self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);147RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,148self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);149RSDK.DrawLine(self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,150self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);151152self->drawFX = FX_FLIP;153RSDK.SetSpriteAnimation(WaterfallSound->aniFrames, 0, &self->animator, true, 0);154155Vector2 drawPos;156drawPos.x = self->position.x;157drawPos.y = self->position.y;158drawPos.x -= (TILE_SIZE * self->size.x);159drawPos.y -= (TILE_SIZE * self->size.y);160161self->direction = FLIP_NONE;162RSDK.DrawSprite(&self->animator, &drawPos, false);163164drawPos.x += (TILE_SIZE * self->size.x) << 1;165self->direction = FLIP_X;166RSDK.DrawSprite(&self->animator, &drawPos, false);167168drawPos.y += (TILE_SIZE * self->size.y) << 1;169self->direction = FLIP_XY;170RSDK.DrawSprite(&self->animator, &drawPos, false);171172drawPos.x -= (TILE_SIZE * self->size.x) << 1;173self->direction = FLIP_Y;174RSDK.DrawSprite(&self->animator, &drawPos, false);175}176177void WaterfallSound_EditorLoad(void) { WaterfallSound->aniFrames = RSDK.LoadSpriteAnimation("Global/TicMark.bin", SCOPE_STAGE); }178#endif179180void WaterfallSound_Serialize(void) { RSDK_EDITABLE_VAR(WaterfallSound, VAR_VECTOR2, size); }181#endif182183184