Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Pinball/PBL_HUD.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PBL_HUD 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_HUD *PBL_HUD;
12
13
void PBL_HUD_Update(void)
14
{
15
RSDK_THIS(PBL_HUD);
16
17
StateMachine_Run(self->state);
18
}
19
20
void PBL_HUD_LateUpdate(void) {}
21
22
void PBL_HUD_StaticUpdate(void) {}
23
24
void PBL_HUD_Draw(void)
25
{
26
RSDK_THIS(PBL_HUD);
27
28
self->position.x = ScreenInfo->center.x << 16;
29
30
if (self->stateDraw) {
31
StateMachine_Run(self->stateDraw);
32
}
33
else {
34
RSDK.DrawSprite(&self->displayAnimator, NULL, true);
35
RSDK.DrawSprite(&self->baseAnimator, NULL, true);
36
}
37
}
38
39
void PBL_HUD_Create(void *data)
40
{
41
RSDK_THIS(PBL_HUD);
42
43
if (!SceneInfo->inEditor) {
44
self->visible = true;
45
self->drawGroup = 12;
46
self->active = ACTIVE_NORMAL;
47
self->position.y = 0;
48
self->scale.x = 0x200;
49
self->scale.y = 0x200;
50
51
RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->displayAnimator, true, 0);
52
RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->baseAnimator, true, 1);
53
RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 1, &self->textAnimator, true, 0);
54
55
RSDK.InitString(&self->text, "", 64);
56
57
if (globals->gameMode == MODE_ENCORE)
58
PBL_HUD_DisplayMessage(self, "BONUS STAGE! RESCUE YOUR BUDDIES!", PBL_HUD_MSG_SCROLL_LEFT);
59
else
60
PBL_HUD_DisplayMessage(self, "BONUS STAGE!", PBL_HUD_MSG_SCROLL_LEFT);
61
}
62
}
63
64
void PBL_HUD_StageLoad(void) { PBL_HUD->aniFrames = RSDK.LoadSpriteAnimation("Pinball/Backglass.bin", SCOPE_STAGE); }
65
66
void PBL_HUD_DisplayMessage(EntityPBL_HUD *entity, const char *message, int32 type)
67
{
68
if (entity->state != PBL_HUD_StateMessage_FlashThenCrane && entity->state != PBL_HUD_State_RevealCrane
69
&& entity->state != PBL_HUD_State_HideCrane) {
70
RSDK.SetString(&entity->text, message);
71
RSDK.SetSpriteString(PBL_HUD->aniFrames, 1, &entity->text);
72
73
entity->stateDraw = PBL_HUD_Draw_Message;
74
75
switch (type) {
76
case PBL_HUD_MSG_SCROLL_LEFT_SLOW:
77
entity->offset.x = 0x410000;
78
entity->state = PBL_HUD_StateMessage_ScrollLeftSlow;
79
entity->timer = 12 * entity->text.length + 128;
80
break;
81
82
case PBL_HUD_MSG_SCROLL_LEFT:
83
entity->offset.x = 0x410000;
84
entity->state = PBL_HUD_StateMessage_ScrollLeftFast;
85
entity->timer = 6 * entity->text.length + 64;
86
break;
87
88
case PBL_HUD_MSG_SCROLL_RIGHT_SLOW:
89
entity->state = PBL_HUD_StateMessage_ScrollRightSlow;
90
entity->timer = 12 * entity->text.length + 128;
91
entity->offset.x = -0x410000 - 0xC0000 * entity->text.length;
92
break;
93
94
case PBL_HUD_MSG_SCROLL_RIGHT:
95
entity->state = PBL_HUD_StateMessage_ScrollRightFast;
96
entity->timer = 6 * entity->text.length + 64;
97
entity->offset.x = -0x410000 - 0xC0000 * entity->text.length;
98
break;
99
100
case PBL_HUD_MSG_SHOW_RISE:
101
entity->offset.y = 0x120000;
102
entity->timer = -9;
103
entity->velocity.y = -0x20000;
104
entity->state = PBL_HUD_StateMessage_ShowMove;
105
entity->offset.x = -0x60000 * entity->text.length;
106
break;
107
108
case PBL_HUD_MSG_SHOW_FALL:
109
entity->offset.y = -0x120000;
110
entity->timer = -9;
111
entity->velocity.y = 0x20000;
112
entity->state = PBL_HUD_StateMessage_ShowMove;
113
entity->offset.x = -0x60000 * entity->text.length;
114
break;
115
116
case PBL_HUD_MSG_FLASH:
117
entity->state = PBL_HUD_StateMessage_Flash;
118
entity->timer = 60;
119
entity->offset.x = -0x60000 * entity->text.length;
120
break;
121
122
case PBL_HUD_MSG_FLASH_CRANE:
123
entity->state = PBL_HUD_StateMessage_FlashThenCrane;
124
entity->timer = 60;
125
entity->offset.x = -0x60000 * entity->text.length;
126
break;
127
128
default: break;
129
}
130
}
131
}
132
133
void PBL_HUD_StateMessage_ScrollLeftSlow(void)
134
{
135
RSDK_THIS(PBL_HUD);
136
137
if (self->timer <= 0) {
138
self->state = StateMachine_None;
139
self->stateDraw = PBL_HUD_Draw_Score;
140
}
141
else {
142
self->timer--;
143
if (!(self->timer & 1))
144
self->offset.x -= 0x20000;
145
}
146
}
147
148
void PBL_HUD_StateMessage_ScrollLeftFast(void)
149
{
150
RSDK_THIS(PBL_HUD);
151
152
if (self->timer <= 0) {
153
self->state = StateMachine_None;
154
self->stateDraw = PBL_HUD_Draw_Score;
155
}
156
else {
157
self->offset.x -= 0x20000;
158
self->timer--;
159
}
160
}
161
void PBL_HUD_StateMessage_ScrollRightSlow(void)
162
{
163
RSDK_THIS(PBL_HUD);
164
165
if (self->timer <= 0) {
166
self->state = StateMachine_None;
167
self->stateDraw = PBL_HUD_Draw_Score;
168
}
169
else {
170
self->timer--;
171
172
if (!(self->timer & 1))
173
self->offset.x += 0x20000;
174
}
175
}
176
177
void PBL_HUD_StateMessage_ScrollRightFast(void)
178
{
179
RSDK_THIS(PBL_HUD);
180
181
if (self->timer <= 0) {
182
self->state = StateMachine_None;
183
self->stateDraw = PBL_HUD_Draw_Score;
184
}
185
else {
186
self->offset.x += 0x20000;
187
self->timer--;
188
}
189
}
190
191
void PBL_HUD_StateMessage_ShowMove(void)
192
{
193
RSDK_THIS(PBL_HUD);
194
195
if (self->timer < 0 || self->timer > 60)
196
self->offset.y += self->velocity.y;
197
198
if (++self->timer > 90) {
199
self->timer = 0;
200
self->offset.y = 0;
201
self->state = StateMachine_None;
202
self->stateDraw = PBL_HUD_Draw_Score;
203
}
204
}
205
206
void PBL_HUD_StateMessage_Flash(void)
207
{
208
RSDK_THIS(PBL_HUD);
209
210
if (self->timer <= 0) {
211
self->state = StateMachine_None;
212
self->stateDraw = PBL_HUD_Draw_Score;
213
}
214
else {
215
self->timer--;
216
217
if ((self->timer & 7) < 4)
218
self->stateDraw = StateMachine_None;
219
else
220
self->stateDraw = PBL_HUD_Draw_Message;
221
}
222
}
223
224
void PBL_HUD_StateMessage_FlashThenCrane(void)
225
{
226
RSDK_THIS(PBL_HUD);
227
228
if (self->timer <= 0) {
229
self->state = PBL_HUD_State_RevealCrane;
230
self->stateDraw = PBL_HUD_Draw_Basic;
231
self->drawFX = FX_SCALE;
232
233
foreach_active(PBL_Crane, crane) { crane->state = PBL_Crane_State_CreatePrizes; }
234
}
235
else {
236
self->timer--;
237
238
if ((self->timer & 7) < 4)
239
self->stateDraw = StateMachine_None;
240
else
241
self->stateDraw = PBL_HUD_Draw_Message;
242
}
243
}
244
245
void PBL_HUD_Draw_Basic(void)
246
{
247
RSDK_THIS(PBL_HUD);
248
249
RSDK.DrawSprite(&self->displayAnimator, NULL, true);
250
}
251
252
void PBL_HUD_Draw_Message(void)
253
{
254
RSDK_THIS(PBL_HUD);
255
256
RSDK.DrawSprite(&self->displayAnimator, NULL, true);
257
RSDK.DrawSprite(&self->baseAnimator, NULL, true);
258
259
Vector2 position;
260
position.x = self->position.x + self->offset.x;
261
position.y = self->position.y + self->offset.y;
262
263
RSDK.SetClipBounds(SceneInfo->currentScreenID, ScreenInfo->center.x - 55, 40, ScreenInfo->center.x + 56, 58);
264
265
RSDK.DrawText(&self->textAnimator, &position, &self->text, 0, 0, 0, 1, 0, 0, true);
266
267
RSDK.SetClipBounds(SceneInfo->currentScreenID, 0, 0, ScreenInfo->size.x, ScreenInfo->size.y);
268
}
269
270
void PBL_HUD_Draw_Score(void)
271
{
272
RSDK_THIS(PBL_HUD);
273
274
int32 score = PBL_Setup->score;
275
int32 count = 0;
276
int32 mult = 1;
277
278
while (score > 0) {
279
++count;
280
score /= 10;
281
}
282
283
Vector2 drawPos;
284
drawPos.x = self->position.x + 0x320000;
285
drawPos.y = self->position.y;
286
RSDK.DrawSprite(&self->displayAnimator, NULL, true);
287
RSDK.DrawSprite(&self->baseAnimator, NULL, true);
288
289
int32 div = 10;
290
while (count > 0) {
291
self->textAnimator.frameID = PBL_Setup->score / mult % div;
292
RSDK.DrawSprite(&self->textAnimator, &drawPos, true);
293
294
drawPos.x -= 0xC0000;
295
mult *= 10;
296
--count;
297
}
298
299
self->textAnimator.frameID = 0;
300
}
301
302
void PBL_HUD_State_RevealCrane(void)
303
{
304
RSDK_THIS(PBL_HUD);
305
306
self->scale.x += 4;
307
self->position.y -= 0x40000;
308
309
if (self->position.y < -0x480000) {
310
self->state = StateMachine_None;
311
self->visible = false;
312
}
313
}
314
315
void PBL_HUD_State_HideCrane(void)
316
{
317
RSDK_THIS(PBL_HUD);
318
319
self->scale.x -= 4;
320
self->position.y += 0x40000;
321
322
if (self->position.y >= 0) {
323
self->position.y = 0;
324
self->scale.x = 0x200;
325
self->scale.y = 0x200;
326
self->drawFX = FX_NONE;
327
self->state = StateMachine_None;
328
self->stateDraw = PBL_HUD_Draw_Score;
329
330
foreach_all(PBL_Player, player)
331
{
332
player->active = ACTIVE_NORMAL;
333
player->velocity.y = 0;
334
}
335
}
336
}
337
338
#if GAME_INCLUDE_EDITOR
339
void PBL_HUD_EditorDraw(void)
340
{
341
RSDK_THIS(PBL_HUD);
342
343
RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->displayAnimator, true, 0);
344
RSDK.SetSpriteAnimation(PBL_HUD->aniFrames, 0, &self->baseAnimator, true, 1);
345
346
RSDK.DrawSprite(&self->displayAnimator, NULL, false);
347
}
348
349
void PBL_HUD_EditorLoad(void) { PBL_HUD->aniFrames = RSDK.LoadSpriteAnimation("Pinball/Backglass.bin", SCOPE_STAGE); }
350
#endif
351
352
void PBL_HUD_Serialize(void) {}
353
#endif
354
355