Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/SPZ/DirectorChair.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: DirectorChair Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectDirectorChair *DirectorChair;
11
12
void DirectorChair_Update(void) { Platform_Update(); }
13
14
void DirectorChair_LateUpdate(void) {}
15
16
void DirectorChair_StaticUpdate(void) {}
17
18
void DirectorChair_Draw(void)
19
{
20
RSDK_THIS(DirectorChair);
21
22
Vector2 drawPos;
23
int32 sin = RSDK.Sin512(self->rotation);
24
25
drawPos = self->centerPos;
26
self->animator.frameID = 2;
27
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
28
29
self->animator.frameID = 1;
30
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
31
32
self->animator.frameID = 0;
33
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
34
RSDK.DrawSprite(&self->animator, &self->centerPos, false);
35
36
drawPos.x += -0x10000 - (RSDK.Cos512(self->rotation) << 11);
37
RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);
38
39
self->direction = FLIP_X;
40
self->rotation = 0x100 - self->rotation;
41
drawPos.y += sin << 12;
42
RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);
43
44
self->direction = FLIP_NONE;
45
self->rotation = 0x100 - self->rotation;
46
47
for (int32 i = 0; i < self->size; ++i) {
48
RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);
49
50
self->direction = FLIP_X;
51
self->rotation = 0x100 - self->rotation;
52
drawPos.y += sin << 12;
53
RSDK.DrawSprite(&self->scissorAnimator, &drawPos, false);
54
55
self->direction = FLIP_NONE;
56
self->rotation = 0x100 - self->rotation;
57
}
58
}
59
60
void DirectorChair_Create(void *data)
61
{
62
RSDK_THIS(DirectorChair);
63
64
RSDK.SetSpriteAnimation(DirectorChair->aniFrames, 0, &self->scissorAnimator, true, 0);
65
RSDK.SetSpriteAnimation(DirectorChair->aniFrames, 1, &self->animator, true, 0);
66
67
if (!SceneInfo->inEditor) {
68
self->centerPos = self->position;
69
self->drawPos = self->position;
70
self->active = ACTIVE_BOUNDS;
71
self->visible = true;
72
self->drawFX = FX_ROTATE | FX_FLIP;
73
self->updateRange.x = 0x800000;
74
self->updateRange.y = ((RSDK.Sin512(96) + 0x8000) << 8) + (RSDK.Sin512(96) << 12) * (self->size + 1);
75
self->drawGroup = Zone->objectDrawGroup[0];
76
self->minRetract = (self->size >> 2) - 16;
77
self->rotation = self->type == DIRECTORCHAIR_CLOSED ? self->minRetract : -96;
78
self->angle = self->rotation << 8;
79
self->state = DirectorChair_State_Idle;
80
self->stateCollide = DirectorChair_Collide_Chair;
81
self->speed <<= 7;
82
self->initExtendVel = MAX(32 - 2 * self->size, 1);
83
}
84
}
85
86
void DirectorChair_StageLoad(void)
87
{
88
if (RSDK.CheckSceneFolder("SPZ1"))
89
DirectorChair->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/DirectorChair.bin", SCOPE_STAGE);
90
91
DirectorChair->hitboxChair.top = -18;
92
DirectorChair->hitboxChair.left = -18;
93
DirectorChair->hitboxChair.right = 18;
94
DirectorChair->hitboxChair.bottom = -4;
95
96
DirectorChair->hitboxL.top = -35;
97
DirectorChair->hitboxL.left = -24;
98
DirectorChair->hitboxL.right = -16;
99
DirectorChair->hitboxL.bottom = -3;
100
101
DirectorChair->hitboxR.top = -35;
102
DirectorChair->hitboxR.left = 16;
103
DirectorChair->hitboxR.right = 24;
104
DirectorChair->hitboxR.bottom = -3;
105
106
DirectorChair->extendCount = 0;
107
DirectorChair->retractCount = 0;
108
109
DirectorChair->sfxUnravel = RSDK.GetSfx("Stage/Unravel.wav");
110
DirectorChair->sfxExtend = RSDK.GetSfx("Stage/Extend.wav");
111
DirectorChair->sfxRetract = RSDK.GetSfx("Stage/Retract.wav");
112
}
113
114
void DirectorChair_Collide_Chair(void)
115
{
116
RSDK_THIS(DirectorChair);
117
118
int32 playerID = 0;
119
self->stoodPlayers = 0;
120
121
foreach_active(Player, player)
122
{
123
bool32 prevOnGround = player->onGround;
124
if (Player_CheckCollisionPlatform(player, self, &DirectorChair->hitboxChair)) {
125
#if MANIA_USE_PLUS
126
if (self->state == DirectorChair_State_Idle && player->state == Player_State_MightyHammerDrop)
127
player->state = Player_State_Air;
128
#endif
129
self->timer = 0;
130
if (!prevOnGround) {
131
self->stoodPlayers |= 1 << playerID;
132
self->stood = true;
133
player->position.x += self->collisionOffset.x;
134
player->position.y += self->collisionOffset.y;
135
player->position.y &= 0xFFFF0000;
136
}
137
}
138
139
if (Player_CheckCollisionBox(player, self, &DirectorChair->hitboxL) == C_TOP) {
140
self->timer = 0;
141
if (!prevOnGround) {
142
self->stoodPlayers |= 1 << playerID;
143
player->position.x += self->collisionOffset.x;
144
player->position.y += self->collisionOffset.y;
145
player->position.y &= 0xFFFF0000;
146
}
147
}
148
149
if (Player_CheckCollisionBox(player, self, &DirectorChair->hitboxR) == C_TOP) {
150
self->timer = 0;
151
if (!prevOnGround) {
152
self->stoodPlayers |= 1 << playerID;
153
player->position.x += self->collisionOffset.x;
154
player->position.y += self->collisionOffset.y;
155
player->position.y &= 0xFFFF0000;
156
}
157
}
158
159
// Extend Hitbox
160
Hitbox hitbox;
161
hitbox.right = (RSDK.Cos512(self->rotation) >> 5) + 8;
162
hitbox.bottom = (self->centerPos.y - self->drawPos.y) >> 16;
163
hitbox.left = -hitbox.right;
164
hitbox.top = 0;
165
Player_CheckCollisionBox(player, self, &hitbox);
166
167
++playerID;
168
}
169
}
170
171
void DirectorChair_State_Idle(void)
172
{
173
RSDK_THIS(DirectorChair);
174
175
int32 sin = RSDK.Sin512(self->rotation);
176
self->drawPos.x = self->centerPos.x;
177
self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);
178
179
if (self->stood) {
180
self->active = ACTIVE_NORMAL;
181
self->extendVel = 512;
182
if (self->type == DIRECTORCHAIR_CLOSED) {
183
RSDK.PlaySfx(DirectorChair->sfxUnravel, false, 0xFF);
184
self->state = DirectorChair_State_StartExtend;
185
}
186
else {
187
++DirectorChair->retractCount;
188
RSDK.PlaySfx(DirectorChair->sfxRetract, false, 0xFF);
189
self->state = DirectorChair_State_Retract;
190
}
191
}
192
}
193
194
void DirectorChair_State_StartExtend(void)
195
{
196
RSDK_THIS(DirectorChair);
197
198
self->angle += self->extendVel;
199
self->extendVel -= self->initExtendVel;
200
self->rotation = self->angle >> 8;
201
202
if (self->rotation >= 0) {
203
self->rotation = 0;
204
self->angle = 0;
205
self->extendVel = -self->initExtendVel;
206
++DirectorChair->extendCount;
207
RSDK.PlaySfx(DirectorChair->sfxExtend, false, 0xFF);
208
self->state = DirectorChair_State_Extend;
209
}
210
211
int32 sin = RSDK.Sin512(self->rotation);
212
self->drawPos.x = self->centerPos.x;
213
self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);
214
}
215
216
void DirectorChair_State_Extend(void)
217
{
218
RSDK_THIS(DirectorChair);
219
220
self->angle -= self->extendVel;
221
if (self->extendVel != self->speed) {
222
if (self->extendVel >= self->speed) {
223
self->speed -= 32;
224
if (self->extendVel < self->speed)
225
self->extendVel = self->speed;
226
}
227
else {
228
self->extendVel += 0x20;
229
if (self->extendVel > self->speed)
230
self->extendVel = self->speed;
231
}
232
}
233
234
self->rotation = self->angle >> 8;
235
if (self->rotation <= -96) {
236
self->rotation = -96;
237
238
if (!--DirectorChair->extendCount)
239
RSDK.StopSfx(DirectorChair->sfxExtend);
240
241
if (self->type == DIRECTORCHAIR_CLOSED) {
242
self->state = DirectorChair_State_StartRetract;
243
}
244
else {
245
self->active = ACTIVE_BOUNDS;
246
self->state = DirectorChair_State_Idle;
247
}
248
}
249
250
int32 sin = RSDK.Sin512(self->rotation);
251
self->drawPos.x = self->centerPos.x;
252
self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);
253
}
254
255
void DirectorChair_State_StartRetract(void)
256
{
257
RSDK_THIS(DirectorChair);
258
259
if (++self->timer >= 60) {
260
self->timer = 0;
261
self->extendVel = 0;
262
263
if (self->type == DIRECTORCHAIR_CLOSED) {
264
++DirectorChair->retractCount;
265
RSDK.PlaySfx(DirectorChair->sfxRetract, false, 0xFF);
266
self->state = DirectorChair_State_Retract;
267
}
268
else {
269
++DirectorChair->extendCount;
270
RSDK.PlaySfx(DirectorChair->sfxExtend, false, 0xFF);
271
self->state = DirectorChair_State_Extend;
272
}
273
}
274
275
int32 sin = RSDK.Sin512(self->rotation);
276
self->drawPos.x = self->centerPos.x;
277
self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);
278
}
279
280
void DirectorChair_State_Retract(void)
281
{
282
RSDK_THIS(DirectorChair);
283
284
self->angle += self->extendVel;
285
286
if (self->extendVel != self->speed) {
287
if (self->extendVel >= self->speed) {
288
self->extendVel -= 32;
289
if (self->extendVel < self->speed)
290
self->extendVel = self->speed;
291
}
292
else {
293
self->extendVel += 0x20;
294
if (self->extendVel > self->speed)
295
self->extendVel = self->speed;
296
}
297
}
298
299
self->rotation = self->angle >> 8;
300
if (self->rotation >= self->minRetract) {
301
if (!--DirectorChair->retractCount)
302
RSDK.StopSfx(DirectorChair->sfxRetract);
303
304
self->rotation = self->minRetract;
305
if (self->type == DIRECTORCHAIR_CLOSED) {
306
self->active = ACTIVE_BOUNDS;
307
self->state = DirectorChair_State_Idle;
308
}
309
else {
310
self->state = DirectorChair_State_StartRetract;
311
}
312
}
313
314
int32 sin = RSDK.Sin512(self->rotation);
315
self->drawPos.x = self->centerPos.x;
316
self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);
317
}
318
319
#if GAME_INCLUDE_EDITOR
320
void DirectorChair_EditorDraw(void)
321
{
322
RSDK_THIS(DirectorChair);
323
324
self->centerPos = self->position;
325
self->drawPos = self->position;
326
self->active = ACTIVE_BOUNDS;
327
self->visible = true;
328
self->drawFX = FX_ROTATE | FX_FLIP;
329
self->updateRange.x = 0x800000;
330
self->updateRange.y = ((RSDK.Sin512(96) + 0x8000) << 8) + (RSDK.Sin512(96) << 12) * (self->size + 1);
331
self->drawGroup = Zone->objectDrawGroup[0];
332
self->minRetract = (self->size >> 2) - 16;
333
self->rotation = self->type == DIRECTORCHAIR_CLOSED ? self->minRetract : -96;
334
self->angle = self->rotation << 8;
335
self->initExtendVel = MAX(32 - 2 * self->size, 1);
336
337
int32 sin = RSDK.Sin512(self->rotation);
338
self->drawPos.x = self->centerPos.x;
339
self->drawPos.y = self->centerPos.y + (sin << 8) + (sin << 12) * (self->size + 1);
340
341
DirectorChair_Draw();
342
343
if (showGizmos()) {
344
RSDK_DRAWING_OVERLAY(true);
345
346
self->rotation = self->type != DIRECTORCHAIR_CLOSED ? self->minRetract : -96;
347
self->angle = self->rotation << 8;
348
self->initExtendVel = MAX(32 - 2 * self->size, 1);
349
350
self->drawPos.x = self->centerPos.x;
351
self->drawPos.y = self->centerPos.y + (RSDK.Sin512(self->rotation) << 8) + (RSDK.Sin512(self->rotation) << 12) * (self->size + 1);
352
353
self->inkEffect = INK_BLEND;
354
DirectorChair_Draw();
355
self->inkEffect = INK_NONE;
356
357
RSDK_DRAWING_OVERLAY(false);
358
}
359
}
360
361
void DirectorChair_EditorLoad(void)
362
{
363
DirectorChair->aniFrames = RSDK.LoadSpriteAnimation("SPZ1/DirectorChair.bin", SCOPE_STAGE);
364
365
RSDK_ACTIVE_VAR(DirectorChair, type);
366
RSDK_ENUM_VAR("Closed", DIRECTORCHAIR_CLOSED);
367
RSDK_ENUM_VAR("Stretched Out", DIRECTORCHAIR_STRETCHED);
368
}
369
#endif
370
371
void DirectorChair_Serialize(void)
372
{
373
RSDK_EDITABLE_VAR(DirectorChair, VAR_ENUM, type);
374
RSDK_EDITABLE_VAR(DirectorChair, VAR_ENUM, speed);
375
RSDK_EDITABLE_VAR(DirectorChair, VAR_ENUM, size);
376
}
377
378