Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Pinball/PBL_Ring.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PBL_Ring 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_Ring *PBL_Ring;
12
13
void PBL_Ring_Update(void)
14
{
15
RSDK_THIS(PBL_Ring);
16
17
StateMachine_Run(self->state);
18
}
19
20
void PBL_Ring_LateUpdate(void)
21
{
22
RSDK_THIS(PBL_Ring);
23
24
int32 x = self->position.x >> 8;
25
int32 y = self->height >> 8;
26
int32 z = self->position.y >> 8;
27
28
Matrix *m = &PBL_Camera->matWorld;
29
30
self->worldX = m->values[0][3] + (y * m->values[0][1] >> 8) + (z * m->values[0][2] >> 8) + (x * m->values[0][0] >> 8);
31
self->worldY = m->values[1][3] + (y * m->values[1][1] >> 8) + (z * m->values[1][2] >> 8) + (x * m->values[1][0] >> 8);
32
self->zdepth = m->values[2][3] + (y * m->values[2][1] >> 8) + (z * m->values[2][2] >> 8) + (x * m->values[2][0] >> 8);
33
}
34
35
void PBL_Ring_StaticUpdate(void) {}
36
37
void PBL_Ring_Draw(void)
38
{
39
RSDK_THIS(PBL_Ring);
40
41
if (self->zdepth >= 0x100) {
42
self->direction = self->animator.frameID > 8;
43
44
Vector2 drawPos;
45
drawPos.x = (ScreenInfo->center.x + (self->worldX << 8) / self->zdepth) << 16;
46
drawPos.y = (ScreenInfo->center.y - (self->worldY << 8) / self->zdepth) << 16;
47
48
self->scale.x = 0x1000000 / self->zdepth;
49
self->scale.y = 0x1000000 / self->zdepth;
50
51
if (self->state == PBL_Ring_State_Ring)
52
self->animator.frameID = PBL_Setup->ringFrame;
53
54
RSDK.DrawSprite(&self->animator, &drawPos, true);
55
}
56
}
57
58
void PBL_Ring_Create(void *data)
59
{
60
RSDK_THIS(PBL_Ring);
61
62
if (!SceneInfo->inEditor) {
63
self->visible = true;
64
self->drawFX = FX_SCALE | FX_FLIP;
65
self->drawGroup = 4;
66
self->active = ACTIVE_BOUNDS;
67
self->updateRange.x = 0x400000;
68
self->updateRange.y = 0x400000;
69
70
if (!self->height)
71
self->height = 12;
72
self->height <<= 16;
73
74
self->state = PBL_Ring_State_Ring;
75
RSDK.SetSpriteAnimation(PBL_Ring->aniFrames, 1, &self->animator, true, 0);
76
}
77
}
78
79
void PBL_Ring_StageLoad(void)
80
{
81
PBL_Ring->aniFrames = RSDK.LoadSpriteAnimation("Global/Ring.bin", SCOPE_STAGE);
82
83
PBL_Ring->sfxRing = RSDK.GetSfx("Global/Ring.wav");
84
}
85
86
void PBL_Ring_GiveRing(void)
87
{
88
if (PBL_Setup->rings < 999)
89
PBL_Setup->rings++;
90
91
PBL_Setup_GiveScore(10);
92
93
if (PBL_Setup->ringPan) {
94
int32 channel = RSDK.PlaySfx(PBL_Ring->sfxRing, false, 0xFF);
95
RSDK.SetChannelAttributes(channel, 1.0, -1.0, 1.0);
96
PBL_Setup->ringPan = 0;
97
}
98
else {
99
int32 channel = RSDK.PlaySfx(PBL_Ring->sfxRing, false, 0xFF);
100
RSDK.SetChannelAttributes(channel, 1.0, 1.0, 1.0);
101
PBL_Setup->ringPan = 1;
102
}
103
}
104
105
void PBL_Ring_State_Ring(void)
106
{
107
RSDK_THIS(PBL_Ring);
108
109
foreach_active(PBL_Player, player)
110
{
111
int32 ry = (self->height - player->height - 0xA0000) >> 16;
112
int32 rz = (self->position.y - player->position.y) >> 16;
113
int32 rx = (self->position.x - player->position.x) >> 16;
114
115
if (rx * rx + rz * rz + ry * ry < 0x100) {
116
RSDK.SetSpriteAnimation(PBL_Ring->aniFrames, 2, &self->animator, true, 4);
117
++self->drawGroup;
118
119
self->state = PBL_Ring_State_RingSparkle;
120
PBL_Ring_GiveRing();
121
}
122
}
123
}
124
125
void PBL_Ring_State_RingSparkle(void)
126
{
127
RSDK_THIS(PBL_Ring);
128
129
RSDK.ProcessAnimation(&self->animator);
130
131
if (self->animator.frameID == 15) {
132
self->state = StateMachine_None;
133
self->active = ACTIVE_NEVER;
134
}
135
}
136
137
#if GAME_INCLUDE_EDITOR
138
void PBL_Ring_EditorDraw(void)
139
{
140
RSDK_THIS(PBL_Ring);
141
142
RSDK.SetSpriteAnimation(PBL_Ring->aniFrames, 0, &self->animator, true, 0);
143
144
RSDK.DrawSprite(&self->animator, NULL, false);
145
}
146
147
void PBL_Ring_EditorLoad(void) { PBL_Ring->aniFrames = RSDK.LoadSpriteAnimation("Global/Ring.bin", SCOPE_STAGE); }
148
#endif
149
150
void PBL_Ring_Serialize(void) { RSDK_EDITABLE_VAR(PBL_Ring, VAR_ENUM, height); }
151
#endif
152
153