Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/FBZ/FBZStorm.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: FBZStorm Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectFBZStorm *FBZStorm;
11
12
void FBZStorm_Update(void)
13
{
14
RSDK_THIS(FBZStorm);
15
16
StateMachine_Run(self->state);
17
18
self->velocity.x = -0x40000;
19
foreach_active(Current, current)
20
{
21
int32 strength = -0x10000 * current->strength;
22
if (strength < self->velocity.x)
23
self->velocity.x = strength;
24
}
25
26
for (int32 p = 0; p < Player->playerCount; ++p) {
27
if (!RSDK_GET_ENTITY(p, Player)->sidekick) {
28
self->screenPosX[p] = ScreenInfo[p].position.x;
29
30
int32 velX = ((self->screenPosX[p] << 14) - (ScreenInfo[p].position.x << 14)) + self->velocity.x;
31
self->stormAngle[p] = RSDK.ATan2(self->velocity.y, -velX) << 1;
32
33
Vector2 *pos = &FBZStorm->raindropPositions[0x40 * p];
34
35
for (int32 i = 0; i < 0x40; ++i) {
36
pos->x += velX;
37
pos->y += self->velocity.y;
38
39
if (pos->x < -0x1000000)
40
pos->x += 0x2000000;
41
42
if (pos->y < -0xA00000)
43
pos->y += 0x1400000;
44
45
if (pos->x > 0x1000000)
46
pos->x -= 0x2000000;
47
48
if (pos->y > 0xA00000)
49
pos->y -= 0x1400000;
50
51
++pos;
52
}
53
}
54
}
55
56
// BGStorm layer
57
if (RSDK.GetTileLayer(3)->drawGroup[0] < DRAWGROUP_COUNT) {
58
self->enabled = true;
59
if (self->blendAmount < 0x100) {
60
self->blendAmount += 8;
61
RSDK.SetLimitedFade(0, FBZStorm->outsideBank, 2, self->blendAmount, 0x80, 0x100);
62
}
63
}
64
else {
65
self->enabled = false;
66
if (self->blendAmount > 0) {
67
self->blendAmount -= 8;
68
RSDK.SetLimitedFade(0, FBZStorm->outsideBank, 2, self->blendAmount, 0x80, 0x100);
69
}
70
}
71
}
72
73
void FBZStorm_LateUpdate(void) {}
74
75
void FBZStorm_StaticUpdate(void)
76
{
77
bool32 enabled = false;
78
foreach_all(FBZStorm, storm)
79
{
80
if (storm->enabled)
81
enabled = true;
82
}
83
84
if (!enabled || RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu)->classID == PauseMenu->classID) {
85
if (FBZStorm->playingRainSfx) {
86
RSDK.StopSfx(FBZStorm->sfxRain);
87
FBZStorm->playingRainSfx = false;
88
}
89
}
90
}
91
92
void FBZStorm_Draw(void)
93
{
94
RSDK_THIS(FBZStorm);
95
RSDKScreenInfo *screen = &ScreenInfo[SceneInfo->currentScreenID];
96
97
int32 centerX = screen->center.x << 16;
98
int32 centerY = screen->center.y << 16;
99
self->rotation = self->stormAngle[SceneInfo->currentScreenID];
100
101
Vector2 *raindropPos = &FBZStorm->raindropPositions[0x40 * SceneInfo->currentScreenID];
102
for (int32 i = 0; i < 0x40; ++i) {
103
Vector2 drawPos;
104
drawPos.x = centerX + raindropPos->x;
105
drawPos.y = centerY + raindropPos->y;
106
RSDK.DrawSprite(&self->animator, &drawPos, true);
107
++raindropPos;
108
}
109
}
110
111
void FBZStorm_Create(void *data)
112
{
113
RSDK_THIS(FBZStorm);
114
115
if (!SceneInfo->inEditor) {
116
self->active = ACTIVE_NORMAL;
117
self->drawGroup = Zone->objectDrawGroup[1];
118
self->drawFX = FX_ROTATE;
119
self->inkEffect = INK_ALPHA;
120
self->velocity.x = -0x40000;
121
self->velocity.y = 0xC0000;
122
self->state = FBZStorm_State_WaitForActive;
123
124
for (int32 p = 0; p < Player->playerCount; ++p) {
125
for (int32 i = 0; i < 0x40; ++i) {
126
FBZStorm->raindropPositions[i].x = RSDK.Rand(-0x1000000, 0x1000000);
127
FBZStorm->raindropPositions[i].y = RSDK.Rand(-0x800000, 0x800000);
128
}
129
}
130
131
RSDK.SetSpriteAnimation(FBZStorm->aniFrames, 0, &self->animator, true, 0);
132
}
133
}
134
135
void FBZStorm_StageLoad(void)
136
{
137
FBZStorm->active = ACTIVE_ALWAYS;
138
139
FBZStorm->aniFrames = RSDK.LoadSpriteAnimation("FBZ/Storm.bin", SCOPE_STAGE);
140
141
FBZStorm->sfxRain = RSDK.GetSfx("FBZ/Rain.wav");
142
FBZStorm->sfxThunder = RSDK.GetSfx("FBZ/Thunder.wav");
143
}
144
145
void FBZStorm_State_WaitForActive(void)
146
{
147
RSDK_THIS(FBZStorm);
148
149
if (self->enabled) {
150
if (RSDK.GetEntityCount(Current->classID, true) > 0)
151
self->state = FBZStorm_State_StormStart;
152
}
153
}
154
155
void FBZStorm_State_StormStart(void)
156
{
157
RSDK_THIS(FBZStorm);
158
159
self->visible = true;
160
if (self->alpha >= 0x80) {
161
FBZStorm->outsideBank = 4;
162
self->inkEffect = INK_BLEND;
163
self->state = FBZStorm_State_Storming;
164
}
165
else {
166
self->alpha += 4;
167
}
168
169
bool32 enabled = false;
170
foreach_all(FBZStorm, storm)
171
{
172
if (storm->enabled)
173
enabled = true;
174
}
175
176
if (FBZStorm->playingRainSfx) {
177
if (!enabled || RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu)->classID == PauseMenu->classID) {
178
RSDK.StopSfx(FBZStorm->sfxRain);
179
FBZStorm->playingRainSfx = false;
180
}
181
}
182
else {
183
RSDK.PlaySfx(FBZStorm->sfxRain, true, 0xFF);
184
FBZStorm->playingRainSfx = true;
185
}
186
}
187
188
void FBZStorm_State_StormFinish(void)
189
{
190
RSDK_THIS(FBZStorm);
191
192
if (self->alpha <= 0) {
193
self->visible = false;
194
if (FBZStorm->playingRainSfx) {
195
RSDK.StopSfx(FBZStorm->sfxRain);
196
}
197
self->state = FBZStorm_State_WaitForActive;
198
}
199
else {
200
self->alpha -= 4;
201
}
202
}
203
204
void FBZStorm_State_Storming(void)
205
{
206
RSDK_THIS(FBZStorm);
207
208
if (self->thunderTimer <= 0) {
209
self->state = FBZStorm_State_Thunder;
210
}
211
else {
212
self->thunderTimer--;
213
if (!self->enabled) {
214
self->inkEffect = INK_ALPHA;
215
self->state = FBZStorm_State_StormFinish;
216
}
217
}
218
}
219
220
void FBZStorm_State_Thunder(void)
221
{
222
RSDK_THIS(FBZStorm);
223
224
RSDK.SetLimitedFade(0, 2, 3, FBZStorm->thunderFade[self->thunderTimer], 0x80, 0x100);
225
226
if (!self->thunderTimer)
227
RSDK.PlaySfx(FBZStorm->sfxThunder, false, 255);
228
229
if (++self->thunderTimer == 20) {
230
self->thunderTimer = RSDK.Rand(180, 320);
231
self->state = FBZStorm_State_Storming;
232
}
233
}
234
235
#if GAME_INCLUDE_EDITOR
236
void FBZStorm_EditorDraw(void) {}
237
238
void FBZStorm_EditorLoad(void) {}
239
#endif
240
241
void FBZStorm_Serialize(void) {}
242
243