Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/CPZ/RotatingStair.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: RotatingStair Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectRotatingStair *RotatingStair;
11
12
void RotatingStair_Update(void) { Platform_Update(); }
13
14
void RotatingStair_LateUpdate(void) {}
15
16
void RotatingStair_StaticUpdate(void) {}
17
18
void RotatingStair_Draw(void)
19
{
20
RSDK_THIS(RotatingStair);
21
22
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
23
}
24
25
void RotatingStair_Create(void *data)
26
{
27
RSDK_THIS(RotatingStair);
28
29
self->frameID = 2;
30
self->collision = PLATFORM_C_SOLID;
31
self->speed = 3;
32
33
if (self->direction)
34
self->amplitude.x = -self->amplitude.x;
35
36
if (self->mode & 1)
37
self->amplitude.x = -self->amplitude.x;
38
39
int32 typeStore = self->mode;
40
self->mode = (RotatingStairModes)PLATFORM_LINEAR;
41
Platform_Create(NULL);
42
self->mode = typeStore;
43
44
if (self->mode >= 4) {
45
self->duration = 120 * self->speed;
46
self->state = RotatingStair_State_Move_Intervals;
47
self->interval = self->duration + 512;
48
}
49
else {
50
self->state = RotatingStair_State_Move;
51
}
52
}
53
54
void RotatingStair_StageLoad(void) { RotatingStair->unused = 0; }
55
56
void RotatingStair_State_Move(void)
57
{
58
RSDK_THIS(RotatingStair);
59
60
int32 timer = Zone->timer + self->oscOff;
61
int32 drawX = -self->drawPos.x;
62
int32 drawY = -self->drawPos.y;
63
64
int32 dir = 0;
65
if (self->mode & 1)
66
dir = self->mode - (((3 * timer) >> 9) & 3) - 2;
67
else
68
dir = ((3 * timer) >> 9) + self->mode;
69
70
switch (dir & 3) {
71
case FLIP_NONE: // right
72
self->drawPos.x = self->centerPos.x + self->amplitude.x * RSDK.Cos1024(timer * self->speed);
73
self->drawPos.y = self->centerPos.y + (self->amplitude.y << 10);
74
break;
75
76
case FLIP_X: // up
77
self->drawPos.x = self->centerPos.x - (self->amplitude.x << 10);
78
self->drawPos.y = self->centerPos.y - self->amplitude.y * RSDK.Cos1024(timer * self->speed);
79
break;
80
81
case FLIP_Y: // left
82
self->drawPos.x = self->centerPos.x - self->amplitude.x * RSDK.Cos1024(timer * self->speed);
83
self->drawPos.y = self->centerPos.y - (self->amplitude.y << 10);
84
break;
85
86
case FLIP_XY: // down
87
self->drawPos.x = self->centerPos.x + (self->amplitude.x << 10);
88
self->drawPos.y = self->centerPos.y + self->amplitude.y * RSDK.Cos1024(timer * self->speed);
89
break;
90
}
91
92
self->velocity.x = drawX + self->drawPos.x;
93
self->velocity.y = drawY + self->drawPos.y;
94
}
95
96
void RotatingStair_State_Move_Intervals(void)
97
{
98
RSDK_THIS(RotatingStair);
99
100
int32 drawX = -self->drawPos.x;
101
int32 drawY = -self->drawPos.y;
102
103
int32 angle = 0;
104
if (self->speed * (Zone->timer + self->oscOff) % self->interval >= self->duration)
105
angle = self->speed * (Zone->timer + self->oscOff) % self->interval - self->duration;
106
107
int32 dir = 0;
108
if (self->mode & 1)
109
dir = self->mode - ((self->speed * (Zone->timer + self->oscOff) / self->interval) & 3) - 2;
110
else
111
dir = self->speed * (Zone->timer + self->oscOff) / self->interval + self->mode;
112
113
switch (dir & 3) {
114
case FLIP_NONE: // right
115
self->drawPos.x = self->centerPos.x + self->amplitude.x * RSDK.Cos1024(angle);
116
self->drawPos.y = self->centerPos.y + (self->amplitude.y << 10);
117
break;
118
119
case FLIP_X: // up
120
self->drawPos.x = self->centerPos.x - (self->amplitude.x << 10);
121
self->drawPos.y = self->centerPos.y - self->amplitude.y * RSDK.Cos1024(angle + 0x200);
122
break;
123
124
case FLIP_Y: // left
125
self->drawPos.x = self->centerPos.x - self->amplitude.x * RSDK.Cos1024(angle);
126
self->drawPos.y = self->centerPos.y - (self->amplitude.y << 10);
127
break;
128
129
case FLIP_XY: // down
130
self->drawPos.x = self->centerPos.x + (self->amplitude.x << 10);
131
self->drawPos.y = self->centerPos.y + self->amplitude.y * RSDK.Cos1024(angle + 0x200);
132
break;
133
}
134
135
self->velocity.x = drawX + self->drawPos.x;
136
self->velocity.y = drawY + self->drawPos.y;
137
}
138
139
#if GAME_INCLUDE_EDITOR
140
void RotatingStair_EditorDraw(void)
141
{
142
RSDK_THIS(RotatingStair);
143
144
self->frameID = 2;
145
self->collision = PLATFORM_C_SOLID;
146
self->speed = 3;
147
if (self->direction)
148
self->amplitude.x = -self->amplitude.x;
149
if (self->mode & 1)
150
self->amplitude.x = -self->amplitude.x;
151
152
int32 typeStore = self->mode;
153
self->mode = (RotatingStairModes)PLATFORM_LINEAR;
154
Platform_Create(NULL);
155
self->mode = typeStore;
156
157
// self->drawPos = self->position;
158
159
Vector2 amplitude = self->amplitude;
160
161
if (self->direction)
162
self->amplitude.x = -self->amplitude.x;
163
if (self->mode & 1)
164
self->amplitude.x = -self->amplitude.x;
165
166
if (self->mode >= 4) {
167
self->duration = 120 * self->speed;
168
self->interval = self->duration + 512;
169
RotatingStair_State_Move_Intervals();
170
}
171
else {
172
RotatingStair_State_Move();
173
}
174
175
RotatingStair_Draw();
176
177
if (showGizmos()) {
178
RSDK_DRAWING_OVERLAY(true);
179
180
for (int32 s = SceneInfo->entitySlot + 1, i = 0; i < self->childCount; ++i) {
181
Entity *child = RSDK_GET_ENTITY_GEN(s + i);
182
if (!child)
183
continue;
184
185
DrawHelpers_DrawArrow(self->drawPos.x, self->drawPos.y, child->position.x, child->position.y, 0xFFFF00, INK_NONE, 0xFF);
186
}
187
188
RSDK_DRAWING_OVERLAY(false);
189
}
190
191
self->amplitude = amplitude;
192
}
193
194
void RotatingStair_EditorLoad(void)
195
{
196
197
RSDK_ACTIVE_VAR(RotatingStair, mode);
198
RSDK_ENUM_VAR("Start Left", ROTATINGSTAIR_LEFT);
199
RSDK_ENUM_VAR("Start Down", ROTATINGSTAIR_DOWN);
200
RSDK_ENUM_VAR("Start Right", ROTATINGSTAIR_RIGHT);
201
RSDK_ENUM_VAR("Start Up", ROTATINGSTAIR_UP);
202
RSDK_ENUM_VAR("Start Left (Use Intervals)", ROTATINGSTAIR_LEFT_INTERVAL);
203
RSDK_ENUM_VAR("Start Down (Use Intervals)", ROTATINGSTAIR_DOWN_INTERVAL);
204
RSDK_ENUM_VAR("Start Right (Use Intervals)", ROTATINGSTAIR_RIGHT_INTERVAL);
205
RSDK_ENUM_VAR("Start Up (Use Intervals)", ROTATINGSTAIR_UP_INTERVAL);
206
207
RSDK_ACTIVE_VAR(RotatingStair, direction);
208
RSDK_ENUM_VAR("No Flip", FLIP_NONE);
209
RSDK_ENUM_VAR("Flipped", FLIP_X);
210
}
211
#endif
212
213
void RotatingStair_Serialize(void)
214
{
215
RSDK_EDITABLE_VAR(RotatingStair, VAR_ENUM, mode);
216
RSDK_EDITABLE_VAR(RotatingStair, VAR_VECTOR2, amplitude);
217
RSDK_EDITABLE_VAR(RotatingStair, VAR_ENUM, childCount);
218
RSDK_EDITABLE_VAR(RotatingStair, VAR_UINT8, direction);
219
RSDK_EDITABLE_VAR(RotatingStair, VAR_UINT16, oscOff);
220
}
221
222