Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/SPZ/GreenScreen.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: GreenScreen Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectGreenScreen *GreenScreen;
11
12
void GreenScreen_Update(void) {}
13
14
void GreenScreen_LateUpdate(void) {}
15
16
void GreenScreen_StaticUpdate(void)
17
{
18
int32 count = 0;
19
20
foreach_active(GreenScreen, screen)
21
{
22
RSDK.AddDrawListRef(Zone->objectDrawGroup[1], RSDK.GetEntitySlot(screen));
23
++count;
24
}
25
26
GreenScreen->greenScreenActive = count > 0;
27
}
28
29
void GreenScreen_Draw(void) { GreenScreen_DrawSprites(); }
30
31
void GreenScreen_Create(void *data)
32
{
33
RSDK_THIS(GreenScreen);
34
35
self->active = ACTIVE_BOUNDS;
36
self->drawGroup = Zone->objectDrawGroup[0];
37
self->startPos = self->position;
38
self->visible = true;
39
self->drawFX = FX_FLIP;
40
self->updateRange.x = 0x800000;
41
self->updateRange.y = 0x800000;
42
self->showBG = true;
43
44
if (!self->paraYFactor)
45
self->paraYFactor = 32;
46
47
// A... Secondary Setup....?
48
GreenScreen->hitbox.left = -104;
49
GreenScreen->hitbox.top = -64;
50
GreenScreen->hitbox.right = 104;
51
GreenScreen->hitbox.bottom = 64;
52
}
53
54
void GreenScreen_StageLoad(void)
55
{
56
GreenScreen->aniFrames = RSDK.LoadSpriteAnimation("SPZ2/GreenScreen.bin", SCOPE_STAGE);
57
58
GreenScreen->hitbox.left = -104;
59
GreenScreen->hitbox.top = -64;
60
GreenScreen->hitbox.right = 104;
61
GreenScreen->hitbox.bottom = 64;
62
63
GreenScreen->parallaxFactor[0] = 0;
64
GreenScreen->parallaxFactor[1] = 42;
65
GreenScreen->parallaxFactor[2] = 64;
66
GreenScreen->parallaxFactor[3] = 96;
67
GreenScreen->parallaxFactor[4] = 112;
68
69
GreenScreen->bgSize[0] = 16 << 16;
70
GreenScreen->bgSize[1] = 180 << 16;
71
GreenScreen->bgSize[2] = 190 << 16;
72
GreenScreen->bgSize[3] = 192 << 16;
73
GreenScreen->bgSize[4] = 192 << 16;
74
}
75
76
void GreenScreen_DrawBG(int32 x, int32 y, uint8 bgID, int32 parallaxFactor)
77
{
78
RSDK_THIS(GreenScreen);
79
Vector2 drawPos;
80
81
int32 paraX = parallaxFactor * (-x / 128);
82
while (paraX >= 0) paraX -= GreenScreen->bgSize[bgID];
83
84
drawPos = self->position;
85
drawPos.y += (self->paraYFactor * (-y / 128));
86
drawPos.x += (GreenScreen->hitbox.left << 16) + paraX;
87
88
int32 sizeX = self->position.x + (GreenScreen->hitbox.right << 16);
89
RSDK.SetSpriteAnimation(GreenScreen->aniFrames, 1, &self->animator, true, bgID);
90
while (drawPos.x < sizeX) {
91
RSDK.DrawSprite(&self->animator, &drawPos, false);
92
drawPos.x += GreenScreen->bgSize[bgID];
93
}
94
}
95
96
void GreenScreen_DrawBackgrounds(void)
97
{
98
RSDK_THIS(GreenScreen);
99
100
int32 clipX1 = 0, clipY1 = 0, clipX2 = 0, clipY2 = 0;
101
if (!SceneInfo->inEditor) {
102
clipX1 = ScreenInfo->clipBound_X1;
103
clipY1 = ScreenInfo->clipBound_Y1;
104
clipX2 = ScreenInfo->clipBound_X2;
105
clipY2 = ScreenInfo->clipBound_Y2;
106
RSDK.SetClipBounds(SceneInfo->currentScreenID, (self->position.x >> 16) + GreenScreen->hitbox.left - ScreenInfo->position.x,
107
(self->position.y >> 16) + GreenScreen->hitbox.top - ScreenInfo->position.y,
108
(self->position.x >> 16) + GreenScreen->hitbox.right - ScreenInfo->position.x,
109
(self->position.y >> 16) + GreenScreen->hitbox.bottom - ScreenInfo->position.y);
110
}
111
112
for (int32 bgID = 0; bgID < 5; ++bgID) {
113
GreenScreen_DrawBG(self->position.x - self->startPos.x + self->paraOffset.x, self->position.y - self->startPos.y + self->paraOffset.y, bgID,
114
GreenScreen->parallaxFactor[bgID]);
115
}
116
117
if (!SceneInfo->inEditor)
118
RSDK.SetClipBounds(SceneInfo->currentScreenID, clipX1, clipY1, clipX2, clipY2);
119
}
120
121
void GreenScreen_DrawSprites(void)
122
{
123
RSDK_THIS(GreenScreen);
124
125
if ((SceneInfo->currentDrawGroup != Zone->objectDrawGroup[1] && self->showBG) || (SceneInfo->inEditor && self->paraPreview))
126
GreenScreen_DrawBackgrounds();
127
128
if (SceneInfo->currentDrawGroup == Zone->objectDrawGroup[1] || SceneInfo->inEditor) {
129
RSDK.SetSpriteAnimation(GreenScreen->aniFrames, 0, &self->animator, true, 0);
130
RSDK.DrawSprite(&self->animator, NULL, false);
131
}
132
}
133
134
#if GAME_INCLUDE_EDITOR
135
void GreenScreen_EditorDraw(void)
136
{
137
RSDK_THIS(GreenScreen);
138
139
self->active = ACTIVE_BOUNDS;
140
self->startPos = self->position;
141
self->visible = true;
142
self->drawFX = FX_FLIP;
143
self->updateRange.x = 0x800000;
144
self->updateRange.y = 0x800000;
145
self->showBG = false;
146
147
if (!self->paraYFactor)
148
self->paraYFactor = 32;
149
150
GreenScreen_DrawSprites();
151
}
152
153
void GreenScreen_EditorLoad(void)
154
{
155
GreenScreen->aniFrames = RSDK.LoadSpriteAnimation("SPZ2/GreenScreen.bin", SCOPE_STAGE);
156
157
GreenScreen->parallaxFactor[0] = 0;
158
GreenScreen->parallaxFactor[1] = 42;
159
GreenScreen->parallaxFactor[2] = 64;
160
GreenScreen->parallaxFactor[3] = 96;
161
GreenScreen->parallaxFactor[4] = 112;
162
163
GreenScreen->bgSize[0] = 16 << 16;
164
GreenScreen->bgSize[1] = 180 << 16;
165
GreenScreen->bgSize[2] = 190 << 16;
166
GreenScreen->bgSize[3] = 192 << 16;
167
GreenScreen->bgSize[4] = 192 << 16;
168
}
169
#endif
170
171
void GreenScreen_Serialize(void)
172
{
173
RSDK_EDITABLE_VAR(GreenScreen, VAR_VECTOR2, paraOffset);
174
RSDK_EDITABLE_VAR(GreenScreen, VAR_ENUM, paraYFactor);
175
RSDK_EDITABLE_VAR(GreenScreen, VAR_BOOL, paraPreview);
176
}
177
178