Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Continue/ContinueSetup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: ContinueSetup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectContinueSetup *ContinueSetup;
11
12
void ContinueSetup_Update(void)
13
{
14
RSDK_THIS(ContinueSetup);
15
16
StateMachine_Run(self->state);
17
18
self->angle = (self->angle - 2) & 0x3FF;
19
}
20
21
void ContinueSetup_LateUpdate(void) {}
22
23
void ContinueSetup_StaticUpdate(void) {}
24
25
void ContinueSetup_Draw(void)
26
{
27
RSDK_THIS(ContinueSetup);
28
29
RSDK.Prepare3DScene(ContinueSetup->sceneIndex);
30
31
RSDK.MatrixTranslateXYZ(&self->matTranslate, 0, -0xF0000, 0x500000, true);
32
RSDK.MatrixRotateX(&self->matRotateX, self->rotationX);
33
RSDK.MatrixRotateZ(&self->matRotateY, self->angle);
34
35
// Number 1 (tens)
36
RSDK.MatrixTranslateXYZ(&self->matTemp, -0x120000, 0, 0, true);
37
RSDK.MatrixMultiply(&self->matFinal, &self->matRotateY, &self->matRotateX);
38
RSDK.MatrixMultiply(&self->matFinal, &self->matTemp, &self->matFinal);
39
RSDK.MatrixMultiply(&self->matFinal, &self->matFinal, &self->matTranslate);
40
RSDK.AddModelTo3DScene(ContinueSetup->countIndex[self->countTimer / 10 % 10], ContinueSetup->sceneIndex, S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN,
41
&self->matFinal, &self->matFinal, self->numberColor);
42
43
// Number 2 (single digits)
44
RSDK.MatrixTranslateXYZ(&self->matTemp, 0x120000, 0, 0, true);
45
RSDK.MatrixMultiply(&self->matFinal, &self->matRotateY, &self->matRotateX);
46
RSDK.MatrixMultiply(&self->matFinal, &self->matTemp, &self->matFinal);
47
RSDK.MatrixMultiply(&self->matFinal, &self->matFinal, &self->matTranslate);
48
RSDK.AddModelTo3DScene(ContinueSetup->countIndex[self->countTimer % 10], ContinueSetup->sceneIndex, S3D_SOLIDCOLOR_SHADED_BLENDED_SCREEN,
49
&self->matFinal, &self->matFinal, self->numberColor);
50
51
RSDK.Draw3DScene(ContinueSetup->sceneIndex);
52
53
Vector2 drawPos;
54
drawPos.y = 0x600000;
55
drawPos.x = ((ScreenInfo->center.x + 4) << 16) - (globals->continues << 19);
56
if (self->showContinues && globals->continues > 0) {
57
RSDK.DrawSprite(&ContinueSetup->animator, &drawPos, true);
58
}
59
60
drawPos.x += 0x140000;
61
for (int32 i = 0; i < globals->continues; ++i) {
62
RSDK.DrawSprite(&ContinueSetup->animator, &drawPos, true);
63
drawPos.x += 0x140000;
64
}
65
}
66
67
void ContinueSetup_Create(void *data)
68
{
69
RSDK_THIS(ContinueSetup);
70
71
if (!SceneInfo->inEditor) {
72
self->active = ACTIVE_NORMAL;
73
self->visible = true;
74
self->drawGroup = 1;
75
self->rotationX = 240;
76
self->angle = 256;
77
self->countTimer = 10;
78
self->numberColor = 0xFF00FF;
79
self->showContinues = true;
80
self->state = ContinueSetup_State_FadeIn;
81
self->updateRange.x = 0x4000000;
82
83
self->updateRange.y = 0x4000000;
84
switch (GET_CHARACTER_ID(1)) {
85
default:
86
case ID_SONIC: RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_ICON, &ContinueSetup->animator, true, 0); break;
87
case ID_TAILS: RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_ICON, &ContinueSetup->animator, true, 1); break;
88
case ID_KNUCKLES: RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_ICON, &ContinueSetup->animator, true, 2); break;
89
#if MANIA_USE_PLUS
90
case ID_MIGHTY: RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_ICON, &ContinueSetup->animator, true, 3); break;
91
case ID_RAY: RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_ICON, &ContinueSetup->animator, true, 4); break;
92
#endif
93
}
94
RSDK.SetActivePalette(1, 0, ScreenInfo->size.y);
95
}
96
}
97
98
void ContinueSetup_StageLoad(void)
99
{
100
const char *paths[10] = {
101
"Continue/Count0.bin", "Continue/Count1.bin", "Continue/Count2.bin", "Continue/Count3.bin", "Continue/Count4.bin",
102
"Continue/Count5.bin", "Continue/Count6.bin", "Continue/Count7.bin", "Continue/Count8.bin", "Continue/Count9.bin",
103
};
104
105
for (int32 i = 0; i < 10; ++i) ContinueSetup->countIndex[i] = RSDK.LoadMesh(paths[i], SCOPE_STAGE);
106
107
ContinueSetup->sceneIndex = RSDK.Create3DScene("View:Continue", 4096, SCOPE_STAGE);
108
109
RSDK.SetDiffuseColor(ContinueSetup->sceneIndex, 0xA0, 0xA0, 0xA0);
110
RSDK.SetDiffuseIntensity(ContinueSetup->sceneIndex, 8, 8, 8);
111
RSDK.SetSpecularIntensity(ContinueSetup->sceneIndex, 15, 15, 15);
112
113
ContinueSetup->sfxAccept = RSDK.GetSfx("Global/MenuAccept.wav");
114
}
115
116
void ContinueSetup_State_FadeIn(void)
117
{
118
RSDK_THIS(ContinueSetup);
119
120
if (++self->timer >= 8 && !RSDK.GetEntityCount(FXFade->classID, true)) {
121
self->timer = 0;
122
self->state = ContinueSetup_State_HandleCountdown;
123
}
124
}
125
126
void ContinueSetup_State_HandleCountdown(void)
127
{
128
RSDK_THIS(ContinueSetup);
129
130
if (++self->secondTimer == 60) {
131
self->secondTimer = 0;
132
133
if (self->countTimer > 0) {
134
self->countTimer--;
135
136
if (self->alpha < 0xFF)
137
self->alpha += 0x18;
138
139
self->numberColor = RSDK.GetPaletteEntry(2, self->alpha);
140
}
141
}
142
143
if (ControllerInfo->keyA.press || ControllerInfo->keyStart.press || TouchInfo->count) {
144
foreach_active(ContinuePlayer, player)
145
{
146
if (!player->isPlayer2)
147
RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, player->animator.animationID + 1, &player->animator, true, 0);
148
149
player->state = ContinuePlayer_State_Idle;
150
}
151
152
self->state = ContinueSetup_State_ContinueGame;
153
RSDK.PlaySfx(ContinueSetup->sfxAccept, false, 255);
154
}
155
156
if (!self->countTimer && ++self->timer == 60) {
157
self->timer = 0;
158
self->state = ContinueSetup_State_ReturnToMenu;
159
160
EntityFXFade *fade = CREATE_ENTITY(FXFade, NULL, self->position.x, self->position.y);
161
fade->speedIn = 12;
162
fade->wait = 240;
163
}
164
}
165
166
void ContinueSetup_State_ContinueGame(void)
167
{
168
RSDK_THIS(ContinueSetup);
169
170
if (++self->timer == 90) {
171
Music_FadeOut(0.0125);
172
}
173
174
if (self->timer == 180) {
175
EntityFXFade *fade = CREATE_ENTITY(FXFade, NULL, self->position.x, self->position.y);
176
fade->speedIn = 12;
177
fade->wait = 240;
178
}
179
180
if (self->timer == 260) {
181
#if MANIA_USE_PLUS
182
if (globals->gameMode == MODE_ENCORE)
183
RSDK.SetScene("Encore Mode", "");
184
else
185
#endif
186
RSDK.SetScene("Mania Mode", "");
187
188
SaveGame_GetSaveRAM()->continues = globals->continues;
189
SceneInfo->listPos = SaveGame_GetSaveRAM()->storedStageID;
190
RSDK.LoadScene();
191
}
192
193
if (self->timer < 58) {
194
self->showContinues = ((self->timer >> 1) & 1);
195
}
196
197
if (self->timer == 60) {
198
self->showContinues = true;
199
200
if (globals->continues > 0)
201
globals->continues--;
202
}
203
}
204
205
void ContinueSetup_State_ReturnToMenu(void)
206
{
207
RSDK_THIS(ContinueSetup);
208
209
if (++self->timer == 80) {
210
RSDK.SetScene("Presentation", "Menu");
211
RSDK.LoadScene();
212
}
213
}
214
215
#if GAME_INCLUDE_EDITOR
216
void ContinueSetup_EditorDraw(void) {}
217
218
void ContinueSetup_EditorLoad(void) {}
219
#endif
220
221
void ContinueSetup_Serialize(void) {}
222
223