Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Credits/TryAgain.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: TryAgain Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectTryAgain *TryAgain;
11
12
void TryAgain_Update(void)
13
{
14
RSDK_THIS(TryAgain);
15
16
StateMachine_Run(self->state);
17
}
18
19
void TryAgain_LateUpdate(void) {}
20
21
void TryAgain_StaticUpdate(void) {}
22
23
void TryAgain_Draw(void)
24
{
25
RSDK_THIS(TryAgain);
26
27
RSDK.SetActivePalette(0, 0, ScreenInfo->size.y);
28
RSDK.SetClipBounds(0, 0, 0, ScreenInfo->size.x, (self->position.y >> 16));
29
30
RSDK.DrawSprite(&self->eggmanAnimator, &self->eggmanPos, false);
31
RSDK.DrawSprite(&self->rubyAnimator, &self->rubyPos, false);
32
33
RSDK.SetClipBounds(0, 0, 0, ScreenInfo->size.x, ScreenInfo->size.y);
34
RSDK.DrawSprite(&self->debrisAnimator, NULL, false);
35
36
RSDK.SetActivePalette(1, 0, ScreenInfo->size.y);
37
}
38
39
void TryAgain_Create(void *data)
40
{
41
RSDK_THIS(TryAgain);
42
43
if (!SceneInfo->inEditor) {
44
self->eggmanPos.x = self->position.x;
45
self->eggmanPos.y = self->position.y + 0x100000;
46
self->rubyPos.x = self->eggmanPos.x - 0x340000;
47
self->rubyPos.y = self->eggmanPos.y;
48
49
self->visible = true;
50
self->drawGroup = 1;
51
self->active = ACTIVE_BOUNDS;
52
self->updateRange.x = 0x800000;
53
self->updateRange.y = 0x800000;
54
55
self->state = TryAgain_State_Init;
56
RSDK.SetSpriteAnimation(TryAgain->aniFrames, 0, &self->debrisAnimator, true, 0);
57
RSDK.SetSpriteAnimation(TryAgain->aniFrames, 2, &self->eggmanAnimator, true, 0);
58
RSDK.SetSpriteAnimation(TryAgain->aniFrames, 4, &self->rubyAnimator, true, 0);
59
}
60
}
61
62
void TryAgain_StageLoad(void)
63
{
64
TryAgain->aniFrames = RSDK.LoadSpriteAnimation("Credits/TryAgain.bin", SCOPE_STAGE);
65
66
RSDK.CopyPalette(0, 0, 1, 0, 128);
67
}
68
69
void TryAgain_State_Init(void)
70
{
71
RSDK_THIS(TryAgain);
72
73
if (++self->timer == 60) {
74
self->timer = 0;
75
self->eggmanVelocityY = -0x5C000;
76
77
#if MANIA_USE_PLUS
78
Music_PlayTrack(TRACK_STAGE);
79
#endif
80
self->state = TryAgain_State_EnterEggman;
81
}
82
}
83
84
void TryAgain_State_EnterEggman(void)
85
{
86
RSDK_THIS(TryAgain);
87
88
self->eggmanVelocityY += 0x3800;
89
int32 targetPos = self->position.y - 0x340000;
90
self->eggmanPos.y += self->eggmanVelocityY;
91
92
if (self->eggmanPos.y <= targetPos || self->eggmanVelocityY <= 0) {
93
self->rubyPos.y = self->eggmanPos.y;
94
}
95
else {
96
self->eggmanVelocityY = 0;
97
self->eggmanPos.y = targetPos;
98
self->rubyPos.y = targetPos;
99
self->state = TryAgain_State_EggmanLaugh;
100
}
101
}
102
103
void TryAgain_State_EggmanLaugh(void)
104
{
105
RSDK_THIS(TryAgain);
106
107
if (self->timer > (MANIA_USE_PLUS ? 15 : 30))
108
RSDK.ProcessAnimation(&self->eggmanAnimator);
109
110
if (++self->timer == 120) {
111
self->timer = 0;
112
RSDK.SetSpriteAnimation(TryAgain->aniFrames, 3, &self->eggmanAnimator, true, 2);
113
self->state = TryAgain_State_Stinger;
114
}
115
}
116
117
void TryAgain_State_Stinger(void)
118
{
119
RSDK_THIS(TryAgain);
120
121
RSDK.ProcessAnimation(&self->eggmanAnimator);
122
123
if (self->eggmanAnimator.frameID == 2) {
124
if (self->eggmanAnimator.timer == 1) {
125
self->rubyVelocity.x = 0x22000;
126
self->rubyVelocity.y = -0x58000;
127
}
128
}
129
else if (self->eggmanAnimator.frameID == 7 && self->eggmanAnimator.timer == 1) {
130
self->rubyVelocity.x = -0x22000;
131
self->rubyVelocity.y = -0x58000;
132
}
133
134
self->rubyVelocity.y += 0x3800;
135
self->rubyPos.x += self->rubyVelocity.x;
136
self->rubyPos.y += self->rubyVelocity.y;
137
138
if (self->rubyPos.y <= self->eggmanPos.y + 0x80000) {
139
if (self->rubyPos.y < self->position.y)
140
RSDK.ProcessAnimation(&self->rubyAnimator);
141
}
142
else {
143
self->rubyPos.y = self->eggmanPos.y + 0x80000;
144
self->rubyVelocity.x = 0;
145
self->rubyVelocity.y = 0;
146
RSDK.SetSpriteAnimation(TryAgain->aniFrames, 4, &self->rubyAnimator, true, 0);
147
}
148
149
++self->timer;
150
if (ControllerInfo->keyA.press || ControllerInfo->keyStart.press)
151
self->timer = 600;
152
153
if (self->timer == 600) {
154
#if MANIA_USE_PLUS
155
PhantomRuby_PlaySfx(RUBYSFX_ATTACK4);
156
EntityFXFade *fxFade = CREATE_ENTITY(FXFade, INT_TO_VOID(0xFFFFFF), self->position.x, self->position.y);
157
fxFade->speedIn = 24;
158
fxFade->speedOut = 24;
159
fxFade->fadeOutBlack = true;
160
#else
161
EntityFXFade *fxFade = CREATE_ENTITY(FXFade, INT_TO_VOID(0x000000), self->position.x, self->position.y);
162
fxFade->speedIn = 12;
163
fxFade->wait = 240;
164
#endif
165
}
166
167
if (self->timer >= (MANIA_USE_PLUS ? 740 : 680)) {
168
#if MANIA_USE_PLUS
169
if (API.CheckDLC(DLC_PLUS))
170
RSDK.SetScene("Presentation", "Game Summary");
171
else
172
#endif
173
RSDK.SetScene("Presentation", "Menu");
174
175
RSDK.LoadScene();
176
}
177
}
178
179
#if GAME_INCLUDE_EDITOR
180
void TryAgain_EditorDraw(void) {}
181
182
void TryAgain_EditorLoad(void) {}
183
#endif
184
185
void TryAgain_Serialize(void) {}
186
187