Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/AIZ/AIZKingClaw.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: AIZKingClaw Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectAIZKingClaw *AIZKingClaw;
11
12
void AIZKingClaw_Update(void)
13
{
14
RSDK_THIS(AIZKingClaw);
15
StateMachine_Run(self->state);
16
17
for (int32 i = 0; i < MIN(self->grabCount, 8); ++i) {
18
Entity *grabbed = self->grabbedEntities[i];
19
if (grabbed) {
20
grabbed->position.x = self->clawPos.x;
21
grabbed->position.y = self->clawPos.y + 0x2C0000;
22
23
if (grabbed->classID == Platform->classID) {
24
EntityPlatform *plat = (EntityPlatform *)grabbed;
25
plat->drawPos.x = plat->position.x;
26
plat->drawPos.y = plat->position.y;
27
plat->centerPos.x = plat->position.x;
28
plat->centerPos.y = plat->position.y;
29
}
30
}
31
}
32
33
AIZKingClaw_HandleClawPositions();
34
}
35
36
void AIZKingClaw_LateUpdate(void) {}
37
38
void AIZKingClaw_StaticUpdate(void)
39
{
40
foreach_active(AIZKingClaw, claw) { RSDK.AddDrawListRef(Zone->objectDrawGroup[1], RSDK.GetEntitySlot(claw)); }
41
}
42
43
void AIZKingClaw_Draw(void)
44
{
45
RSDK_THIS(AIZKingClaw);
46
if (SceneInfo->currentDrawGroup == Zone->objectDrawGroup[0]) {
47
RSDK.DrawSprite(&self->clawBackAnimator, &self->clawPos, false);
48
}
49
else {
50
for (int32 i = 0; i < AIZKingClaw_ChainCount; ++i) RSDK.DrawSprite(&self->chainAnimator, &self->chainPos[i], false);
51
52
RSDK.DrawSprite(&self->hingeAnimator, &self->clawPos, false);
53
RSDK.DrawSprite(&self->clawFrontAnimator, &self->clawPos, false);
54
}
55
}
56
57
void AIZKingClaw_Create(void *data)
58
{
59
RSDK_THIS(AIZKingClaw);
60
if (!SceneInfo->inEditor) {
61
self->visible = true;
62
self->drawFX = FX_ROTATE;
63
self->drawGroup = Zone->objectDrawGroup[0];
64
self->active = ACTIVE_NORMAL;
65
self->updateRange.x = 0x800000;
66
self->updateRange.y = 0x1000000;
67
self->startY = self->position.y - 0x300000;
68
if (RSDK.CheckSceneFolder("AIZ")) {
69
self->position.y -= 0x1000000;
70
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 3, &self->clawBackAnimator, true, 0);
71
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 2, &self->clawFrontAnimator, true, 0);
72
}
73
else {
74
self->position.y -= 0x40000;
75
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 3, &self->clawBackAnimator, true, 3);
76
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 2, &self->clawFrontAnimator, true, 3);
77
}
78
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 0, &self->chainAnimator, true, 0);
79
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 1, &self->hingeAnimator, true, 0);
80
}
81
}
82
83
void AIZKingClaw_StageLoad(void)
84
{
85
if (RSDK.CheckSceneFolder("AIZ")) {
86
AIZKingClaw->aniFrames = RSDK.LoadSpriteAnimation("AIZ/Claw.bin", SCOPE_STAGE);
87
}
88
else if (RSDK.CheckSceneFolder("GHZCutscene")) {
89
AIZKingClaw->aniFrames = RSDK.LoadSpriteAnimation("GHZCutscene/Claw.bin", SCOPE_STAGE);
90
}
91
92
AIZKingClaw->active = ACTIVE_NORMAL;
93
AIZKingClaw->sfxClack = RSDK.GetSfx("Stage/Clack.wav");
94
AIZKingClaw->sfxWalkerLegs = RSDK.GetSfx("LRZ/WalkerLegs.wav");
95
}
96
97
void AIZKingClaw_HandleClawPositions(void)
98
{
99
RSDK_THIS(AIZKingClaw);
100
101
self->clawPos.x = self->position.x;
102
self->clawPos.y = self->position.y;
103
int32 moveX = RSDK.Sin256(self->angle) << 12;
104
int32 moveY = RSDK.Cos256(self->angle) << 12;
105
106
for (int32 i = 0; i < AIZKingClaw_ChainCount; ++i) {
107
self->chainPos[i].x = self->clawPos.x;
108
self->chainPos[i].y = self->clawPos.y;
109
self->clawPos.x += moveX;
110
self->clawPos.y += moveY;
111
}
112
113
self->clawPos.x += 0xC00 * RSDK.Sin256(self->angle);
114
self->clawPos.y += 0xC00 * RSDK.Cos256(self->angle);
115
}
116
117
void AIZKingClaw_State_Grab(void)
118
{
119
RSDK_THIS(AIZKingClaw);
120
if (!self->timer)
121
RSDK.PlaySfx(AIZKingClaw->sfxClack, false, 0);
122
123
++self->timer;
124
if (!(self->timer & 3)) {
125
if (self->clawFrontAnimator.frameID >= 3) {
126
self->state = StateMachine_None;
127
}
128
else {
129
self->clawBackAnimator.frameID++;
130
self->clawFrontAnimator.frameID++;
131
if (self->clawFrontAnimator.frameID == 3)
132
RSDK.PlaySfx(AIZKingClaw->sfxWalkerLegs, false, 0);
133
}
134
}
135
}
136
137
#if GAME_INCLUDE_EDITOR
138
void AIZKingClaw_EditorDraw(void)
139
{
140
RSDK_THIS(AIZKingClaw);
141
int32 y = self->position.y;
142
if (RSDK.CheckSceneFolder("AIZ")) {
143
self->position.y -= 0x1000000;
144
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 3, &self->clawBackAnimator, true, 0);
145
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 2, &self->clawFrontAnimator, true, 0);
146
}
147
else {
148
self->position.y -= 0x40000;
149
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 3, &self->clawBackAnimator, true, 3);
150
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 2, &self->clawFrontAnimator, true, 3);
151
}
152
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 0, &self->chainAnimator, true, 0);
153
RSDK.SetSpriteAnimation(AIZKingClaw->aniFrames, 1, &self->hingeAnimator, true, 0);
154
155
AIZKingClaw_HandleClawPositions();
156
157
for (int32 i = 0; i < AIZKingClaw_ChainCount; ++i) RSDK.DrawSprite(&self->chainAnimator, &self->chainPos[i], false);
158
159
RSDK.DrawSprite(&self->hingeAnimator, &self->clawPos, false);
160
RSDK.DrawSprite(&self->clawFrontAnimator, &self->clawPos, false);
161
162
RSDK.DrawSprite(&self->clawBackAnimator, &self->clawPos, false);
163
164
self->position.y = y;
165
}
166
167
void AIZKingClaw_EditorLoad(void)
168
{
169
if (RSDK.CheckSceneFolder("AIZ"))
170
AIZKingClaw->aniFrames = RSDK.LoadSpriteAnimation("AIZ/Claw.bin", SCOPE_STAGE);
171
else if (RSDK.CheckSceneFolder("GHZCutscene"))
172
AIZKingClaw->aniFrames = RSDK.LoadSpriteAnimation("GHZCutscene/Claw.bin", SCOPE_STAGE);
173
}
174
#endif
175
176
void AIZKingClaw_Serialize(void) {}
177
178