Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/OOZ/Smog.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: Smog Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectSmog *Smog;
11
12
void Smog_Update(void)
13
{
14
RSDK_THIS(Smog);
15
16
if (Smog->forceEnabled) {
17
OOZSetup->smogTimer = 0;
18
self->alpha = 0x80;
19
RSDK.SetLimitedFade(0, 1, 2, 224, 0, 255);
20
}
21
else {
22
if (OOZSetup->smogTimer <= 600) {
23
if (self->alpha > 0) {
24
RSDK.SetLimitedFade(0, 1, 2, 0, 0, 255);
25
self->alpha -= 8;
26
}
27
28
self->timer = 0;
29
}
30
else {
31
RSDK.SetLimitedFade(0, 1, 2, (OOZSetup->smogTimer - 600) >> 2, 0, 255);
32
33
if (self->alpha < 0x80)
34
self->alpha++;
35
}
36
}
37
38
if (OOZSetup->smogTimer > 1800) {
39
++self->timer;
40
41
foreach_active(Player, player)
42
{
43
if (player->superState != SUPERSTATE_SUPER) {
44
HUD_EnableRingFlash();
45
46
if (self->timer == 60 && !player->sidekick && player->rings > 0)
47
Player_GiveRings(player, -1, true);
48
}
49
}
50
51
if (self->timer == 60)
52
self->timer = 0;
53
}
54
}
55
56
void Smog_LateUpdate(void) {}
57
58
void Smog_StaticUpdate(void)
59
{
60
globals->tempFlags = OOZSetup->useSmogEffect;
61
62
if (Smog->starPostID != StarPost->postIDs[0]) {
63
Smog->starPostID = StarPost->postIDs[0];
64
globals->restartFlags = OOZSetup->useSmogEffect;
65
}
66
}
67
68
void Smog_Draw(void)
69
{
70
RSDK_THIS(Smog);
71
72
int32 y = (Zone->timer + (ScreenInfo->position.y << 1)) << 14;
73
uint8 scanlineID = ((ScreenInfo->position.y >> 1) + 2 * Zone->timer);
74
75
ScanlineInfo *scanline = Smog->scanlines;
76
for (int32 i = 0; i < ScreenInfo->size.y; ++i) {
77
scanline->position.x = TO_FIXED(ScreenInfo->position.x) + Smog->scanlineList[scanlineID].position.x;
78
scanline->position.y = y;
79
scanline->deform.x = Smog->scanlineList[scanlineID].deform.x;
80
scanline->deform.y = 0;
81
82
y += Smog->scanlineList[(scanlineID + 1) & 0xFF].deform.y;
83
scanline++;
84
scanlineID++;
85
}
86
87
if (self->alpha >= 0x80)
88
RSDK.DrawDeformedSprite(Smog->aniFrames, INK_BLEND, 0xE0);
89
else
90
RSDK.DrawDeformedSprite(Smog->aniFrames, INK_ALPHA, self->alpha);
91
}
92
93
void Smog_Create(void *data)
94
{
95
RSDK_THIS(Smog);
96
97
if (!SceneInfo->inEditor) {
98
self->active = ACTIVE_NORMAL;
99
self->visible = true;
100
self->inkEffect = INK_ALPHA;
101
self->drawGroup = Zone->hudDrawGroup - 1;
102
103
OOZSetup->smogTimer = 0;
104
105
if (!SceneInfo->milliseconds && !SceneInfo->seconds && !SceneInfo->minutes) {
106
Smog->starPostID = 0;
107
globals->restartFlags = 1;
108
globals->tempFlags = 1;
109
OOZSetup->useSmogEffect = true;
110
}
111
else {
112
if (isMainGameMode() && globals->enableIntro) {
113
if (CutsceneRules_CheckStageReload()) {
114
if (SceneInfo->minutes == globals->tempMinutes && SceneInfo->seconds == globals->tempSeconds
115
&& SceneInfo->milliseconds == globals->tempMilliseconds) {
116
OOZSetup->useSmogEffect = globals->tempFlags;
117
}
118
else {
119
OOZSetup->useSmogEffect = globals->restartFlags;
120
}
121
122
EntityZone *zone = RSDK_GET_ENTITY(SLOT_ZONE, Zone);
123
zone->fadeColor = 0x000000;
124
zone->timer = 0;
125
zone->visible = true;
126
zone->drawGroup = DRAWGROUP_COUNT - 1;
127
zone->stateDraw = Zone_Draw_Fade;
128
}
129
else {
130
Smog->starPostID = 0;
131
globals->restartFlags = 1;
132
globals->tempFlags = 1;
133
OOZSetup->useSmogEffect = true;
134
}
135
}
136
else {
137
if (SceneInfo->minutes == globals->tempMinutes && SceneInfo->seconds == globals->tempSeconds
138
&& SceneInfo->milliseconds == globals->tempMilliseconds) {
139
OOZSetup->useSmogEffect = globals->tempFlags;
140
}
141
else {
142
OOZSetup->useSmogEffect = globals->restartFlags;
143
}
144
145
EntityZone *zone = RSDK_GET_ENTITY(SLOT_ZONE, Zone);
146
zone->fadeColor = 0x000000;
147
zone->timer = 0;
148
zone->visible = true;
149
zone->drawGroup = DRAWGROUP_COUNT - 1;
150
zone->stateDraw = Zone_Draw_Fade;
151
}
152
}
153
}
154
}
155
156
void Smog_StageLoad(void)
157
{
158
Smog->aniFrames = RSDK.LoadSpriteSheet("OOZ/Smog.gif", SCOPE_STAGE);
159
Smog->scanlines = RSDK.GetScanlines();
160
161
ScanlineInfo *scanline = (ScanlineInfo *)Smog->scanlineList;
162
int32 angle = 0;
163
for (int32 i = 0; i < 0x100; ++i) {
164
scanline[i].deform.x = (RSDK.Sin256(angle >> 1) << 6) + 0x10000;
165
scanline[i].deform.y = (RSDK.Sin256(angle >> 1) << 5) + 0x10000;
166
scanline[i].position.x = (RSDK.Sin256(angle) << 10) - scanline[i].deform.x * ScreenInfo->center.x;
167
scanline[i].position.y = 0;
168
169
angle += 2;
170
}
171
172
RSDK.CopyPalette(0, 0, 1, 0, 128);
173
RSDK.CopyPalette(0, 0, 2, 0, 128);
174
RSDK.SetLimitedFade(2, 1, 3, 64, 0, 127);
175
RSDK.SetLimitedFade(0, 1, 2, 0, 0, 255);
176
RSDK.SetDrawGroupProperties(Zone->hudDrawGroup - 1, false, Smog_DrawHook_ApplySmogPalette);
177
}
178
179
void Smog_DrawHook_ApplySmogPalette(void) { RSDK.CopyPalette(1, 0, 0, 0, 128); }
180
181
#if GAME_INCLUDE_EDITOR
182
void Smog_EditorDraw(void) {}
183
184
void Smog_EditorLoad(void) {}
185
#endif
186
187
void Smog_Serialize(void) {}
188
189