Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/MSZ/BarStool.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: BarStool Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectBarStool *BarStool;
11
12
void BarStool_Update(void)
13
{
14
RSDK_THIS(BarStool);
15
16
if (self->spinSpeed <= 0) {
17
if (!self->activePlayers)
18
self->spinSpeed -= (self->spinSpeed >> 4);
19
20
if (self->spinSpeed < -0x100000)
21
self->spinSpeed = -0x100000;
22
}
23
else {
24
if (!self->activePlayers)
25
self->spinSpeed -= (self->spinSpeed >> 4);
26
27
if (self->spinSpeed > 0x100000)
28
self->spinSpeed = 0x100000;
29
}
30
31
self->activePlayers = 0;
32
if (abs(self->spinSpeed) > 0x10000 && !(Zone->timer & 0xF))
33
RSDK.PlaySfx(BarStool->sfxSpin, false, 255);
34
35
int32 playerID = 0;
36
foreach_active(Player, player)
37
{
38
int32 velY = player->velocity.y;
39
if (Player_CheckCollisionPlatform(player, self, &BarStool->hitboxStool)) {
40
bool32 canTurntable = true;
41
if (abs(player->velocity.x) <= 0x20000 && player->state != Player_State_Static) {
42
if (abs(self->spinSpeed) <= 0x10000)
43
canTurntable = false;
44
}
45
46
#if MANIA_USE_PLUS
47
canTurntable = canTurntable && player->state != Player_State_MightyHammerDrop;
48
#endif
49
50
if (canTurntable) {
51
RSDK.SetSpriteAnimation(player->aniFrames, ANI_TURNTABLE, &player->animator, false, 0);
52
if (player->state != Player_State_Static) {
53
if (velY >= 0)
54
self->spinSpeed += player->velocity.x;
55
56
self->playerAngle[playerID] = 0;
57
self->playerPos[playerID] = (player->position.x - self->position.x) >> 1;
58
59
player->state = Player_State_Static;
60
player->nextAirState = StateMachine_None;
61
player->nextGroundState = StateMachine_None;
62
}
63
64
player->velocity.x = 0;
65
player->groundVel = 0;
66
67
int32 ang = self->playerAngle[playerID] >> 16;
68
69
player->position.x = CLAMP((self->playerPos[playerID] >> 8) * RSDK.Cos256(ang), -0x100000, 0x100000);
70
ang &= 0xFF;
71
72
int32 frame = (ang / 21) % 12;
73
if (self->spinSpeed <= 0)
74
player->animator.frameID = 11 - frame;
75
else
76
player->animator.frameID = frame;
77
player->animator.speed = 0;
78
79
player->position.x += self->position.x;
80
81
if (self->playerPos[playerID] <= 0)
82
self->playerPos[playerID] -= 0x2000;
83
else
84
self->playerPos[playerID] += 0x2000;
85
86
self->playerAngle[playerID] += self->spinSpeed;
87
88
if (abs(self->playerPos[playerID]) > 0x100000) {
89
int32 speed = self->spinSpeed;
90
91
bool32 shouldFling = true;
92
if (!player->left && !player->right) {
93
if (player->position.x <= self->position.x)
94
speed = -abs(speed);
95
else
96
speed = abs(speed);
97
}
98
else if (player->left) {
99
if (player->position.x < self->position.x)
100
speed = -abs(speed);
101
else
102
shouldFling = false;
103
}
104
else {
105
if (player->position.x > self->position.x)
106
speed = abs(speed);
107
else
108
shouldFling = false;
109
}
110
111
if (shouldFling) {
112
player->velocity.x = speed;
113
player->onGround = false;
114
player->velocity.y = -0x20000;
115
player->state = Player_State_Air;
116
RSDK.SetSpriteAnimation(player->aniFrames, ANI_AIR_WALK, &player->animator, false, 0);
117
RSDK.PlaySfx(BarStool->sfxHop, false, 0xFF);
118
}
119
}
120
121
if (player->jumpPress && player->state == Player_State_Static) {
122
int32 speed = self->spinSpeed;
123
if (player->position.x <= self->position.x)
124
speed = -abs(speed);
125
else
126
speed = -speed;
127
128
player->velocity.x = speed;
129
player->onGround = false;
130
player->velocity.y = -0x40000;
131
player->state = Player_State_Air;
132
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
133
}
134
135
self->activePlayers |= 1 << playerID;
136
}
137
}
138
139
playerID++;
140
}
141
142
self->spinAngle = (self->spinAngle + (self->spinSpeed >> 2)) & 0x7FFFF;
143
self->stoolAnimator.frameID = self->spinAngle >> 16;
144
}
145
146
void BarStool_LateUpdate(void) {}
147
148
void BarStool_StaticUpdate(void) {}
149
150
void BarStool_Draw(void)
151
{
152
RSDK_THIS(BarStool);
153
154
RSDK.DrawSprite(&self->poleAnimator, NULL, false);
155
RSDK.DrawSprite(&self->stoolAnimator, NULL, false);
156
}
157
158
void BarStool_Create(void *data)
159
{
160
RSDK_THIS(BarStool);
161
162
if (!SceneInfo->inEditor) {
163
RSDK.SetSpriteAnimation(BarStool->aniFrames, 0, &self->stoolAnimator, true, 0);
164
RSDK.SetSpriteAnimation(BarStool->aniFrames, 1, &self->poleAnimator, true, self->height);
165
166
self->active = ACTIVE_BOUNDS;
167
self->updateRange.x = 0x800000;
168
self->updateRange.y = 0x800000;
169
self->visible = true;
170
self->drawGroup = Zone->objectDrawGroup[0];
171
}
172
}
173
174
void BarStool_StageLoad(void)
175
{
176
BarStool->aniFrames = RSDK.LoadSpriteAnimation("MSZ/BarStool.bin", SCOPE_STAGE);
177
178
BarStool->hitboxStool.left = -16;
179
BarStool->hitboxStool.top = -24;
180
BarStool->hitboxStool.right = 16;
181
BarStool->hitboxStool.bottom = -16;
182
183
BarStool->sfxSpin = RSDK.GetSfx("MSZ/StoolSpin.wav");
184
BarStool->sfxHop = RSDK.GetSfx("MSZ/StoolHop.wav");
185
}
186
187
#if GAME_INCLUDE_EDITOR
188
void BarStool_EditorDraw(void)
189
{
190
RSDK_THIS(BarStool);
191
192
RSDK.SetSpriteAnimation(BarStool->aniFrames, 0, &self->stoolAnimator, true, 0);
193
RSDK.SetSpriteAnimation(BarStool->aniFrames, 1, &self->poleAnimator, true, self->height);
194
195
RSDK.DrawSprite(&self->poleAnimator, NULL, false);
196
RSDK.DrawSprite(&self->stoolAnimator, NULL, false);
197
}
198
199
void BarStool_EditorLoad(void)
200
{
201
BarStool->aniFrames = RSDK.LoadSpriteAnimation("MSZ/BarStool.bin", SCOPE_STAGE);
202
203
RSDK_ACTIVE_VAR(BarStool, height);
204
RSDK_ENUM_VAR("Short", BARSTOOL_HEIGHT_SHORT);
205
RSDK_ENUM_VAR("Tall", BARSTOOL_HEIGHT_TALL);
206
}
207
#endif
208
209
void BarStool_Serialize(void) { RSDK_EDITABLE_VAR(BarStool, VAR_UINT8, height); }
210
211