Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/LRZ/KingClaw.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: KingClaw Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectKingClaw *KingClaw;
11
12
void KingClaw_Update(void)
13
{
14
RSDK_THIS(KingClaw);
15
16
StateMachine_Run(self->state);
17
18
KingClaw_HandleJointPositions();
19
}
20
21
void KingClaw_LateUpdate(void) {}
22
23
void KingClaw_StaticUpdate(void)
24
{
25
foreach_active(KingClaw, claw) { RSDK.AddDrawListRef(1, RSDK.GetEntitySlot(claw)); }
26
}
27
28
void KingClaw_Draw(void)
29
{
30
RSDK_THIS(KingClaw);
31
32
if (self->forceHighdrawGroup) {
33
RSDK.DrawSprite(&self->clawBackAnimator, &self->drawPos, false);
34
35
for (int32 i = 0; i < KINGCLAW_CHAIN_COUNT; ++i) RSDK.DrawSprite(&self->chainAnimator, &self->chainPos[i], false);
36
}
37
else {
38
if (SceneInfo->currentDrawGroup != Zone->objectDrawGroup[0])
39
RSDK.DrawSprite(&self->clawBackAnimator, &self->drawPos, false);
40
else
41
for (int32 i = 0; i < KINGCLAW_CHAIN_COUNT; ++i) RSDK.DrawSprite(&self->chainAnimator, &self->chainPos[i], false);
42
}
43
44
RSDK.DrawSprite(&self->hingeAnimator, &self->drawPos, false);
45
RSDK.DrawSprite(&self->clawFrontAnimator, &self->drawPos, false);
46
}
47
48
void KingClaw_Create(void *data)
49
{
50
RSDK_THIS(KingClaw);
51
52
if (!SceneInfo->inEditor) {
53
self->visible = true;
54
self->drawFX = FX_ROTATE;
55
self->drawGroup = Zone->objectDrawGroup[0];
56
self->targetY = self->position.y - 0x300000;
57
self->position.y = self->position.y - 0x1000000;
58
self->active = ACTIVE_XBOUNDS;
59
self->updateRange.x = 0x800000;
60
self->updateRange.y = 0x1000000;
61
62
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 0, &self->chainAnimator, true, 0);
63
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 1, &self->hingeAnimator, true, 0);
64
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 3, &self->clawBackAnimator, true, 0);
65
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 2, &self->clawFrontAnimator, true, 0);
66
}
67
}
68
69
void KingClaw_StageLoad(void)
70
{
71
KingClaw->aniFrames = RSDK.LoadSpriteAnimation("LRZ3/Claw.bin", SCOPE_STAGE);
72
73
KingClaw->active = ACTIVE_NORMAL;
74
75
KingClaw->sfxClack = RSDK.GetSfx("Stage/Clack.wav");
76
KingClaw->sfxWalkerLegs = RSDK.GetSfx("LRZ/WalkerLegs.wav");
77
}
78
79
void KingClaw_HandleJointPositions(void)
80
{
81
RSDK_THIS(KingClaw);
82
83
self->drawPos.x = self->position.x;
84
self->drawPos.y = self->position.y;
85
86
for (int32 i = 0; i < KINGCLAW_CHAIN_COUNT; ++i) {
87
self->chainPos[i].x = self->drawPos.x;
88
self->chainPos[i].y = self->drawPos.y;
89
self->drawPos.x += RSDK.Sin256(self->angle) << 12;
90
self->drawPos.y += RSDK.Cos256(self->angle) << 12;
91
}
92
93
self->drawPos.x += 0xC00 * RSDK.Sin256(self->angle);
94
self->drawPos.y += 0xC00 * RSDK.Cos256(self->angle);
95
}
96
97
void KingClaw_State_EnterClaw(void)
98
{
99
RSDK_THIS(KingClaw);
100
101
if (self->position.y >= self->targetY)
102
self->state = StateMachine_None;
103
else
104
self->position.y += 0x8000;
105
}
106
107
void KingClaw_State_Grab(void)
108
{
109
RSDK_THIS(KingClaw);
110
111
if (!self->timer)
112
RSDK.PlaySfx(KingClaw->sfxClack, false, 0);
113
114
++self->timer;
115
if (!(self->timer & 3)) {
116
if (self->clawFrontAnimator.frameID < 3) {
117
++self->clawBackAnimator.frameID;
118
++self->clawFrontAnimator.frameID;
119
120
if (self->clawFrontAnimator.frameID == 3)
121
RSDK.PlaySfx(KingClaw->sfxWalkerLegs, false, 0);
122
}
123
}
124
125
if (self->timer == 60) {
126
foreach_active(HPZEmerald, emerald)
127
{
128
if (emerald->type == HPZEMERALD_MASTER)
129
self->masterEmerald = emerald;
130
}
131
132
self->timer = 0;
133
self->state = KingClaw_State_LiftMasterEmerald;
134
}
135
}
136
137
void KingClaw_State_LiftMasterEmerald(void)
138
{
139
RSDK_THIS(KingClaw);
140
141
self->position.y -= 0x2000;
142
143
if (self->masterEmerald)
144
self->masterEmerald->position.y = self->position.y + 0xF80000;
145
146
if (++self->timer == 480) {
147
self->timer = 0;
148
self->state = StateMachine_None;
149
}
150
}
151
152
void KingClaw_State_Swinging(void)
153
{
154
RSDK_THIS(KingClaw);
155
156
if (self->clawFrontAnimator.frameID > 0) {
157
--self->clawBackAnimator.frameID;
158
--self->clawFrontAnimator.frameID;
159
}
160
161
if (self->velocity.y > -0x8000)
162
self->velocity.y -= 0x100;
163
164
self->position.y += self->velocity.y;
165
self->angle = RSDK.Sin256(-self->timer) >> 4;
166
self->rotation = -2 * self->angle;
167
168
self->timer += 3;
169
if (self->timer >= 0x800) {
170
self->state = StateMachine_None;
171
self->angle = 0;
172
self->timer = 0;
173
}
174
}
175
176
void KingClaw_State_LowerClaw(void)
177
{
178
RSDK_THIS(KingClaw);
179
180
if (self->velocity.y < 0x40000)
181
self->velocity.y += 0x200;
182
183
if (self->position.y >= self->targetY) {
184
self->velocity.y >>= 3;
185
self->state = StateMachine_None;
186
}
187
else {
188
self->position.y += self->velocity.y;
189
}
190
}
191
192
void KingClaw_State_RaiseClaw(void)
193
{
194
RSDK_THIS(KingClaw);
195
196
if (self->velocity.y > -0x80000)
197
self->velocity.y -= 0x400;
198
199
self->position.y += self->velocity.y;
200
}
201
202
#if GAME_INCLUDE_EDITOR
203
void KingClaw_EditorDraw(void)
204
{
205
RSDK_THIS(KingClaw);
206
207
self->updateRange.x = 0x800000;
208
self->updateRange.y = 0x1000000;
209
210
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 0, &self->chainAnimator, true, 0);
211
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 1, &self->hingeAnimator, true, 0);
212
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 3, &self->clawBackAnimator, true, 0);
213
RSDK.SetSpriteAnimation(KingClaw->aniFrames, 2, &self->clawFrontAnimator, true, 0);
214
215
self->forceHighdrawGroup = true;
216
217
KingClaw_HandleJointPositions();
218
KingClaw_Draw();
219
220
if (showGizmos()) {
221
RSDK_DRAWING_OVERLAY(true);
222
223
self->position.y += SCREEN_YSIZE << 15;
224
DrawHelpers_DrawArenaBounds(-320, -(SCREEN_YSIZE >> 1), 320, SCREEN_YSIZE >> 1, 1 | 2 | 4 | 0, 0x00C0F0);
225
self->position.y -= SCREEN_YSIZE << 15;
226
227
RSDK_DRAWING_OVERLAY(false);
228
}
229
}
230
231
void KingClaw_EditorLoad(void) { KingClaw->aniFrames = RSDK.LoadSpriteAnimation("LRZ3/Claw.bin", SCOPE_STAGE); }
232
#endif
233
234
void KingClaw_Serialize(void) {}
235
236