Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/LRZ/DashLift.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: DashLift Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectDashLift *DashLift;
11
12
void DashLift_Update(void) { Platform_Update(); }
13
14
void DashLift_LateUpdate(void) {}
15
16
void DashLift_StaticUpdate(void) {}
17
18
void DashLift_Draw(void)
19
{
20
RSDK_THIS(DashLift);
21
22
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
23
}
24
25
void DashLift_Create(void *data)
26
{
27
RSDK_THIS(DashLift);
28
29
self->collision = PLATFORM_C_SOLID;
30
Platform_Create(NULL);
31
32
if (!SceneInfo->inEditor) {
33
self->drawGroup = Zone->playerDrawGroup[1];
34
RSDK.SetSpriteAnimation(Platform->aniFrames, 2, &self->animator, true, 4);
35
36
self->drawPos.y += self->startOff << 15;
37
self->updateRange.y = self->length << 15;
38
39
self->amplitude.x = self->position.y - (self->length << 15);
40
self->amplitude.y = self->position.y + (self->length << 15);
41
42
self->updateRange.x = 0x800000;
43
self->state = DashLift_State_Init;
44
}
45
}
46
47
void DashLift_StageLoad(void) { DashLift->sfxPulley = RSDK.GetSfx("Stage/Pulley.wav"); }
48
49
void DashLift_CheckOffScreen(void)
50
{
51
RSDK_THIS(DashLift);
52
53
if (!RSDK.CheckPosOnScreen(&self->drawPos, &self->updateRange) && !RSDK.CheckPosOnScreen(&self->centerPos, &self->updateRange)) {
54
self->drawPos = self->centerPos;
55
self->position = self->centerPos;
56
self->activePlayers = 0;
57
self->active = ACTIVE_BOUNDS;
58
DashLift_Create(NULL);
59
}
60
}
61
62
void DashLift_State_Init(void)
63
{
64
RSDK_THIS(DashLift);
65
66
self->active = ACTIVE_NORMAL;
67
self->state = DashLift_State_HandleDash;
68
}
69
70
void DashLift_State_HandleDash(void)
71
{
72
RSDK_THIS(DashLift);
73
74
int32 totalSpeed = 0;
75
foreach_active(Player, player)
76
{
77
int32 playerID = RSDK.GetEntitySlot(player);
78
79
if (!((1 << playerID) & self->stoodPlayers)) {
80
if (((1 << playerID) & self->activePlayers)) {
81
player->position.x = self->position.x;
82
self->activePlayers &= ~(1 << playerID);
83
if (player->animator.animationID == ANI_JUMP)
84
player->velocity.x = 0;
85
}
86
}
87
else {
88
int32 anim = player->animator.animationID;
89
if (anim == ANI_SPINDASH || (anim == ANI_JUMP && ((1 << playerID) & self->activePlayers))) {
90
self->activePlayers |= (1 << playerID);
91
92
foreach_active(Dust, dust)
93
{
94
if (dust->parent == (Entity *)player)
95
destroyEntity(dust);
96
}
97
98
player->velocity.x -= player->velocity.x >> 5;
99
player->position.x = self->position.x;
100
if (player->direction == FLIP_X) {
101
if ((player->sidekick && totalSpeed < 0) || self->drawPos.y >= self->amplitude.y)
102
continue;
103
104
int32 speed = 0;
105
if (player->state == Player_State_Spindash) {
106
if (player->superState == SUPERSTATE_SUPER)
107
speed = ((player->abilityTimer >> 1) & 0x7FFF8000) + 0xB0000;
108
else
109
speed = ((player->abilityTimer >> 1) & 0x7FFF8000) + 0x80000;
110
}
111
else {
112
speed = -player->groundVel;
113
}
114
115
speed -= 0x40000;
116
if (speed < 0) {
117
speed = 0;
118
player->groundVel = 0;
119
player->velocity.x = 0;
120
}
121
122
self->drawPos.y += speed >> 2;
123
totalSpeed += speed >> 2;
124
self->animator.timer += abs((speed >> 2) >> 16);
125
126
if (self->animator.timer >= 4) {
127
self->animator.timer = 0;
128
if (++self->animator.frameID > 4)
129
self->animator.frameID = 0;
130
}
131
132
if (!(Zone->timer & 0xF))
133
RSDK.PlaySfx(DashLift->sfxPulley, false, 255);
134
}
135
else {
136
if ((player->sidekick && totalSpeed > 0) || self->drawPos.y <= self->amplitude.x)
137
continue;
138
139
int32 speed = 0;
140
if (player->state == Player_State_Spindash) {
141
if (player->superState == SUPERSTATE_SUPER)
142
speed = -((player->abilityTimer >> 1) & 0x7FFF8000) - 0xB0000;
143
else
144
speed = -((player->abilityTimer >> 1) & 0x7FFF8000) - 0x80000;
145
}
146
else {
147
speed = -player->groundVel;
148
}
149
150
speed += 0x40000;
151
if (speed > 0) {
152
speed = 0;
153
player->groundVel = 0;
154
player->velocity.x = 0;
155
}
156
157
self->drawPos.y += speed >> 2;
158
totalSpeed += speed >> 2;
159
self->animator.timer -= abs((speed >> 2) >> 16);
160
161
if (self->animator.timer <= 0) {
162
self->animator.timer = 3;
163
if (--self->animator.frameID < 0)
164
self->animator.frameID = 4;
165
}
166
167
if (!(Zone->timer & 0xF))
168
RSDK.PlaySfx(DashLift->sfxPulley, false, 255);
169
}
170
}
171
else {
172
self->activePlayers &= ~(1 << playerID);
173
}
174
}
175
}
176
177
DashLift_CheckOffScreen();
178
}
179
180
#if GAME_INCLUDE_EDITOR
181
void DashLift_EditorDraw(void)
182
{
183
RSDK_THIS(DashLift);
184
185
self->drawPos = self->position;
186
RSDK.SetSpriteAnimation(Platform->aniFrames, 2, &self->animator, true, 4);
187
188
DashLift_Draw();
189
190
if (showGizmos()) {
191
RSDK_DRAWING_OVERLAY(true);
192
self->drawPos.y += self->startOff << 15;
193
self->updateRange.y = self->length << 15;
194
195
self->amplitude.x = self->position.y - (self->length << 15);
196
self->amplitude.y = self->position.y + (self->length << 15);
197
198
self->inkEffect = INK_BLEND;
199
200
// Offset Preview
201
DashLift_Draw();
202
203
self->drawPos = self->position;
204
self->drawPos.y += self->length << 15;
205
206
// Length Preview
207
DashLift_Draw();
208
209
DrawHelpers_DrawArrow(self->position.x, self->position.y, self->drawPos.x, self->drawPos.y, 0x00FF00, INK_NONE, 0xFF);
210
211
self->inkEffect = INK_NONE;
212
213
for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {
214
Entity *child = RSDK_GET_ENTITY_GEN(s + i);
215
if (!child)
216
continue;
217
218
DrawHelpers_DrawArrow(self->position.x, self->position.y, child->position.x, child->position.y, 0xE0E0E0, INK_NONE, 0xFF);
219
}
220
221
RSDK_DRAWING_OVERLAY(false);
222
}
223
}
224
225
void DashLift_EditorLoad(void) {}
226
#endif
227
228
void DashLift_Serialize(void)
229
{
230
RSDK_EDITABLE_VAR(DashLift, VAR_ENUM, length);
231
RSDK_EDITABLE_VAR(DashLift, VAR_ENUM, childCount);
232
RSDK_EDITABLE_VAR(DashLift, VAR_ENUM, startOff);
233
}
234
235