Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/UFO/UFO_ItemBox.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: UFO_ItemBox Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectUFO_ItemBox *UFO_ItemBox;
11
12
void UFO_ItemBox_Update(void)
13
{
14
RSDK_THIS(UFO_ItemBox);
15
StateMachine_Run(self->state);
16
}
17
18
void UFO_ItemBox_LateUpdate(void)
19
{
20
RSDK_THIS(UFO_ItemBox);
21
22
if (self->state == UFO_ItemBox_State_HasContents) {
23
self->visible = true;
24
25
int32 x = self->position.x >> 8;
26
int32 y = self->height >> 8;
27
int32 z = self->position.y >> 8;
28
29
Matrix *mat = &UFO_Camera->matWorld;
30
31
self->worldX = mat->values[0][3] + (y * mat->values[0][1] >> 8) + (z * mat->values[0][2] >> 8) + (x * mat->values[0][0] >> 8);
32
self->worldY = mat->values[1][3] + (y * mat->values[1][1] >> 8) + (z * mat->values[1][2] >> 8) + (x * mat->values[1][0] >> 8);
33
self->zdepth = mat->values[2][3] + (y * mat->values[2][1] >> 8) + (z * mat->values[2][2] >> 8) + (x * mat->values[2][0] >> 8);
34
35
if (self->zdepth >= 0x2000) {
36
int32 depth = (int32)((mat->values[0][3] << 8) + (y * mat->values[0][1] & 0xFFFFFF00) + (z * mat->values[0][2] & 0xFFFFFF00)
37
+ (x * mat->values[0][0] & 0xFFFFFF00))
38
/ self->zdepth;
39
40
self->visible = abs(depth) < 0x100;
41
}
42
else {
43
self->visible = false;
44
}
45
}
46
}
47
48
void UFO_ItemBox_StaticUpdate(void) {}
49
50
void UFO_ItemBox_Draw(void)
51
{
52
RSDK_THIS(UFO_ItemBox);
53
54
if (self->state == UFO_ItemBox_State_HasContents) {
55
RSDK_GET_ENTITY(SLOT_UFO_CAMERA, UFO_Camera);
56
57
RSDK.Prepare3DScene(UFO_ItemBox->sceneIndex);
58
59
RSDK.MatrixTranslateXYZ(&self->matTransform, self->position.x, self->height, self->position.y, true);
60
RSDK.MatrixRotateY(&self->matNormal, 8 * UFO_Setup->timer);
61
62
RSDK.MatrixMultiply(&self->matWorld, &self->matNormal, &self->matTransform);
63
RSDK.MatrixMultiply(&self->matWorld, &self->matWorld, &UFO_Camera->matWorld);
64
65
RSDK.MatrixRotateXYZ(&self->matNormal, 0, 8 * UFO_Setup->timer, 4 * UFO_Setup->timer);
66
67
RSDK.AddModelTo3DScene(UFO_ItemBox->meshFrames, UFO_ItemBox->sceneIndex, S3D_WIREFRAME_SHADED_SCREEN, &self->matWorld, &self->matNormal,
68
0xFFFF00);
69
70
RSDK.Draw3DScene(UFO_ItemBox->sceneIndex);
71
72
self->drawPos.x = (ScreenInfo->center.x + (self->worldX << 8) / self->zdepth) << 16;
73
self->drawPos.y = (ScreenInfo->center.y - (self->worldY << 8) / self->zdepth) << 16;
74
self->scale.x = 0x2000000 / self->zdepth;
75
self->scale.y = 0x2000000 / self->zdepth;
76
}
77
78
RSDK.DrawSprite(&self->contentsAnimator, &self->drawPos, true);
79
}
80
81
void UFO_ItemBox_Create(void *data)
82
{
83
RSDK_THIS(UFO_ItemBox);
84
85
if (!SceneInfo->inEditor) {
86
self->visible = true;
87
self->drawFX = FX_SCALE;
88
self->drawGroup = 4;
89
self->active = ACTIVE_RBOUNDS;
90
self->updateRange.x = 0x400;
91
self->updateRange.y = 0x400;
92
93
self->contentsTimer = 256;
94
self->sfxTimer = 10;
95
if (!self->height)
96
self->height = 12;
97
98
self->height <<= 16;
99
self->state = UFO_ItemBox_State_HasContents;
100
101
RSDK.SetSpriteAnimation(UFO_ItemBox->aniFrames, 0, &self->contentsAnimator, true, self->type);
102
}
103
}
104
105
void UFO_ItemBox_StageLoad(void)
106
{
107
UFO_ItemBox->aniFrames = RSDK.LoadSpriteAnimation("SpecialUFO/Items.bin", SCOPE_STAGE);
108
109
UFO_ItemBox->meshFrames = RSDK.LoadMesh("Special/ItemBox.bin", SCOPE_STAGE);
110
UFO_ItemBox->sceneIndex = RSDK.Create3DScene("View:Items", 1024, SCOPE_STAGE);
111
112
UFO_ItemBox->breakCount = -1;
113
114
RSDK.SetDiffuseColor(UFO_ItemBox->sceneIndex, 0xA0, 0xA0, 0x00);
115
RSDK.SetDiffuseIntensity(UFO_ItemBox->sceneIndex, 8, 8, 0);
116
RSDK.SetSpecularIntensity(UFO_ItemBox->sceneIndex, 14, 14, 0);
117
118
UFO_ItemBox->sfxDestroy = RSDK.GetSfx("Global/Destroy.wav");
119
UFO_ItemBox->sfxRockemSockem = RSDK.GetSfx("Stage/RockemSockem.wav");
120
UFO_ItemBox->sfxBumper = RSDK.GetSfx("Stage/Bumper.wav");
121
}
122
123
void UFO_ItemBox_State_HasContents(void)
124
{
125
RSDK_THIS(UFO_ItemBox);
126
127
foreach_active(UFO_Player, player)
128
{
129
if (self->timer) {
130
self->timer--;
131
}
132
else if (player->stateInput) {
133
if (player->state != UFO_Player_State_CourseOut) {
134
int32 rx = (self->position.x - player->position.x) >> 16;
135
int32 ry = (self->height - player->height - 0xA0000) >> 16;
136
int32 rz = (self->position.y - player->position.y) >> 16;
137
138
if (rx * rx + ry * ry + rz * rz < UFO_Player->maxSpeed >> 8) {
139
player->gravityStrength = 0x60000;
140
player->onGround = false;
141
player->state = UFO_Player_State_Jump;
142
143
RSDK.SetModelAnimation(UFO_Player->jumpModel, &player->animator, 128, 0, true, 0);
144
145
#if MANIA_USE_PLUS
146
if (self->type >= UFO_ITEMBOX_BUMPER) {
147
RSDK.PlaySfx(UFO_ItemBox->sfxBumper, false, 255);
148
self->timer = 16;
149
}
150
else {
151
#endif
152
RSDK.PlaySfx(UFO_ItemBox->sfxDestroy, false, 255);
153
self->drawGroup = 12;
154
self->active = 2;
155
self->state = UFO_ItemBox_State_ShowContents;
156
#if MANIA_USE_PLUS
157
}
158
#endif
159
++UFO_ItemBox->breakCount;
160
}
161
}
162
}
163
}
164
}
165
166
void UFO_ItemBox_State_ShowContents(void)
167
{
168
RSDK_THIS(UFO_ItemBox);
169
170
self->drawPos.x += ((ScreenInfo->center.x << 16) - self->drawPos.x) >> 3;
171
self->drawPos.y += (((ScreenInfo->center.x - 4) << 16) - self->drawPos.y) >> 3;
172
173
int32 scale = self->scale.x + ((0x200 - self->scale.x) >> 3);
174
self->scale.x = scale;
175
self->scale.y = scale;
176
177
if (self->contentsTimer > 0)
178
self->contentsTimer -= 8;
179
180
if (++self->timer > 15) {
181
self->visible = (self->timer >> 2) & 1;
182
183
switch (self->type) {
184
case UFO_ITEMBOX_RING:
185
if (!(self->timer & 3)) {
186
if (self->sfxTimer > 0) {
187
self->sfxTimer--;
188
UFO_Ring_PlayRingSfx();
189
}
190
}
191
break;
192
193
case UFO_ITEMBOX_SPHERE:
194
if (!(self->timer & 1) && self->sfxTimer > 0) {
195
++UFO_Setup->machPoints;
196
UFO_HUD_CheckLevelUp();
197
UFO_Setup_PlaySphereSfx();
198
}
199
break;
200
201
case UFO_ITEMBOX_LVLUP:
202
if (self->timer == 16)
203
UFO_HUD_LevelUpMach();
204
break;
205
}
206
}
207
208
if (self->timer == 80) {
209
if (UFO_ItemBox->breakCount > -1)
210
UFO_ItemBox->breakCount--;
211
212
destroyEntity(self);
213
}
214
}
215
216
#if GAME_INCLUDE_EDITOR
217
void UFO_ItemBox_EditorDraw(void)
218
{
219
RSDK_THIS(UFO_ItemBox);
220
221
RSDK.SetSpriteAnimation(UFO_ItemBox->aniFrames, 0, &self->contentsAnimator, true, self->type);
222
223
RSDK.DrawSprite(&self->contentsAnimator, NULL, false);
224
}
225
226
void UFO_ItemBox_EditorLoad(void)
227
{
228
UFO_ItemBox->aniFrames = RSDK.LoadSpriteAnimation("SpecialUFO/Items.bin", SCOPE_STAGE);
229
230
RSDK_ACTIVE_VAR(UFO_ItemBox, type);
231
RSDK_ENUM_VAR("Rings", UFO_ITEMBOX_RING);
232
RSDK_ENUM_VAR("Spheres", UFO_ITEMBOX_SPHERE);
233
RSDK_ENUM_VAR("Level Up", UFO_ITEMBOX_LVLUP);
234
#if MANIA_USE_PLUS
235
RSDK_ENUM_VAR("Bumper", UFO_ITEMBOX_BUMPER);
236
#endif
237
}
238
#endif
239
240
void UFO_ItemBox_Serialize(void)
241
{
242
RSDK_EDITABLE_VAR(UFO_ItemBox, VAR_ENUM, type);
243
RSDK_EDITABLE_VAR(UFO_ItemBox, VAR_ENUM, height);
244
}
245
246