Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/UFO/UFO_HUD.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: UFO_HUD Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectUFO_HUD *UFO_HUD;
11
12
void UFO_HUD_Update(void)
13
{
14
RSDK_THIS(UFO_HUD);
15
16
#if MANIA_USE_PLUS && GAME_VERSION != VER_107
17
if (ControllerInfo->keyY.press) {
18
// Not original code, should help fix some crashes/glitches that occur due to how this works through
19
Entity *selfStore = SceneInfo->entity;
20
SceneInfo->entity = RSDK_GET_ENTITY_GEN(SLOT_PLAYER1);
21
22
// Cool Debug thingy they left in
23
UFO_HUD_LevelUpMach();
24
25
// Not original code, should help fix some crashes/glitches that occur due to how this works through
26
SceneInfo->entity = selfStore;
27
}
28
#endif
29
30
if (self->scale.x > 0x200) {
31
self->scale.x -= 0x10;
32
self->scale.y -= 0x10;
33
34
if (self->scale.x <= 0x200) {
35
int32 cnt = 32 * UFO_Setup->machPoints / UFO_Setup->machQuotas[UFO_Setup->machLevel];
36
RSDK.CopyPalette(self->machPaletteBank, 96, 0, 96, cnt);
37
RSDK.CopyPalette(1, cnt + 96, 0, cnt + 96, (uint8)(32 - cnt));
38
}
39
else {
40
RSDK.SetLimitedFade(0, 1, 4, self->scale.x - 0x200, 96, 127);
41
}
42
}
43
44
if (self->timer > 0)
45
self->timer--;
46
47
if (UFO_Setup->rings <= 0 || UFO_Setup->rings >= 10)
48
self->showRingCount = true;
49
else
50
self->showRingCount = (UFO_Setup->timer >> 3) & 1;
51
}
52
53
void UFO_HUD_LateUpdate(void) {}
54
55
void UFO_HUD_StaticUpdate(void) {}
56
57
void UFO_HUD_Draw(void)
58
{
59
RSDK_THIS(UFO_HUD);
60
61
Vector2 drawPos;
62
drawPos.y = 0x240000;
63
drawPos.x = ScreenInfo->center.x << 16;
64
if (self->scale.x > 0x200)
65
self->drawFX = FX_SCALE;
66
67
RSDK.DrawSprite(&self->hudAnimator, &drawPos, true);
68
69
for (int32 i = 0; i <= UFO_Setup->machLevel; ++i) {
70
RSDK.DrawSprite(&self->stripeAnimator, &drawPos, true);
71
drawPos.x += 0xA0000;
72
}
73
74
drawPos.x = ScreenInfo->center.x << 16;
75
if (!(self->timer & 4) && self->timer) {
76
self->machAnimator.frameID = 3;
77
RSDK.DrawSprite(&self->machAnimator, &drawPos, true);
78
}
79
else if (!self->timer) {
80
self->machAnimator.frameID = UFO_Setup->machLevel;
81
RSDK.DrawSprite(&self->machAnimator, &drawPos, true);
82
}
83
84
self->drawFX = FX_NONE;
85
if (self->showRingCount) {
86
drawPos.x += 0x200000;
87
drawPos.y = 0x250000;
88
UFO_HUD_DrawNumbers(&drawPos, UFO_Setup->rings);
89
}
90
}
91
92
void UFO_HUD_Create(void *data)
93
{
94
RSDK_THIS(UFO_HUD);
95
96
if (!SceneInfo->inEditor) {
97
self->active = ACTIVE_NORMAL;
98
self->visible = true;
99
self->drawGroup = 12;
100
self->updateRange.x = 0x800000;
101
self->updateRange.y = 0x800000;
102
self->scale.x = 0x200;
103
self->scale.y = 0x200;
104
self->machPaletteBank = 2;
105
106
RSDK.SetSpriteAnimation(UFO_HUD->aniFrames, 0, &self->hudAnimator, true, 0);
107
RSDK.SetSpriteAnimation(UFO_HUD->aniFrames, 1, &self->numbersAnimator, true, 0);
108
RSDK.SetSpriteAnimation(UFO_HUD->aniFrames, 2, &self->machAnimator, true, 0);
109
RSDK.SetSpriteAnimation(UFO_HUD->aniFrames, 3, &self->stripeAnimator, true, 0);
110
}
111
}
112
113
void UFO_HUD_StageLoad(void)
114
{
115
UFO_HUD->aniFrames = RSDK.LoadSpriteAnimation("SpecialUFO/HUD.bin", SCOPE_STAGE);
116
117
RSDK.ResetEntitySlot(SLOT_UFO_HUD, UFO_HUD->classID, NULL);
118
}
119
120
void UFO_HUD_CheckLevelUp(void)
121
{
122
EntityUFO_HUD *hud = RSDK_GET_ENTITY(SLOT_UFO_HUD, UFO_HUD);
123
124
if (UFO_Setup->machPoints >= UFO_Setup->machQuotas[UFO_Setup->machLevel]) {
125
UFO_Setup->machPoints -= UFO_Setup->machQuotas[UFO_Setup->machLevel];
126
127
if (UFO_Setup->machLevel >= 2) {
128
++UFO_Setup->scoreBonus;
129
hud->timer = 60;
130
}
131
else {
132
if (++UFO_Setup->machLevel == 2)
133
hud->machPaletteBank = 3;
134
}
135
136
UFO_Player_ChangeMachState();
137
138
hud->scale.x = 0x300;
139
hud->scale.y = 0x300;
140
RSDK.PlaySfx(UFO_Sphere->sfxMachSpeed, false, 0xFF);
141
}
142
143
if (hud->scale.x == 0x200) {
144
int32 cnt = 32 * UFO_Setup->machPoints / UFO_Setup->machQuotas[UFO_Setup->machLevel];
145
RSDK.CopyPalette(hud->machPaletteBank, 96, 0, 96, cnt);
146
RSDK.CopyPalette(1, cnt + 96, 0, cnt + 96, (uint8)(32 - cnt));
147
}
148
}
149
150
void UFO_HUD_LevelUpMach(void)
151
{
152
EntityUFO_HUD *hud = RSDK_GET_ENTITY(SLOT_UFO_HUD, UFO_HUD);
153
UFO_Setup->machPoints = 0;
154
155
if (UFO_Setup->machLevel >= 2) {
156
++UFO_Setup->scoreBonus;
157
hud->timer = 60;
158
}
159
else {
160
if (++UFO_Setup->machLevel == 2)
161
hud->machPaletteBank = 3;
162
}
163
164
UFO_Player_ChangeMachState();
165
166
hud->scale.x = 0x300;
167
hud->scale.y = 0x300;
168
RSDK.PlaySfx(UFO_Sphere->sfxMachSpeed, false, 255);
169
}
170
171
void UFO_HUD_DrawNumbers(Vector2 *drawPos, int32 value)
172
{
173
RSDK_THIS(UFO_HUD);
174
175
int32 mult = 1;
176
for (int32 i = 0; i < 3; ++i) {
177
self->numbersAnimator.frameID = value / mult % 10;
178
RSDK.DrawSprite(&self->numbersAnimator, drawPos, true);
179
drawPos->x -= 0x100000;
180
mult *= 10;
181
}
182
}
183
184
#if GAME_INCLUDE_EDITOR
185
void UFO_HUD_EditorDraw(void) {}
186
187
void UFO_HUD_EditorLoad(void) {}
188
#endif
189
190
void UFO_HUD_Serialize(void) {}
191
192