Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/GHZ/WaterfallSound.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: WaterfallSound Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
#if MANIA_USE_PLUS
11
ObjectWaterfallSound *WaterfallSound;
12
13
void WaterfallSound_Update(void) {}
14
15
void WaterfallSound_LateUpdate(void) {}
16
17
void WaterfallSound_StaticUpdate(void) {}
18
19
void WaterfallSound_Draw(void)
20
{
21
RSDK_THIS(WaterfallSound);
22
23
RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,
24
self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
25
RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y,
26
self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
27
RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,
28
self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
29
RSDK.DrawLine(self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,
30
self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
31
32
if (self->sfxActive)
33
DrawHelpers_DrawCross(self->sfxPos.x, self->sfxPos.y, 0x200000, 0x200000, 0xFF00FF);
34
}
35
36
void WaterfallSound_Create(void *data)
37
{
38
RSDK_THIS(WaterfallSound);
39
if (!SceneInfo->inEditor) {
40
self->updateRange.x = TILE_SIZE * self->size.x;
41
self->updateRange.y = TILE_SIZE * self->size.y;
42
self->visible = true;
43
self->active = ACTIVE_NEVER;
44
self->sfxPos.x = 0;
45
self->sfxPos.y = 0;
46
self->drawGroup = Zone->objectDrawGroup[1];
47
}
48
}
49
50
void WaterfallSound_StageLoad(void)
51
{
52
if (globals->gameMode != MODE_COMPETITION)
53
Soundboard_LoadSfx("Stage/WaterfallLoop.wav", 2820, WaterfallSound_SfxCheck_WaterfallLoop, WaterfallSound_SfxUpdate_WaterfallLoop);
54
}
55
56
bool32 WaterfallSound_SfxCheck_WaterfallLoop(void)
57
{
58
int32 worldCenterX = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;
59
int32 worldCenterY = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;
60
61
WaterfallSound->activeCount = 0;
62
int32 count = 0;
63
64
foreach_all(WaterfallSound, sound)
65
{
66
sound->sfxActive = false;
67
sound->sfxPos.x = 0;
68
sound->sfxPos.y = 0;
69
70
Hitbox hitbox;
71
hitbox.left = -(sound->size.x >> 12);
72
hitbox.top = -(sound->size.y >> 12);
73
hitbox.right = sound->size.x >> 12;
74
hitbox.bottom = sound->size.y >> 12;
75
76
if (MathHelpers_PointInHitbox(sound->position.x, sound->position.y, worldCenterX, worldCenterY, FLIP_NONE, &hitbox)) {
77
++count;
78
sound->sfxActive = true;
79
sound->sfxPos.x = worldCenterX;
80
sound->sfxPos.y = worldCenterY;
81
}
82
else {
83
if (MathHelpers_Distance(sound->position.x, sound->position.y, worldCenterX, worldCenterY) - 8 * sound->size.y - 8 * sound->size.x
84
<= 0x2800000) {
85
if (MathHelpers_ConstrainToBox(&sound->sfxPos, worldCenterX, worldCenterY, sound->position, hitbox)) {
86
if (MathHelpers_Distance(sound->sfxPos.x, sound->sfxPos.y, worldCenterX, worldCenterY) <= 0x2800000) {
87
sound->sfxActive = true;
88
++count;
89
}
90
}
91
}
92
}
93
}
94
95
WaterfallSound->activeCount = count;
96
return WaterfallSound->activeCount > 0;
97
}
98
void WaterfallSound_SfxUpdate_WaterfallLoop(int32 sfxID)
99
{
100
int32 worldCenterX = (ScreenInfo->position.x + ScreenInfo->center.x) << 16;
101
int32 worldCenterY = (ScreenInfo->position.y + ScreenInfo->center.y) << 16;
102
int32 worldLeft = worldCenterX - (ScreenInfo->center.x << 16);
103
int32 worldRight = worldCenterX + (ScreenInfo->center.x << 16);
104
105
float pan = 0.0f;
106
float volDivisor = 0.0f;
107
int32 dist = 0x7FFF0000;
108
109
foreach_all(WaterfallSound, sound)
110
{
111
if (sound->sfxActive) {
112
int16 sqRoot = MIN(MathHelpers_Distance(sound->sfxPos.x, sound->sfxPos.y, worldCenterX, worldCenterY) >> 16, 640);
113
float volume = (sqRoot / -640.0f) + 1.0f;
114
float distance = -1.0;
115
if (sound->sfxPos.x > worldLeft) {
116
distance = 1.0;
117
if (sound->sfxPos.x < worldRight) {
118
distance = (((sound->sfxPos.x - worldCenterX) >> 16) / (float)ScreenInfo->center.x);
119
}
120
}
121
volDivisor += volume;
122
if (dist >= (sqRoot << 16))
123
dist = (sqRoot << 16);
124
pan += volume * distance;
125
}
126
}
127
128
float div = FABS(volDivisor);
129
if (div > 0)
130
pan /= volDivisor;
131
132
float volume = MIN(dist >> 16, 640);
133
RSDK.SetChannelAttributes(Soundboard->sfxChannel[sfxID], (volume / -640.0f) + 1.0, CLAMP(pan, -1.0, 1.0), 1.0f);
134
}
135
136
#if GAME_INCLUDE_EDITOR
137
void WaterfallSound_EditorDraw(void)
138
{
139
RSDK_THIS(WaterfallSound);
140
141
self->updateRange.x = TILE_SIZE * self->size.x;
142
self->updateRange.y = TILE_SIZE * self->size.y;
143
144
RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,
145
self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
146
RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y,
147
self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
148
RSDK.DrawLine(self->position.x - TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,
149
self->position.x - TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
150
RSDK.DrawLine(self->position.x + TILE_SIZE * self->size.x, self->position.y - TILE_SIZE * self->size.y,
151
self->position.x + TILE_SIZE * self->size.x, self->position.y + TILE_SIZE * self->size.y, 0xFFFF00, 0xFF, INK_NONE, false);
152
153
self->drawFX = FX_FLIP;
154
RSDK.SetSpriteAnimation(WaterfallSound->aniFrames, 0, &self->animator, true, 0);
155
156
Vector2 drawPos;
157
drawPos.x = self->position.x;
158
drawPos.y = self->position.y;
159
drawPos.x -= (TILE_SIZE * self->size.x);
160
drawPos.y -= (TILE_SIZE * self->size.y);
161
162
self->direction = FLIP_NONE;
163
RSDK.DrawSprite(&self->animator, &drawPos, false);
164
165
drawPos.x += (TILE_SIZE * self->size.x) << 1;
166
self->direction = FLIP_X;
167
RSDK.DrawSprite(&self->animator, &drawPos, false);
168
169
drawPos.y += (TILE_SIZE * self->size.y) << 1;
170
self->direction = FLIP_XY;
171
RSDK.DrawSprite(&self->animator, &drawPos, false);
172
173
drawPos.x -= (TILE_SIZE * self->size.x) << 1;
174
self->direction = FLIP_Y;
175
RSDK.DrawSprite(&self->animator, &drawPos, false);
176
}
177
178
void WaterfallSound_EditorLoad(void) { WaterfallSound->aniFrames = RSDK.LoadSpriteAnimation("Global/TicMark.bin", SCOPE_STAGE); }
179
#endif
180
181
void WaterfallSound_Serialize(void) { RSDK_EDITABLE_VAR(WaterfallSound, VAR_VECTOR2, size); }
182
#endif
183
184