Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/SSZ/JunctionWheel.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: JunctionWheel Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectJunctionWheel *JunctionWheel;
11
12
void JunctionWheel_Update(void)
13
{
14
RSDK_THIS(JunctionWheel);
15
16
if (RSDK_GET_ENTITY((SceneInfo->entitySlot - 1), Button)->currentlyActive)
17
self->spinDir ^= 1;
18
19
if (self->spinDir)
20
self->rotation += 4;
21
else
22
self->rotation -= 4;
23
24
self->rotation &= 0x1FF;
25
26
int32 direction = ((self->rotation + 48) >> 6) & 7;
27
28
foreach_active(Player, player)
29
{
30
if (player->state == Player_State_Static) {
31
if (Player_CheckCollisionTouch(player, self, &JunctionWheel->hitboxWheelRange)) {
32
player->position.x = player->groundVel * RSDK.Cos512(self->rotation) + self->position.x;
33
player->position.y = player->groundVel * RSDK.Sin512(self->rotation) + self->position.y;
34
35
if (player->groundVel < -0x1000)
36
player->groundVel += 0x200;
37
38
if (player->groundVel == -0x1000) {
39
if (self->rotation == 0x180) {
40
player->state = Player_State_Air;
41
player->tileCollisions = TILECOLLISION_DOWN;
42
player->groundVel = 0;
43
player->velocity.x = 0;
44
player->velocity.y = 0x80000;
45
player->onGround = false;
46
RSDK.PlaySfx(Player->sfxRelease, false, 255);
47
}
48
49
if (self->spinDir == 1 && self->rotation == 0x11C) {
50
player->state = Player_State_Air;
51
player->tileCollisions = TILECOLLISION_DOWN;
52
player->groundVel = 0x80000;
53
player->velocity.x = 0x80000;
54
player->velocity.y = 0x40000;
55
player->onGround = false;
56
RSDK.PlaySfx(Player->sfxRelease, false, 255);
57
}
58
}
59
}
60
}
61
else {
62
switch (direction) {
63
case 1:
64
Player_CheckCollisionBox(player, self, &JunctionWheel->hitboxSolidR);
65
66
if (Player_CheckCollisionTouch(player, self, &JunctionWheel->hitboxEntryR)) {
67
player->state = Player_State_Static;
68
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
69
player->onGround = false;
70
player->groundVel = -0x1C00;
71
72
player->tileCollisions = TILECOLLISION_NONE;
73
player->nextAirState = StateMachine_None;
74
player->nextGroundState = StateMachine_None;
75
player->velocity.x = 0;
76
player->velocity.y = 0;
77
RSDK.PlaySfx(Player->sfxRoll, false, 255);
78
}
79
break;
80
81
case 0:
82
case 2:
83
case 3:
84
case 4:
85
case 6:
86
case 7:
87
if (player->position.y < self->position.y)
88
Player_CheckCollisionBox(player, self, &JunctionWheel->hitboxSolidL);
89
90
Player_CheckCollisionBox(player, self, &JunctionWheel->hitboxSolidR);
91
break;
92
93
case 5:
94
if (player->velocity.x <= 0) {
95
Player_CheckCollisionBox(player, self, &JunctionWheel->hitboxSolidL);
96
97
if (Player_CheckCollisionTouch(player, self, &JunctionWheel->hitboxEntryL)) {
98
player->state = Player_State_Static;
99
RSDK.SetSpriteAnimation(player->aniFrames, ANI_JUMP, &player->animator, false, 0);
100
101
player->onGround = false;
102
player->groundVel = -0x1800;
103
104
player->tileCollisions = TILECOLLISION_NONE;
105
player->nextAirState = StateMachine_None;
106
player->nextGroundState = StateMachine_None;
107
player->velocity.x = 0;
108
player->velocity.y = 0;
109
RSDK.PlaySfx(Player->sfxRoll, false, 255);
110
}
111
}
112
break;
113
}
114
115
if (player->velocity.y < 0 || (player->onGround && player->collisionMode))
116
Player_CheckCollisionBox(player, self, &JunctionWheel->hitboxSolidB);
117
}
118
}
119
}
120
121
void JunctionWheel_LateUpdate(void) {}
122
123
void JunctionWheel_StaticUpdate(void) {}
124
125
void JunctionWheel_Draw(void)
126
{
127
RSDK_THIS(JunctionWheel);
128
129
RSDK.DrawSprite(&self->slotAnimator, NULL, false);
130
RSDK.DrawSprite(&self->maskAnimator, NULL, false);
131
}
132
133
void JunctionWheel_Create(void *data)
134
{
135
RSDK_THIS(JunctionWheel);
136
self->visible = true;
137
self->drawGroup = Zone->objectDrawGroup[0];
138
self->active = ACTIVE_BOUNDS;
139
self->updateRange.x = 0x800000;
140
self->updateRange.y = 0x800000;
141
self->drawFX = FX_ROTATE;
142
143
RSDK.SetSpriteAnimation(JunctionWheel->aniFrames, 0, &self->slotAnimator, true, 0);
144
RSDK.SetSpriteAnimation(JunctionWheel->aniFrames, 1, &self->maskAnimator, true, 0);
145
}
146
147
void JunctionWheel_StageLoad(void)
148
{
149
if (RSDK.CheckSceneFolder("SSZ1"))
150
JunctionWheel->aniFrames = RSDK.LoadSpriteAnimation("SSZ1/JunctionWheel.bin", SCOPE_STAGE);
151
152
JunctionWheel->hitboxWheelRange.left = -192;
153
JunctionWheel->hitboxWheelRange.top = -192;
154
JunctionWheel->hitboxWheelRange.right = 192;
155
JunctionWheel->hitboxWheelRange.bottom = 192;
156
157
JunctionWheel->hitboxSolidL.left = -40;
158
JunctionWheel->hitboxSolidL.top = -56;
159
JunctionWheel->hitboxSolidL.right = -16;
160
JunctionWheel->hitboxSolidL.bottom = 32;
161
162
JunctionWheel->hitboxSolidR.left = 16;
163
JunctionWheel->hitboxSolidR.top = -56;
164
JunctionWheel->hitboxSolidR.right = 40;
165
JunctionWheel->hitboxSolidR.bottom = 32;
166
167
JunctionWheel->hitboxSolidB.left = -40;
168
JunctionWheel->hitboxSolidB.top = 32;
169
JunctionWheel->hitboxSolidB.right = 40;
170
JunctionWheel->hitboxSolidB.bottom = 56;
171
172
JunctionWheel->hitboxEntryR.left = -40;
173
JunctionWheel->hitboxEntryR.top = -40;
174
JunctionWheel->hitboxEntryR.right = -16;
175
JunctionWheel->hitboxEntryR.bottom = -8;
176
177
JunctionWheel->hitboxEntryL.left = 16;
178
JunctionWheel->hitboxEntryL.top = 8;
179
JunctionWheel->hitboxEntryL.right = 38;
180
JunctionWheel->hitboxEntryL.bottom = 40;
181
}
182
183
#if GAME_INCLUDE_EDITOR
184
void JunctionWheel_EditorDraw(void)
185
{
186
RSDK_THIS(JunctionWheel);
187
188
JunctionWheel_Draw();
189
190
if (showGizmos()) {
191
RSDK_DRAWING_OVERLAY(true);
192
193
// May also be something like a SSZ/SDashWheel since Common/Button doesn't exist in SSZ1 object list
194
EntityButton *button = RSDK_GET_ENTITY(SceneInfo->entitySlot - 1, Button);
195
196
if (button) {
197
DrawHelpers_DrawArrow(button->position.x, button->position.y, self->position.x, self->position.y, 0xFFFF00, INK_NONE, 0xFF);
198
}
199
200
RSDK_DRAWING_OVERLAY(false);
201
}
202
}
203
204
void JunctionWheel_EditorLoad(void) { JunctionWheel->aniFrames = RSDK.LoadSpriteAnimation("SSZ1/JunctionWheel.bin", SCOPE_STAGE); }
205
#endif
206
207
void JunctionWheel_Serialize(void) {}
208
209