Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/HCZ/ButtonDoor.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: ButtonDoor Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectButtonDoor *ButtonDoor;
11
12
void ButtonDoor_Update(void)
13
{
14
RSDK_THIS(ButtonDoor);
15
16
EntityButton *button = self->taggedButton;
17
if (button && button->activated) {
18
19
if (!self->movePos)
20
RSDK.PlaySfx(ButtonDoor->sfxOpen, false, 255);
21
22
if (self->movePos < self->duration) {
23
switch (self->orientation) {
24
case BUTTONDOOR_UP: self->position.y = self->startPos.y - self->movePos * (self->size.y / self->duration); break;
25
case BUTTONDOOR_LEFT: self->position.x = self->startPos.x - self->movePos * (self->size.x / self->duration); break;
26
case BUTTONDOOR_DOWN: self->position.y = self->startPos.y + self->movePos * (self->size.y / self->duration); break;
27
case BUTTONDOOR_RIGHT: self->position.x = self->startPos.x + self->movePos * (self->size.x / self->duration); break;
28
}
29
30
self->movePos++;
31
}
32
else {
33
switch (self->orientation) {
34
case BUTTONDOOR_UP: self->position.y = self->startPos.y - self->size.y; break;
35
case BUTTONDOOR_LEFT: self->position.x = self->startPos.x - self->size.x; break;
36
case BUTTONDOOR_DOWN: self->position.y = self->startPos.y + self->size.y; break;
37
case BUTTONDOOR_RIGHT: self->position.x = self->startPos.x + self->size.x; break;
38
}
39
}
40
}
41
42
foreach_active(Player, player) { Player_CheckCollisionBox(player, self, &self->hitbox); }
43
}
44
45
void ButtonDoor_LateUpdate(void) {}
46
47
void ButtonDoor_StaticUpdate(void) {}
48
49
void ButtonDoor_Draw(void) { ButtonDoor_DrawSprites(); }
50
51
void ButtonDoor_Create(void *data)
52
{
53
RSDK_THIS(ButtonDoor);
54
55
if (!self->duration)
56
self->duration = 6;
57
58
if (!self->length)
59
self->length = 2 - (RSDK.CheckSceneFolder("HCZ") != true);
60
61
self->active = ACTIVE_BOUNDS;
62
self->drawGroup = Zone->objectDrawGroup[0];
63
self->startPos = self->position;
64
self->visible = true;
65
self->drawFX = FX_FLIP;
66
self->updateRange.x = self->size.x + 0x800000;
67
self->updateRange.y = self->size.y + 0x800000;
68
69
ButtonDoor_SetupSize();
70
ButtonDoor_SetupTagLink();
71
72
RSDK.SetSpriteAnimation(ButtonDoor->aniFrames, 0, &self->animator, true, 0);
73
}
74
75
void ButtonDoor_StageLoad(void)
76
{
77
if (RSDK.CheckSceneFolder("LRZ1")) {
78
ButtonDoor->aniFrames = RSDK.LoadSpriteAnimation("LRZ1/ButtonDoor.bin", SCOPE_STAGE);
79
ButtonDoor->sfxOpen = RSDK.GetSfx("Stage/Open.wav");
80
}
81
else if (RSDK.CheckSceneFolder("LRZ2")) {
82
ButtonDoor->aniFrames = RSDK.LoadSpriteAnimation("LRZ2/ButtonDoor.bin", SCOPE_STAGE);
83
ButtonDoor->sfxOpen = RSDK.GetSfx("Stage/Open.wav");
84
}
85
else if (RSDK.CheckSceneFolder("HCZ")) {
86
ButtonDoor->aniFrames = RSDK.LoadSpriteAnimation("HCZ/ButtonDoor.bin", SCOPE_STAGE);
87
ButtonDoor->sfxOpen = RSDK.GetSfx("Stage/Clack.wav");
88
}
89
}
90
91
void ButtonDoor_SetupSize(void)
92
{
93
RSDK_THIS(ButtonDoor);
94
95
if (RSDK.CheckSceneFolder("LRZ1")) {
96
self->size.y = 0x800000;
97
self->size.x = 0x200000;
98
}
99
else if (RSDK.CheckSceneFolder("LRZ2")) {
100
self->size.y = 0x400000;
101
self->size.x = 0x200000;
102
}
103
else if (RSDK.CheckSceneFolder("HCZ")) {
104
self->size.y = 0x200000;
105
self->size.x = 0x200000;
106
}
107
108
// Size of one "block"
109
self->segmentSize = self->size;
110
111
// Total Size
112
if (self->orientation == BUTTONDOOR_UP || self->orientation == BUTTONDOOR_DOWN)
113
self->size.y *= self->length;
114
else if (self->orientation == BUTTONDOOR_LEFT || self->orientation == BUTTONDOOR_RIGHT)
115
self->size.x *= self->length;
116
117
self->hitbox.left = -(self->size.x >> 17);
118
self->hitbox.top = -(self->size.y >> 17);
119
self->hitbox.right = self->size.x >> 17;
120
self->hitbox.bottom = self->size.y >> 17;
121
}
122
123
void ButtonDoor_SetupTagLink(void)
124
{
125
RSDK_THIS(ButtonDoor);
126
127
self->taggedButton = NULL;
128
129
if (RSDK.CheckSceneFolder("LRZ2")) {
130
self->taggedButton = LRZ2Setup_SetupTagLink(self->buttonTag, (Entity *)self);
131
}
132
else {
133
EntityButton *taggedButton = RSDK_GET_ENTITY(RSDK.GetEntitySlot(self) - 1, Button);
134
bool32 tagged = false;
135
136
if (self->buttonTag > 0) {
137
if (Button) {
138
foreach_all(Button, button)
139
{
140
if (button->tag == self->buttonTag) {
141
taggedButton = button;
142
tagged = true;
143
foreach_break;
144
}
145
}
146
}
147
148
if (PullChain && !tagged) {
149
foreach_all(PullChain, chain)
150
{
151
if (chain->tag == self->buttonTag) {
152
taggedButton = (EntityButton *)chain;
153
tagged = true;
154
foreach_break;
155
}
156
}
157
}
158
159
if (TurretSwitch && !tagged) {
160
foreach_all(TurretSwitch, turretSwitch)
161
{
162
if (turretSwitch->tag == self->buttonTag) {
163
taggedButton = (EntityButton *)turretSwitch;
164
tagged = true;
165
foreach_break;
166
}
167
}
168
}
169
}
170
171
if (taggedButton) {
172
if ((Button && taggedButton->classID == Button->classID) || (TurretSwitch && taggedButton->classID == TurretSwitch->classID)
173
|| (PullChain && taggedButton->classID == PullChain->classID)) {
174
if (self) {
175
int32 distX = abs(self->position.x - taggedButton->position.x) + 0x800000;
176
int32 distY = abs(self->position.y - taggedButton->position.y) + 0x800000;
177
178
if (self->updateRange.x < distX)
179
self->updateRange.x = distX;
180
181
if (self->updateRange.y < distY)
182
self->updateRange.y = distY;
183
}
184
185
self->taggedButton = taggedButton;
186
}
187
}
188
}
189
}
190
191
void ButtonDoor_DrawSprites(void)
192
{
193
RSDK_THIS(ButtonDoor);
194
195
Vector2 drawPos = self->position;
196
197
int32 incX = 0, incY = 0;
198
if (self->orientation == BUTTONDOOR_UP || self->orientation == BUTTONDOOR_DOWN) {
199
drawPos.y = (self->segmentSize.y >> 1) + self->position.y - (self->size.y >> 1);
200
incY = self->segmentSize.y;
201
}
202
else if (self->orientation == BUTTONDOOR_LEFT || self->orientation == BUTTONDOOR_RIGHT) {
203
drawPos.x = (self->segmentSize.x >> 1) + self->position.x - (self->size.x >> 1);
204
incX = self->segmentSize.x;
205
}
206
207
for (int32 i = 0; i < self->length; ++i) {
208
RSDK.DrawSprite(&self->animator, &drawPos, false);
209
210
drawPos.x += incX;
211
drawPos.y += incY;
212
}
213
}
214
215
#if GAME_INCLUDE_EDITOR
216
void ButtonDoor_EditorDraw(void)
217
{
218
RSDK_THIS(ButtonDoor);
219
220
ButtonDoor_SetupSize();
221
ButtonDoor_DrawSprites();
222
223
if (showGizmos()) {
224
ButtonDoor_SetupTagLink();
225
226
RSDK_DRAWING_OVERLAY(true);
227
228
Vector2 storePos = self->position;
229
switch (self->orientation) {
230
case BUTTONDOOR_UP: self->position.y = self->startPos.y - self->size.y; break;
231
case BUTTONDOOR_LEFT: self->position.x = self->startPos.x - self->size.x; break;
232
case BUTTONDOOR_DOWN: self->position.y = self->startPos.y + self->size.y; break;
233
case BUTTONDOOR_RIGHT: self->position.x = self->startPos.x + self->size.x; break;
234
}
235
self->inkEffect = INK_BLEND;
236
ButtonDoor_DrawSprites();
237
238
DrawHelpers_DrawArrow(storePos.x, storePos.y, self->position.x, self->position.y, 0x00F000, INK_NONE, 0xFF);
239
self->position = storePos;
240
self->inkEffect = INK_NONE;
241
242
if (self->taggedButton) {
243
DrawHelpers_DrawArrow(self->taggedButton->position.x, self->taggedButton->position.y, self->position.x, self->position.y, 0xFFFF00,
244
INK_NONE, 0xFF);
245
}
246
RSDK_DRAWING_OVERLAY(false);
247
}
248
}
249
250
void ButtonDoor_EditorLoad(void)
251
{
252
if (RSDK.CheckSceneFolder("LRZ1"))
253
ButtonDoor->aniFrames = RSDK.LoadSpriteAnimation("LRZ1/ButtonDoor.bin", SCOPE_STAGE);
254
else if (RSDK.CheckSceneFolder("LRZ2"))
255
ButtonDoor->aniFrames = RSDK.LoadSpriteAnimation("LRZ2/ButtonDoor.bin", SCOPE_STAGE);
256
else if (RSDK.CheckSceneFolder("HCZ"))
257
ButtonDoor->aniFrames = RSDK.LoadSpriteAnimation("HCZ/ButtonDoor.bin", SCOPE_STAGE);
258
259
RSDK_ACTIVE_VAR(ButtonDoor, orientation);
260
RSDK_ENUM_VAR("Up", BUTTONDOOR_UP);
261
RSDK_ENUM_VAR("Left", BUTTONDOOR_LEFT);
262
RSDK_ENUM_VAR("Down", BUTTONDOOR_DOWN);
263
RSDK_ENUM_VAR("Right", BUTTONDOOR_RIGHT);
264
}
265
#endif
266
267
void ButtonDoor_Serialize(void)
268
{
269
RSDK_EDITABLE_VAR(ButtonDoor, VAR_ENUM, buttonTag);
270
RSDK_EDITABLE_VAR(ButtonDoor, VAR_ENUM, length);
271
RSDK_EDITABLE_VAR(ButtonDoor, VAR_ENUM, duration);
272
RSDK_EDITABLE_VAR(ButtonDoor, VAR_UINT8, orientation);
273
}
274
275