Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/OOZ/PullSwitch.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: PullSwitch Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectPullSwitch *PullSwitch;
11
12
void PullSwitch_Update(void)
13
{
14
RSDK_THIS(PullSwitch);
15
16
if (!self->activated) {
17
if (self->pullPos > 0) {
18
self->position.y -= 0x20000;
19
self->pullPos -= 0x20000;
20
}
21
}
22
else if (self->pullPos < 0x300000) {
23
self->position.y += 0x20000;
24
self->pullPos += 0x20000;
25
}
26
else {
27
if (OOZSetup->smogTimer > 16 || Smog->forceEnabled)
28
RSDK.PlaySfx(PullSwitch->sfxSmogClear, false, 0xFF);
29
30
OOZSetup->smogTimer = 0;
31
Smog->forceEnabled = false;
32
}
33
34
self->activated = false;
35
foreach_active(Player, player)
36
{
37
int32 playerID = RSDK.GetEntitySlot(player);
38
Hitbox *playerHitbox = Player_GetHitbox(player);
39
40
if (self->playerTimers[playerID]) {
41
self->playerTimers[playerID]--;
42
}
43
else if (((1 << playerID) & self->activePlayers)) {
44
player->position.x = self->position.x;
45
player->position.y = self->position.y - (playerHitbox->top << 16) + 0x1A0000;
46
self->activated = true;
47
48
if (player->state == Player_State_Static) {
49
if (player->jumpPress) {
50
self->activePlayers &= ~(1 << playerID);
51
self->playerTimers[playerID] = 60;
52
player->velocity.y = -0x40000;
53
player->onGround = false;
54
player->groundedStore = false;
55
player->jumpAbilityState = 1;
56
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
57
player->animator.speed = 48;
58
player->state = Player_State_Air;
59
}
60
}
61
else {
62
self->activePlayers &= ~(1 << playerID);
63
self->playerTimers[playerID] = 60;
64
}
65
}
66
else {
67
if (Player_CheckCollisionTouch(player, self, &PullSwitch->hitbox) && player->velocity.y >= 0) {
68
self->activePlayers |= 1 << playerID;
69
player->state = Player_State_Static;
70
player->nextGroundState = StateMachine_None;
71
player->nextAirState = StateMachine_None;
72
RSDK.SetSpriteAnimation(player->aniFrames, ANI_HANG, &player->animator, false, 0);
73
74
player->velocity.x = 0;
75
player->velocity.y = 0;
76
player->groundVel = 0;
77
player->controlLock = 0;
78
player->position.x = self->position.x;
79
player->position.y = self->position.y - (playerHitbox->top << 16) + 0x1A0000;
80
self->activated = true;
81
}
82
}
83
}
84
}
85
86
void PullSwitch_LateUpdate(void) {}
87
88
void PullSwitch_StaticUpdate(void) {}
89
90
void PullSwitch_Draw(void)
91
{
92
RSDK_THIS(PullSwitch);
93
94
SpriteFrame *frame = RSDK.GetFrame(PullSwitch->aniFrames, 0, 1);
95
96
frame->height = (self->position.y - self->handlePos.y) >> 16;
97
frame->sprY = self->sprY + self->sprHeight - frame->height;
98
RSDK.DrawSprite(&self->chainAnimator, &self->handlePos, false);
99
RSDK.DrawSprite(&self->handleAnimator, NULL, false);
100
RSDK.DrawSprite(&self->dispenserAnimator, &self->handlePos, false);
101
}
102
103
void PullSwitch_Create(void *data)
104
{
105
RSDK_THIS(PullSwitch);
106
107
self->drawFX = FX_FLIP;
108
if (!SceneInfo->inEditor) {
109
self->active = ACTIVE_BOUNDS;
110
self->visible = true;
111
self->drawFX = FX_FLIP;
112
self->drawGroup = Zone->objectDrawGroup[0];
113
self->handlePos = self->position;
114
self->updateRange.x = 0x800000;
115
self->updateRange.y = 0x800000;
116
117
RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->handleAnimator, true, 2);
118
RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->dispenserAnimator, true, 0);
119
RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->chainAnimator, true, 1);
120
121
SpriteFrame *frame = RSDK.GetFrame(PullSwitch->aniFrames, 0, 1);
122
self->sprY = frame->sprY;
123
self->sprHeight = frame->height;
124
}
125
}
126
127
void PullSwitch_StageLoad(void)
128
{
129
if (RSDK.CheckSceneFolder("OOZ1") || RSDK.CheckSceneFolder("OOZ2"))
130
PullSwitch->aniFrames = RSDK.LoadSpriteAnimation("OOZ/PullSwitch.bin", SCOPE_STAGE);
131
132
PullSwitch->hitbox.left = -16;
133
PullSwitch->hitbox.top = 20;
134
PullSwitch->hitbox.right = 16;
135
PullSwitch->hitbox.bottom = 28;
136
137
PullSwitch->sfxButton = RSDK.GetSfx("Stage/Button.wav");
138
PullSwitch->sfxSmogClear = RSDK.GetSfx("OOZ/SmogClear.wav");
139
}
140
141
#if GAME_INCLUDE_EDITOR
142
void PullSwitch_EditorDraw(void)
143
{
144
RSDK_THIS(PullSwitch);
145
146
self->handlePos = self->position;
147
148
RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->handleAnimator, false, 2);
149
RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->dispenserAnimator, false, 0);
150
RSDK.SetSpriteAnimation(PullSwitch->aniFrames, 0, &self->chainAnimator, false, 1);
151
152
RSDK.DrawSprite(&self->chainAnimator, &self->handlePos, false);
153
RSDK.DrawSprite(&self->dispenserAnimator, &self->handlePos, false);
154
155
self->handlePos.y += 0x300000;
156
RSDK.DrawSprite(&self->handleAnimator, &self->handlePos, false);
157
}
158
159
void PullSwitch_EditorLoad(void) { PullSwitch->aniFrames = RSDK.LoadSpriteAnimation("OOZ/PullSwitch.bin", SCOPE_STAGE); }
160
#endif
161
162
void PullSwitch_Serialize(void) {}
163
164