Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Pinball/PBL_Setup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PBL_Setup 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
ObjectPBL_Setup *PBL_Setup;
12
13
void PBL_Setup_Update(void)
14
{
15
RSDK_THIS(PBL_Setup);
16
17
StateMachine_Run(self->state);
18
19
if (self->state != PBL_Setup_SaveAndChangeScene && globals->gameMode < MODE_TIMEATTACK)
20
++SaveGame_GetSaveRAM()->zoneTimes[28];
21
}
22
23
void PBL_Setup_LateUpdate(void) {}
24
25
void PBL_Setup_StaticUpdate(void)
26
{
27
RSDK_THIS_GEN();
28
29
++PBL_Setup->timer;
30
PBL_Setup->timer &= 0x7FFF;
31
32
if (!(PBL_Setup->timer & 1)) {
33
++PBL_Setup->ringFrame;
34
PBL_Setup->ringFrame &= 0xF;
35
}
36
37
if (!(PBL_Setup->timer & 0xF)) {
38
for (int32 i = 0; i < 8; ++i) {
39
RSDK.RotatePalette(i, 176, 181, true);
40
RSDK.RotatePalette(i, 176, 181, true);
41
}
42
}
43
44
PBL_Setup->scanlineTimer += 0x8000;
45
PBL_Setup->scanlineTimer &= 0x7FFFFFFF;
46
47
if ((ControllerInfo->keyStart.press || Unknown_pausePress) && SceneInfo->state == ENGINESTATE_REGULAR
48
&& !RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu)->classID) {
49
RSDK.ResetEntitySlot(SLOT_PAUSEMENU, PauseMenu->classID, NULL);
50
51
EntityPauseMenu *pauseMenu = RSDK_GET_ENTITY(SLOT_PAUSEMENU, PauseMenu);
52
pauseMenu->disableRestart = true;
53
pauseMenu->triggerPlayer = RSDK.GetEntitySlot(self);
54
}
55
}
56
57
void PBL_Setup_Draw(void)
58
{
59
RSDK_THIS(PBL_Setup);
60
61
RSDK.FillScreen(self->color, self->timer, self->timer - 128, self->timer - 256);
62
}
63
64
void PBL_Setup_Create(void *data)
65
{
66
RSDK_THIS(PBL_Setup);
67
68
self->active = ACTIVE_NORMAL;
69
self->visible = true;
70
self->drawGroup = DRAWGROUP_COUNT - 1;
71
self->color = 0xF0F0F0;
72
self->timer = 512;
73
74
self->state = PBL_Setup_State_FadeIn;
75
}
76
77
void PBL_Setup_StageLoad(void)
78
{
79
PBL_Setup->tableLow = RSDK.GetTileLayerID("Table Low");
80
PBL_Setup->tableHigh = RSDK.GetTileLayerID("Table High");
81
82
PBL_Setup->rings = 0;
83
PBL_Setup->sectorID = 0;
84
PBL_Setup->sectorCount = 0;
85
PBL_Setup->score = 0;
86
PBL_Setup->score1UP = 10000;
87
88
RSDK.GetTileLayer(PBL_Setup->tableLow)->scanlineCallback = PBL_Setup_Scanline_TableLow;
89
RSDK.GetTileLayer(PBL_Setup->tableHigh)->scanlineCallback = PBL_Setup_Scanline_TableHigh;
90
RSDK.GetTileLayer(1)->scanlineCallback = PBL_Setup_Scanline_PinballBG;
91
92
RSDK.SetDrawGroupProperties(1, false, PBL_Setup_DrawHook_PrepareDrawingFX);
93
RSDK.SetDrawGroupProperties(3, false, PBL_Setup_DrawHook_PrepareDrawingFX);
94
RSDK.SetDrawGroupProperties(4, true, StateMachine_None);
95
96
RSDK.SetLimitedFade(1, 0, 7, 36, 0, 255);
97
RSDK.SetLimitedFade(2, 0, 7, 72, 0, 255);
98
RSDK.SetLimitedFade(3, 0, 7, 108, 0, 255);
99
RSDK.SetLimitedFade(4, 0, 7, 144, 0, 255);
100
RSDK.SetLimitedFade(5, 0, 7, 180, 0, 255);
101
RSDK.SetLimitedFade(6, 0, 7, 216, 0, 255);
102
103
RSDK.ResetEntitySlot(SLOT_PBL_SETUP, PBL_Setup->classID, NULL);
104
105
PBL_Setup->sfxContinue = RSDK.GetSfx("Special/Continue.wav");
106
}
107
108
void PBL_Setup_Scanline_TableLow(ScanlineInfo *scanlines)
109
{
110
EntityPBL_Camera *camera = RSDK_GET_ENTITY(SLOT_PBL_CAMERA, PBL_Camera);
111
RSDK.SetClipBounds(0, 0, camera->centerY, ScreenInfo->size.x, ScreenInfo->size.y);
112
113
int32 sin = RSDK.Sin1024(camera->angle) >> 2;
114
int32 cos = RSDK.Cos1024(camera->angle) >> 2;
115
int32 negSin = RSDK.Sin1024(-camera->rotationY) >> 2;
116
int32 negCos = RSDK.Cos1024(-camera->rotationY) >> 2;
117
int32 cosVal = -ScreenInfo->center.y * negCos;
118
119
for (int32 i = -ScreenInfo->center.y; i < ScreenInfo->center.y; ++i) {
120
int32 div = negSin + (cosVal >> 8);
121
if (!div)
122
div = 1;
123
124
int32 mult = camera->worldY / div;
125
scanlines->deform.x = -(cos * mult) >> 8;
126
scanlines->deform.y = sin * mult >> 8;
127
128
int32 pos = (negCos * mult >> 8) - (negSin * (i * mult >> 8) >> 8);
129
RSDK.SetActivePalette(CLAMP((abs(pos) >> 12) - 27, 0, 7), i + 120, i + 121);
130
131
scanlines->position.x = (sin * pos - ScreenInfo->center.x * scanlines->deform.x) + camera->position.x;
132
scanlines->position.y = (cos * pos - ScreenInfo->center.x * scanlines->deform.y) + camera->position.y;
133
134
cosVal += negCos;
135
scanlines++;
136
}
137
}
138
void PBL_Setup_Scanline_TableHigh(ScanlineInfo *scanlines)
139
{
140
EntityPBL_Camera *camera = RSDK_GET_ENTITY(SLOT_PBL_CAMERA, PBL_Camera);
141
RSDK.SetClipBounds(0, 0, camera->centerY, ScreenInfo->size.x, ScreenInfo->size.y);
142
143
int32 sin = RSDK.Sin1024(camera->angle) >> 2;
144
int32 cos = RSDK.Cos1024(camera->angle) >> 2;
145
int32 negSin = RSDK.Sin1024(-camera->rotationY) >> 2;
146
int32 negCos = RSDK.Cos1024(-camera->rotationY) >> 2;
147
int32 cosVal = -ScreenInfo->center.y * negCos;
148
149
for (int32 i = -ScreenInfo->center.y; i < ScreenInfo->center.y; ++i) {
150
int32 div = negSin + (cosVal >> 8);
151
if (!div)
152
div = 1;
153
154
int32 mult = (camera->worldY - 0x100000) / div;
155
scanlines->deform.x = -(cos * mult) >> 8;
156
scanlines->deform.y = sin * mult >> 8;
157
158
int32 pos = (negCos * mult >> 8) - (negSin * (i * mult >> 8) >> 8);
159
RSDK.SetActivePalette(CLAMP((abs(pos) >> 12) - 24, 0, 7), i + 120, i + 121);
160
161
scanlines->position.x = (sin * pos - ScreenInfo->center.x * scanlines->deform.x) + camera->position.x;
162
scanlines->position.y = (cos * pos - ScreenInfo->center.x * scanlines->deform.y) + camera->position.y;
163
164
cosVal += negCos;
165
scanlines++;
166
}
167
}
168
void PBL_Setup_Scanline_PinballBG(ScanlineInfo *scanlines)
169
{
170
RSDK.SetClipBounds(0, 0, 0, ScreenInfo->size.x, 112);
171
172
int32 x = 116 << 16;
173
int32 centerX = ScreenInfo->center.x;
174
int32 sin = RSDK.Sin256(32);
175
int32 cos = RSDK.Cos256(32);
176
int32 timer = PBL_Setup->scanlineTimer >> 1;
177
178
int32 clr = 0;
179
for (int32 i = 160; i > 40; --i) {
180
x += 0xE000;
181
int32 id = x / (8 * i);
182
183
scanlines->deform.x = -(cos * id) >> 7;
184
scanlines->deform.y = sin * id >> 7;
185
scanlines->position.x = timer + sin * id - centerX * scanlines->deform.x;
186
scanlines->position.y = timer + cos * id - centerX * (sin * id >> 7);
187
188
RSDK.SetActivePalette(CLAMP((abs(id) >> 11) - 16, 0, 7), clr, clr + 1);
189
190
scanlines++;
191
++clr;
192
}
193
}
194
195
void PBL_Setup_DrawHook_PrepareDrawingFX(void)
196
{
197
RSDK.SetClipBounds(0, 0, 0, ScreenInfo->size.x, ScreenInfo->size.y);
198
RSDK.SetActivePalette(0, 0, ScreenInfo->size.y);
199
}
200
201
void PBL_Setup_ExitPinball(void)
202
{
203
EntityPBL_Setup *setup = RSDK_GET_ENTITY(SLOT_BSS_SETUP, PBL_Setup);
204
setup->visible = true;
205
setup->state = PBL_Setup_SaveAndChangeScene;
206
setup->color = 0x000000;
207
208
Music_FadeOut(0.025);
209
210
PauseMenu->disableEvents = true;
211
int32 oldScore = globals->restartScore;
212
globals->restartScore += PBL_Setup->score;
213
if (globals->restartScore > 9999999 || globals->restartScore < oldScore)
214
globals->restartScore = 9999999;
215
216
while (globals->restartScore1UP < globals->restartScore) globals->restartScore1UP += 50000;
217
}
218
219
void PBL_Setup_GiveScore(int32 score)
220
{
221
PBL_Setup->score += score;
222
if (PBL_Setup->score > 9999999)
223
PBL_Setup->score = 9999999;
224
225
if (PBL_Setup->score > PBL_Setup->score1UP) {
226
RSDK.PlaySfx(PBL_Setup->sfxContinue, false, 255);
227
228
SaveRAM *saveRAM = SaveGame_GetSaveRAM();
229
if (saveRAM->continues < 20)
230
saveRAM->continues++;
231
232
while (PBL_Setup->score1UP <= PBL_Setup->score) PBL_Setup->score1UP += 10000;
233
234
foreach_active(PBL_HUD, hud) { PBL_HUD_DisplayMessage(hud, "!CONTINUE!", PBL_HUD_MSG_SCROLL_LEFT); }
235
}
236
}
237
238
void PBL_Setup_GiveLife(void)
239
{
240
SaveRAM *saveRAM = SaveGame_GetSaveRAM();
241
242
if (globals->gameMode != MODE_TIMEATTACK && globals->gameMode != MODE_ENCORE) {
243
if (saveRAM->lives < 99)
244
saveRAM->lives++;
245
246
Music_PlayJingle(TRACK_1UP);
247
}
248
}
249
250
void PBL_Setup_State_FadeIn(void)
251
{
252
RSDK_THIS(PBL_Setup);
253
254
if (self->timer <= 0) {
255
self->timer = 0;
256
self->visible = false;
257
self->state = PBL_Setup_State_ManageStageExit;
258
259
SceneInfo->timeEnabled = true;
260
}
261
else {
262
self->timer -= 16;
263
}
264
}
265
266
void PBL_Setup_State_ManageStageExit(void)
267
{
268
EntityPBL_Camera *camera = RSDK_GET_ENTITY(SLOT_PBL_CAMERA, PBL_Camera);
269
270
foreach_active(PBL_Player, player)
271
{
272
if (player->position.y > camera->curCamBoundaryB + 0x400000) {
273
PBL_Setup_ExitPinball();
274
player->state = StateMachine_None;
275
}
276
}
277
}
278
279
void PBL_Setup_SaveAndChangeScene(void)
280
{
281
RSDK_THIS(PBL_Setup);
282
283
if (self->timer >= 1024) {
284
SaveRAM *saveRAM = SaveGame_GetSaveRAM();
285
if (saveRAM) {
286
saveRAM->characterFlags = globals->characterFlags;
287
saveRAM->stock = globals->stock;
288
saveRAM->playerID = globals->playerID;
289
290
if (globals->gameMode == MODE_ENCORE)
291
RSDK.SetScene("Encore Mode", "");
292
else
293
RSDK.SetScene("Mania Mode", "");
294
295
SceneInfo->listPos = saveRAM->storedStageID;
296
}
297
else {
298
RSDK.SetScene("Presentation", "Title Screen");
299
}
300
301
RSDK.LoadScene();
302
}
303
else {
304
self->timer += 16;
305
}
306
}
307
308
#if GAME_INCLUDE_EDITOR
309
void PBL_Setup_EditorDraw(void) {}
310
311
void PBL_Setup_EditorLoad(void) {}
312
#endif
313
314
void PBL_Setup_Serialize(void) {}
315
#endif
316
317