Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/TMZ/TMZCable.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: TMZCable Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectTMZCable *TMZCable;
11
12
void TMZCable_Update(void)
13
{
14
RSDK_THIS(TMZCable);
15
16
StateMachine_Run(self->state);
17
}
18
19
void TMZCable_LateUpdate(void) {}
20
21
void TMZCable_StaticUpdate(void) {}
22
23
void TMZCable_Draw(void)
24
{
25
RSDK_THIS(TMZCable);
26
27
for (int32 i = 0; i < TMZCABLE_JOINT_COUNT; ++i) {
28
if (!self->jointVisible[i])
29
RSDK.DrawSprite(&self->animator, &self->jointPos[i], false);
30
}
31
}
32
33
void TMZCable_Create(void *data)
34
{
35
RSDK_THIS(TMZCable);
36
37
if (!SceneInfo->inEditor) {
38
self->visible = true;
39
self->drawGroup = Zone->objectDrawGroup[0];
40
self->cableID &= 3;
41
self->active = ACTIVE_BOUNDS;
42
self->updateRange.x = 0x800000;
43
self->updateRange.y = 0x800000;
44
45
switch (self->cableID) {
46
case 0:
47
self->offset.x = -0x1C0000;
48
self->offset.y = 0x100000;
49
self->angle = 0x00;
50
break;
51
52
case 1:
53
self->offset.x = 0x1C0000;
54
self->offset.y = 0x100000;
55
self->angle = 0x40;
56
break;
57
58
case 2:
59
self->offset.x = -0x1C0000;
60
self->offset.y = -0x100000;
61
self->angle = 0x80;
62
break;
63
64
case 3:
65
self->offset.x = 0x1C0000;
66
self->offset.y = -0x100000;
67
self->angle = 0xC0;
68
break;
69
70
default: break;
71
}
72
73
self->parentPos = (Vector2 *)data;
74
RSDK.SetSpriteAnimation(PhantomEgg->aniFrames, 9, &self->animator, true, 0);
75
}
76
}
77
78
void TMZCable_StageLoad(void)
79
{
80
TMZCable->hitbox.left = -10;
81
TMZCable->hitbox.top = -10;
82
TMZCable->hitbox.right = 10;
83
TMZCable->hitbox.bottom = 10;
84
}
85
86
void TMZCable_HandleDrawPositions(void)
87
{
88
RSDK_THIS(TMZCable);
89
90
if (self->parentPos) {
91
int32 x = self->parentPos->x + self->offset.x;
92
int32 y = self->parentPos->y + self->offset.y;
93
int32 entityAngle = self->angle;
94
int32 angle = RSDK.ATan2((self->position.x - x) >> 16, (self->position.y - y) >> 16) + 64;
95
96
int32 id = 0;
97
for (int32 i = 0; i < (18 * TMZCABLE_JOINT_COUNT); i += 18) {
98
self->jointPos[id].x = x + 0x20 * id * ((self->position.x - x) >> 8);
99
self->jointPos[id].y = y + 0x20 * id * ((self->position.y - y) >> 8);
100
self->jointPos[id].x += ((RSDK.Sin256(entityAngle) * RSDK.Sin256(i)) >> 5) * RSDK.Cos256(angle);
101
self->jointPos[id].y += ((RSDK.Sin256(entityAngle) * RSDK.Sin256(i)) >> 5) * RSDK.Sin256(angle);
102
103
entityAngle += 32;
104
id++;
105
}
106
}
107
}
108
109
void TMZCable_State_Idle(void)
110
{
111
RSDK_THIS(TMZCable);
112
113
TMZCable_HandleDrawPositions();
114
self->angle = (self->angle + 4) & 0xFF;
115
}
116
117
void TMZCable_State_Charge(void)
118
{
119
RSDK_THIS(TMZCable);
120
121
RSDK.ProcessAnimation(&self->animator);
122
123
if (self->animator.frameID == self->animator.frameCount - 1) {
124
RSDK.SetSpriteAnimation(PhantomEgg->aniFrames, 11, &self->animator, true, RSDK.Rand(0, 8));
125
self->state = TMZCable_State_Live;
126
}
127
}
128
129
void TMZCable_State_Live(void)
130
{
131
RSDK_THIS(TMZCable);
132
133
RSDK.ProcessAnimation(&self->animator);
134
135
int32 storeX = self->position.x;
136
int32 storeY = self->position.y;
137
138
for (int32 i = 1; i < TMZCABLE_JOINT_COUNT; ++i) {
139
self->position.x = self->jointPos[i].x;
140
self->position.y = self->jointPos[i].y;
141
142
foreach_active(Player, player)
143
{
144
if (Player_CheckCollisionTouch(player, self, &TMZCable->hitbox)) {
145
Player_Hurt(player, self);
146
}
147
}
148
}
149
150
self->position.x = storeX;
151
self->position.y = storeY;
152
153
if (++self->timer == 120) {
154
self->timer = 0;
155
RSDK.SetSpriteAnimation(PhantomEgg->aniFrames, 12, &self->animator, true, 0);
156
self->state = TMZCable_State_Fade;
157
}
158
}
159
160
void TMZCable_State_Fade(void)
161
{
162
RSDK_THIS(TMZCable);
163
164
RSDK.ProcessAnimation(&self->animator);
165
if (self->animator.frameID == self->animator.frameCount - 1) {
166
RSDK.SetSpriteAnimation(PhantomEgg->aniFrames, 9, &self->animator, true, 0);
167
self->state = TMZCable_State_Idle;
168
}
169
}
170
171
void TMZCable_State_Destroyed(void)
172
{
173
RSDK_THIS(TMZCable);
174
TMZCable_HandleDrawPositions();
175
176
int32 id = self->timer >> 5;
177
if (!(Zone->timer % 3)) {
178
RSDK.PlaySfx(PhantomEgg->sfxExplosion2, false, 255);
179
if (Zone->timer & 4) {
180
int32 y = self->jointPos[id].y + RSDK.Rand(-0x100000, 0x100000);
181
int32 x = self->jointPos[id].x + RSDK.Rand(-0x100000, 0x100000);
182
CREATE_ENTITY(Explosion, INT_TO_VOID((RSDK.Rand(0, 256) > 192) + EXPLOSION_BOSS), x, y)->drawGroup = Zone->objectDrawGroup[1];
183
}
184
}
185
186
self->timer += 3;
187
if (self->timer < 256) {
188
int32 timer = self->timer & 0x1F;
189
if (timer >= 29) {
190
self->jointVisible[id] = true;
191
192
EntityDebris *debris = CREATE_ENTITY(Debris, NULL, self->jointPos[id].x, self->jointPos[id].y);
193
debris->state = Debris_State_Fall;
194
debris->gravityStrength = 0x4000;
195
debris->velocity.x = RSDK.Rand(-0x20000, 0x20000);
196
debris->velocity.y = RSDK.Rand(-0x40000, -0x10000);
197
debris->drawGroup = Zone->objectDrawGroup[0];
198
RSDK.SetSpriteAnimation(PhantomEgg->aniFrames, 9, &debris->animator, true, 0);
199
}
200
}
201
else {
202
destroyEntity(self);
203
}
204
}
205
206
#if GAME_INCLUDE_EDITOR
207
void TMZCable_EditorDraw(void)
208
{
209
RSDK_THIS(TMZCable);
210
211
if (PhantomEgg) {
212
uint8 angles[] = { 0x00, 0x40, 0x80, 0xC0 };
213
self->angle = angles[self->cableID & 3];
214
RSDK.SetSpriteAnimation(PhantomEgg->aniFrames, 9, &self->animator, true, 0);
215
216
for (int32 i = 0; i < TMZCABLE_JOINT_COUNT; ++i) {
217
self->jointPos[i].x = self->position.x;
218
self->jointPos[i].y = self->position.y;
219
}
220
221
TMZCable_Draw();
222
}
223
}
224
225
void TMZCable_EditorLoad(void)
226
{
227
228
RSDK_ACTIVE_VAR(TMZCable, cableID);
229
RSDK_ENUM_VAR("Cable 1", 0);
230
RSDK_ENUM_VAR("Cable 2", 1);
231
RSDK_ENUM_VAR("Cable 3", 2);
232
RSDK_ENUM_VAR("Cable 4", 3);
233
}
234
#endif
235
236
void TMZCable_Serialize(void) { RSDK_EDITABLE_VAR(TMZCable, VAR_ENUM, cableID); }
237
238