Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/MMZ/PlaneSeeSaw.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PlaneSeeSaw Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPlaneSeeSaw *PlaneSeeSaw;
11
12
void PlaneSeeSaw_Update(void)
13
{
14
RSDK_THIS(PlaneSeeSaw);
15
16
StateMachine_Run(self->state);
17
}
18
19
void PlaneSeeSaw_LateUpdate(void) {}
20
21
void PlaneSeeSaw_StaticUpdate(void) {}
22
23
void PlaneSeeSaw_Draw(void)
24
{
25
RSDK_THIS(PlaneSeeSaw);
26
27
Vector2 drawPos;
28
drawPos.x = self->position.x;
29
drawPos.y = self->position.y + self->scale.y * (self->seeSawPos >> 9);
30
self->direction = FLIP_X;
31
RSDK.DrawSprite(&self->swingAnimator, NULL, false);
32
33
self->direction = FLIP_NONE;
34
RSDK.DrawSprite(&self->swingAnimator, NULL, false);
35
RSDK.DrawSprite(&self->weightAnimator, &drawPos, false);
36
RSDK.DrawSprite(&self->platformAnimator, NULL, false);
37
}
38
39
void PlaneSeeSaw_Create(void *data)
40
{
41
RSDK_THIS(PlaneSeeSaw);
42
self->drawFX = FX_FLIP;
43
44
if (!SceneInfo->inEditor) {
45
self->visible = true;
46
self->drawGroup = Zone->objectDrawGroup[0];
47
self->active = ACTIVE_BOUNDS;
48
self->updateRange.x = 0x800000;
49
self->updateRange.y = 0x800000;
50
self->scale.x = 0x200;
51
self->scale.y = 0x200;
52
self->state = PlaneSeeSaw_State_WaitForPlayer;
53
RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 0, &self->swingAnimator, true, 0);
54
RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 1, &self->platformAnimator, true, 0);
55
RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 2, &self->weightAnimator, true, 0);
56
}
57
}
58
59
void PlaneSeeSaw_StageLoad(void)
60
{
61
PlaneSeeSaw->aniFrames = RSDK.LoadSpriteAnimation("MMZ/SeeSaw.bin", SCOPE_STAGE);
62
63
PlaneSeeSaw->sfxSpring = RSDK.GetSfx("Global/Spring.wav");
64
PlaneSeeSaw->sfxFlipper = RSDK.GetSfx("Stage/Flipper.wav");
65
}
66
67
void PlaneSeeSaw_State_WaitForPlayer(void)
68
{
69
RSDK_THIS(PlaneSeeSaw);
70
71
Hitbox *hitbox = RSDK.GetHitbox(&self->platformAnimator, 0);
72
foreach_active(Player, player)
73
{
74
if (Player_CheckCollisionPlatform(player, self, hitbox)) {
75
#if MANIA_USE_PLUS
76
if (player->state == Player_State_MightyHammerDrop)
77
player->state = Player_State_Air;
78
#endif
79
self->state = PlaneSeeSaw_State_PlayerPushDown;
80
}
81
}
82
}
83
84
void PlaneSeeSaw_State_PlayerPushDown(void)
85
{
86
RSDK_THIS(PlaneSeeSaw);
87
88
Hitbox *hitboxOld = RSDK.GetHitbox(&self->platformAnimator, 0);
89
if (self->platformAnimator.frameID >= self->platformAnimator.frameCount - 1) {
90
self->velocity.y += 0x3800;
91
self->seeSawPos += self->velocity.y;
92
}
93
else {
94
++self->swingAnimator.frameID;
95
++self->platformAnimator.frameID;
96
97
if (self->platformAnimator.frameID == self->platformAnimator.frameCount - 1) {
98
self->velocity.y = -0x60000;
99
RSDK.PlaySfx(PlaneSeeSaw->sfxFlipper, false, 255);
100
}
101
102
self->seeSawPos = RSDK.GetHitbox(&self->swingAnimator, 0)->top << 16;
103
}
104
105
Hitbox *hitboxNew = RSDK.GetHitbox(&self->platformAnimator, 0);
106
foreach_active(Player, player)
107
{
108
if (Player_CheckCollisionPlatform(player, self, hitboxOld))
109
player->position.y += (hitboxNew->bottom - hitboxOld->bottom) << 16;
110
}
111
112
if (self->seeSawPos > -0x230000 && self->velocity.y > 0) {
113
self->velocity.y = 0;
114
self->seeSawPos = -0x230000;
115
self->state = PlaneSeeSaw_State_Launch;
116
RSDK.PlaySfx(PlaneSeeSaw->sfxSpring, false, 255);
117
}
118
}
119
120
void PlaneSeeSaw_State_Launch(void)
121
{
122
RSDK_THIS(PlaneSeeSaw);
123
124
Hitbox *hitboxOld = RSDK.GetHitbox(&self->platformAnimator, 0);
125
if (self->platformAnimator.frameID <= 0) {
126
self->state = PlaneSeeSaw_State_WaitForPlayer;
127
}
128
else {
129
--self->swingAnimator.frameID;
130
--self->platformAnimator.frameID;
131
132
self->seeSawPos = RSDK.GetHitbox(&self->swingAnimator, 0)->top << 16;
133
}
134
135
Hitbox *hitboxNew = RSDK.GetHitbox(&self->platformAnimator, 0);
136
foreach_active(Player, player)
137
{
138
if (Player_CheckCollisionPlatform(player, self, hitboxOld)) {
139
player->position.y += (hitboxNew->bottom - hitboxOld->bottom) << 16;
140
141
if (self->platformAnimator.frameID < 4) {
142
if (self->scale.x == 0x100) {
143
player->position.x -= FarPlane->originPos.x;
144
player->position.y -= FarPlane->originPos.y;
145
player->position.x += FarPlane->position.x;
146
player->position.y += FarPlane->position.y;
147
148
if (player->camera) {
149
player->camera->targetMoveVel.x = 0;
150
player->camera->targetMoveVel.y = 0;
151
}
152
153
player->groundVel = 0;
154
player->velocity.x = 0;
155
player->drawGroup = Zone->playerDrawGroup[0];
156
player->state = PlaneSeeSaw_PlayerState_ToFG;
157
player->velocity.y = -0x60000;
158
}
159
else {
160
player->groundVel = 0;
161
player->velocity.x = 0;
162
player->scale.x = 0x200;
163
player->scale.y = 0x200;
164
player->state = PlaneSeeSaw_PlayerState_ToBG;
165
player->velocity.y = -0xA0000;
166
}
167
168
player->abilityValues[0] = self->position.x;
169
player->nextAirState = StateMachine_None;
170
player->nextGroundState = StateMachine_None;
171
player->interaction = false;
172
player->tileCollisions = TILECOLLISION_NONE;
173
player->jumpAbilityState = 0;
174
player->drawFX |= FX_SCALE;
175
player->applyJumpCap = false;
176
player->onGround = false;
177
178
EntityShield *shield = RSDK_GET_ENTITY(Player->playerCount + RSDK.GetEntitySlot(player), Shield);
179
if (shield && shield->classID)
180
shield->drawFX |= FX_SCALE;
181
182
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
183
player->animator.speed = 0x80;
184
}
185
}
186
}
187
}
188
189
void PlaneSeeSaw_PlayerState_ToBG(void)
190
{
191
EntityPlayer *self = RSDK_GET_ENTITY(SceneInfo->entitySlot, Player);
192
193
self->left = false;
194
self->right = false;
195
196
if ((self->abilityValues[0] ^ self->position.x) & 0xFFFF0000) {
197
self->position.x += self->position.x <= self->abilityValues[0] ? 0x8000 : -0x8000;
198
}
199
200
ControllerInfo[self->controllerID].keyY.press = false;
201
Player_State_Air();
202
203
self->tileCollisions = TILECOLLISION_NONE;
204
if (self->scale.x <= 0x100) {
205
self->interaction = true;
206
self->tileCollisions = TILECOLLISION_DOWN;
207
self->drawGroup = 2;
208
209
self->position.x -= FarPlane->position.x;
210
self->position.y -= FarPlane->position.y;
211
self->position.x += FarPlane->originPos.x;
212
self->position.y += FarPlane->originPos.y;
213
Zone->deathBoundary[0] += 0x8000000;
214
215
self->state = Player_State_Air;
216
if (self->camera) {
217
self->camera->targetMoveVel.x = FarPlane->position.x - FarPlane->originPos.x;
218
self->camera->targetMoveVel.y = FarPlane->position.y - FarPlane->originPos.y;
219
}
220
221
self->scale.y = self->scale.x;
222
}
223
else {
224
self->scale.x -= 4;
225
self->scale.y = self->scale.x;
226
}
227
}
228
229
void PlaneSeeSaw_PlayerState_ToFG(void)
230
{
231
// ???
232
EntityPlayer *self = RSDK_GET_ENTITY(SceneInfo->entitySlot, Player);
233
234
self->left = false;
235
self->right = false;
236
if (((self->abilityValues[0] ^ self->position.x) & 0xFFFF0000)) {
237
self->position.x += self->position.x <= self->abilityValues[0] ? 0x8000 : -0x8000;
238
}
239
240
ControllerInfo[self->controllerID].keyY.press = false;
241
Player_State_Air();
242
243
self->tileCollisions = TILECOLLISION_NONE;
244
if (self->scale.x >= 0x200) {
245
self->interaction = true;
246
self->tileCollisions = TILECOLLISION_DOWN;
247
Zone->deathBoundary[0] -= 0x8000000;
248
249
self->drawFX &= ~FX_SCALE;
250
self->state = Player_State_Air;
251
252
EntityShield *shield = RSDK_GET_ENTITY(Player->playerCount + RSDK.GetEntitySlot(self), Shield);
253
if (shield && shield->classID)
254
shield->drawFX &= ~FX_SCALE;
255
256
self->scale.y = self->scale.x;
257
}
258
else {
259
self->scale.x += 4;
260
self->scale.y = self->scale.x;
261
}
262
}
263
264
#if GAME_INCLUDE_EDITOR
265
void PlaneSeeSaw_EditorDraw(void)
266
{
267
RSDK_THIS(PlaneSeeSaw);
268
269
RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 0, &self->swingAnimator, false, 0);
270
RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 1, &self->platformAnimator, false, 0);
271
RSDK.SetSpriteAnimation(PlaneSeeSaw->aniFrames, 2, &self->weightAnimator, false, 0);
272
273
PlaneSeeSaw_Draw();
274
}
275
276
void PlaneSeeSaw_EditorLoad(void) { PlaneSeeSaw->aniFrames = RSDK.LoadSpriteAnimation("MMZ/SeeSaw.bin", SCOPE_STAGE); }
277
#endif
278
279
void PlaneSeeSaw_Serialize(void) {}
280
281