Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/SSZ/MSFactory.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: MSFactory Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectMSFactory *MSFactory;
11
12
void MSFactory_Update(void)
13
{
14
RSDK_THIS(MSFactory);
15
16
StateMachine_Run(self->state);
17
}
18
19
void MSFactory_LateUpdate(void) {}
20
21
void MSFactory_StaticUpdate(void) {}
22
23
void MSFactory_Draw(void)
24
{
25
RSDK_THIS(MSFactory);
26
27
self->animator.frameID = 0;
28
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
29
30
self->animator.frameID = 1;
31
RSDK.DrawSprite(&self->animator, NULL, false);
32
}
33
34
void MSFactory_Create(void *data)
35
{
36
RSDK_THIS(MSFactory);
37
38
if (!SceneInfo->inEditor) {
39
self->visible = false;
40
self->drawGroup = Zone->objectDrawGroup[0];
41
self->drawPos = self->position;
42
self->active = ACTIVE_BOUNDS;
43
self->updateRange.x = 0x800000;
44
self->updateRange.y = 0x800000;
45
46
self->state = MSFactory_State_SetupFactory;
47
RSDK.SetSpriteAnimation(MSFactory->aniFrames, 0, &self->animator, true, 1);
48
}
49
}
50
51
void MSFactory_StageLoad(void)
52
{
53
MSFactory->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSFactory.bin", SCOPE_STAGE);
54
55
MSFactory->sfxMachineActivate = RSDK.GetSfx("Stage/MachineActivate.wav");
56
MSFactory->sfxHullClose = RSDK.GetSfx("Stage/HullClose.wav");
57
}
58
59
void MSFactory_State_SetupFactory(void)
60
{
61
RSDK_THIS(MSFactory);
62
63
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
64
65
if (player1->position.y < self->position.y + 0x100000 && player1->position.y > self->position.y - 0x1000000) {
66
Zone->playerBoundActiveL[0] = true;
67
Zone->playerBoundActiveR[0] = true;
68
69
Zone->cameraBoundsL[0] = (self->position.x >> 16) - ScreenInfo->center.x;
70
Zone->cameraBoundsR[0] = (self->position.x >> 16) + ScreenInfo->center.x;
71
Zone->cameraBoundsT[0] = (self->position.y >> 16) - ScreenInfo->size.y + 44;
72
Zone->cameraBoundsB[0] = (self->position.y >> 16) + 44;
73
74
self->state = MSFactory_State_SetupMetalSonic;
75
}
76
}
77
78
void MSFactory_State_SetupMetalSonic(void)
79
{
80
RSDK_THIS(MSFactory);
81
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
82
83
if (player1->position.x > self->position.x && player1->position.y < self->position.y + 0x300000) {
84
foreach_active(MetalSonic, metal)
85
{
86
if (!RSDK.CheckOnScreen(metal, NULL)) {
87
metal->position.x = self->position.x;
88
metal->position.y = self->position.y;
89
metal->position.x -= 0x1000000;
90
}
91
}
92
93
self->state = StateMachine_None;
94
}
95
}
96
97
void MSFactory_State_OpeningDoor(void)
98
{
99
RSDK_THIS(MSFactory);
100
101
self->position.y += 0x20000;
102
103
if (!self->timer)
104
RSDK.PlaySfx(MSFactory->sfxMachineActivate, false, 255);
105
106
if (++self->timer == 24) {
107
self->timer = 0;
108
self->state = MSFactory_State_CreateSilverSonic;
109
}
110
}
111
112
void MSFactory_State_CreateSilverSonic(void)
113
{
114
RSDK_THIS(MSFactory);
115
116
if (++self->timer == 8) {
117
foreach_active(MetalSonic, metal)
118
{
119
if (metal && metal->state != MetalSonic_State_PanelExplosion)
120
CREATE_ENTITY(SilverSonic, NULL, self->drawPos.x, self->drawPos.y + 0x80000);
121
122
foreach_break;
123
}
124
}
125
126
if (self->timer == 60) {
127
self->timer = 0;
128
self->state = MSFactory_State_CloseDoor;
129
}
130
}
131
132
void MSFactory_State_CloseDoor(void)
133
{
134
RSDK_THIS(MSFactory);
135
136
self->position.y -= 0x20000;
137
if (++self->timer == 24) {
138
Camera_ShakeScreen(0, 0, 2);
139
140
self->timer = 0;
141
self->visible = false;
142
self->state = StateMachine_None;
143
144
RSDK.PlaySfx(MSFactory->sfxHullClose, false, 255);
145
}
146
}
147
148
#if GAME_INCLUDE_EDITOR
149
void MSFactory_EditorDraw(void)
150
{
151
RSDK_THIS(MSFactory);
152
RSDK.SetSpriteAnimation(MSFactory->aniFrames, 0, &self->animator, false, 1);
153
154
self->animator.frameID = 0;
155
RSDK.DrawSprite(&self->animator, NULL, false);
156
157
self->animator.frameID = 1;
158
RSDK.DrawSprite(&self->animator, NULL, false);
159
160
if (showGizmos()) {
161
RSDK_DRAWING_OVERLAY(true);
162
163
DrawHelpers_DrawArenaBounds(-WIDE_SCR_XCENTER, -SCREEN_YSIZE + 44, WIDE_SCR_XCENTER, 44, 1 | 2 | 4 | 8, 0x00C0F0);
164
165
RSDK_DRAWING_OVERLAY(false);
166
}
167
}
168
169
void MSFactory_EditorLoad(void) { MSFactory->aniFrames = RSDK.LoadSpriteAnimation("SSZ2/MSFactory.bin", SCOPE_STAGE); }
170
#endif
171
172
void MSFactory_Serialize(void) {}
173
174