Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Continue/ContinuePlayer.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: ContinuePlayer Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectContinuePlayer *ContinuePlayer;
11
12
void ContinuePlayer_Update(void)
13
{
14
RSDK_THIS(ContinuePlayer);
15
16
RSDK.ProcessAnimation(&self->animator);
17
18
StateMachine_Run(self->state);
19
}
20
21
void ContinuePlayer_LateUpdate(void) {}
22
23
void ContinuePlayer_StaticUpdate(void) {}
24
25
void ContinuePlayer_Draw(void)
26
{
27
RSDK_THIS(ContinuePlayer);
28
29
RSDK.DrawSprite(&self->animator, NULL, false);
30
}
31
32
void ContinuePlayer_Create(void *data)
33
{
34
RSDK_THIS(ContinuePlayer);
35
36
if (!SceneInfo->inEditor) {
37
self->visible = true;
38
self->drawGroup = 1;
39
self->active = ACTIVE_NORMAL;
40
41
if (!self->isPlayer2) {
42
switch (GET_CHARACTER_ID(1)) {
43
default:
44
case ID_SONIC:
45
RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_IDLE_SONIC, &self->animator, true, 0);
46
47
if (globals->playerID & ID_TAILS_ASSIST)
48
self->position.x -= 0x100000;
49
break;
50
51
case ID_TAILS:
52
RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_IDLE_TAILS, &self->animator, true, 0);
53
self->position.y += 0x40000;
54
break;
55
56
case ID_KNUCKLES: RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_IDLE_KNUX, &self->animator, true, 0); break;
57
58
#if MANIA_USE_PLUS
59
case ID_MIGHTY: RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_IDLE_MIGHTY, &self->animator, true, 0); break;
60
61
case ID_RAY:
62
RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_IDLE_RAY, &self->animator, true, 0);
63
self->position.y += 0x40000;
64
break;
65
#endif
66
}
67
68
self->timer = 60;
69
self->aniFrames = ContinuePlayer->playerAniFrames;
70
}
71
else {
72
RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, CONTPLR_ANI_IDLE_AI, &self->animator, true, 0);
73
74
if (!(globals->playerID & ID_TAILS_ASSIST))
75
self->active = ACTIVE_NEVER;
76
77
self->timer = 76;
78
self->aniFrames = ContinuePlayer->tailAniFrames;
79
}
80
}
81
}
82
83
void ContinuePlayer_StageLoad(void)
84
{
85
ContinuePlayer->aniFrames = RSDK.LoadSpriteAnimation("Players/Continue.bin", SCOPE_STAGE);
86
87
if (globals->playerID == ID_NONE)
88
globals->playerID = ID_DEFAULT_PLAYER;
89
90
switch (GET_CHARACTER_ID(1)) {
91
default:
92
case ID_SONIC: ContinuePlayer->playerAniFrames = RSDK.LoadSpriteAnimation("Players/Sonic.bin", SCOPE_STAGE); break;
93
case ID_TAILS: ContinuePlayer->playerAniFrames = RSDK.LoadSpriteAnimation("Players/Tails.bin", SCOPE_STAGE); break;
94
case ID_KNUCKLES: ContinuePlayer->playerAniFrames = RSDK.LoadSpriteAnimation("Players/Knux.bin", SCOPE_STAGE); break;
95
#if MANIA_USE_PLUS
96
case ID_MIGHTY: ContinuePlayer->playerAniFrames = RSDK.LoadSpriteAnimation("Players/Mighty.bin", SCOPE_STAGE); break;
97
case ID_RAY: ContinuePlayer->playerAniFrames = RSDK.LoadSpriteAnimation("Players/Ray.bin", SCOPE_STAGE); break;
98
#endif
99
}
100
101
ContinuePlayer->tailAniFrames = RSDK.LoadSpriteAnimation("Players/Tails.bin", SCOPE_STAGE);
102
103
ContinuePlayer->sfxRoll = RSDK.GetSfx("Global/Roll.wav");
104
ContinuePlayer->sfxCharge = RSDK.GetSfx("Global/Charge.wav");
105
ContinuePlayer->sfxRelease = RSDK.GetSfx("Global/Release.wav");
106
}
107
108
void ContinuePlayer_HandleDashAnim(void)
109
{
110
RSDK_THIS(ContinuePlayer);
111
112
if (self->groundVel >= 0x40000) {
113
if (self->groundVel >= 0x60000) {
114
if (self->groundVel >= 0xA0000) {
115
RSDK.SetSpriteAnimation(self->aniFrames, ANI_DASH, &self->animator, false, 0);
116
self->animator.speed = 256;
117
}
118
else {
119
RSDK.SetSpriteAnimation(self->aniFrames, ANI_RUN, &self->animator, false, 1);
120
121
self->animator.speed = (self->groundVel >> 12) + 96;
122
if (self->animator.speed > 0x100)
123
self->animator.speed = 0x100;
124
}
125
}
126
else {
127
RSDK.SetSpriteAnimation(self->aniFrames, ANI_JOG, &self->animator, false, 0);
128
int32 vel = (self->groundVel >> 16);
129
self->animator.speed = 4 * ((vel << 1) + vel) + 64;
130
}
131
}
132
else {
133
RSDK.SetSpriteAnimation(self->aniFrames, ANI_WALK, &self->animator, false, 0);
134
self->animator.speed = (self->groundVel >> 12) + 48;
135
}
136
}
137
138
void ContinuePlayer_State_Idle(void)
139
{
140
RSDK_THIS(ContinuePlayer);
141
142
if (self->timer <= 0) {
143
ContinuePlayer_HandleDashAnim();
144
self->state = ContinuePlayer_State_ChargeDash;
145
146
RSDK.PlaySfx(ContinuePlayer->sfxRoll, false, 255);
147
}
148
else {
149
self->timer--;
150
}
151
}
152
153
void ContinuePlayer_State_ChargeDash(void)
154
{
155
RSDK_THIS(ContinuePlayer);
156
157
if (self->groundVel >= 0xC0000) {
158
RSDK.PlaySfx(ContinuePlayer->sfxRelease, false, 255);
159
160
self->state = ContinuePlayer_State_DashRelease;
161
}
162
else {
163
self->groundVel += 0x4000;
164
}
165
166
ContinuePlayer_HandleDashAnim();
167
}
168
169
void ContinuePlayer_State_DashRelease(void)
170
{
171
RSDK_THIS(ContinuePlayer);
172
173
self->position.x += self->groundVel;
174
}
175
176
#if GAME_INCLUDE_EDITOR
177
void ContinuePlayer_EditorDraw(void)
178
{
179
RSDK_THIS(ContinuePlayer);
180
181
RSDK.SetSpriteAnimation(ContinuePlayer->aniFrames, self->isPlayer2 ? CONTPLR_ANI_IDLE_SONIC : CONTPLR_ANI_IDLE_AI, &self->animator, true, 0);
182
183
ContinuePlayer_Draw();
184
}
185
186
void ContinuePlayer_EditorLoad(void) { ContinuePlayer->aniFrames = RSDK.LoadSpriteAnimation("Players/Continue.bin", SCOPE_STAGE); }
187
#endif
188
189
void ContinuePlayer_Serialize(void) { RSDK_EDITABLE_VAR(ContinuePlayer, VAR_BOOL, isPlayer2); }
190
191