Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Menu/BGAnimation.txt
1319 views
1
//------------Sonic CD Background Animation Script------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.AngleFull
7
#alias Object.Value1 : Object.AngleRounded
8
#alias Object.Value2 : Object.BackBGSonicXPos
9
#alias Object.Value3 : Object.FrontBGSonicXPos
10
#alias Object.Value4 : Object.ZPos
11
12
// Ink Effects
13
#alias 1 : INK_BLEND
14
15
// Priority
16
#alias 1 : PRIORITY_ACTIVE
17
18
// Face Buffer Flags
19
#alias 2 : FACE_FLAG_COLOURED_3D
20
21
22
sub ObjectDraw
23
// The "Full" value ranges from 0 to 1023, using 10 bits
24
Object.AngleFull++
25
Object.AngleFull &= 1023
26
27
// The "Rounded" value, however, ranges from 0 to 511, using 9 bits, as RSDK's anlges are 512-based rather than 1024-based
28
Object.AngleRounded = Object.AngleFull
29
Object.AngleRounded >>= 1
30
31
// From this rounded value, now we actually do stuff
32
33
// First, manage the depth of the BG
34
Sin(Object.ZPos, Object.AngleRounded)
35
Object.ZPos += 0x5000
36
MatrixTranslateXYZ(MAT_WORLD, 0, 0, Object.ZPos)
37
38
// Now, handle the rotating of the BG
39
TempValue0 = Object.AngleRounded
40
MatrixRotateXYZ(MAT_VIEW, 0, 0, TempValue0)
41
42
// Draw the rectangles here, notably before we draw the Sonic sprites
43
Draw3DScene()
44
45
// Now after we've drawn the 3d stuff, draw Sonic himself
46
47
Object.BackBGSonicXPos = Screen.CenterX
48
Object.BackBGSonicXPos -= 4
49
DrawSpriteScreenFX(0, FX_INK, Object.BackBGSonicXPos, Screen.CenterY)
50
51
Object.FrontBGSonicXPos = Screen.CenterX
52
Object.FrontBGSonicXPos += 4
53
DrawSpriteScreenFX(0, FX_INK, Object.FrontBGSonicXPos, Screen.CenterY)
54
end sub
55
56
57
sub ObjectStartup
58
// So this is removing the stage's FG layer but,
59
// the stage's configuration in the act file already has it set up like that anyway...
60
Stage[0].ActiveLayer = 9
61
62
LoadSpriteSheet("Menu/MenuGfx1_EN.gif")
63
64
SpriteFrame(-160, -104, 320, 224, 0, 0) // #0 - Sonic Background
65
66
ArrayPos0 = 32
67
while ArrayPos0 < 1056
68
if Object[ArrayPos0].Type == TypeName[BG Animation]
69
Object[ArrayPos0].Priority = PRIORITY_ACTIVE
70
Object[ArrayPos0].DrawOrder = 2
71
Object[ArrayPos0].InkEffect = INK_BLEND
72
end if
73
74
ArrayPos0++
75
loop
76
77
// The three rotating rectanlges in the background are actually 3d elements, let's setup them up here
78
79
// First, reset all the matrix values
80
MatrixTranslateXYZ(MAT_WORLD, 0, 0, 0)
81
MatrixRotateXYZ(MAT_VIEW, 0, 0, 0)
82
83
// Three rectanlges, four edges per rectanlge, yup that makes 12 corners in total!
84
3DScene.NoVertices = 12
85
3DScene.NoFaces = 3
86
87
// Set the vertex coordinates for the first rectangle
88
89
// 0 - Top left
90
VertexBuffer[0].x = -0xC800
91
VertexBuffer[0].y = 0xC800
92
VertexBuffer[0].z = 256
93
94
// 1 - Top right
95
VertexBuffer[1].x = 0xC00
96
VertexBuffer[1].y = 0xC800
97
VertexBuffer[1].z = 256
98
99
// 2 - Bottom left
100
VertexBuffer[2].x = -0xC800
101
VertexBuffer[2].y = 0x3000
102
VertexBuffer[2].z = 256
103
104
// 3 - Bottom right
105
VertexBuffer[3].x = 0xC00
106
VertexBuffer[3].y = 0x3000
107
VertexBuffer[3].z = 256
108
109
// Set the faces of the first rectangle
110
FaceBuffer[0].a = 0
111
FaceBuffer[0].b = 1
112
FaceBuffer[0].c = 2
113
FaceBuffer[0].d = 3
114
115
FaceBuffer[0].Flag = FACE_FLAG_COLOURED_3D
116
117
// Setting the color of the first rectangle, giving it a green of sorts (0x80E040)
118
FaceBuffer[0].Color = 128
119
FaceBuffer[0].Color <<= 16
120
TempValue0 = 224
121
TempValue0 <<= 8
122
FaceBuffer[0].Color += TempValue0
123
FaceBuffer[0].Color += 64
124
FaceBuffer[0].Color += 0x7F000000 // Half transparency
125
126
// Now, set up the second rectanlge
127
128
// 4 - Top left
129
VertexBuffer[4].x = -0xC800
130
VertexBuffer[4].y = 0x3000
131
VertexBuffer[4].z = 256
132
133
// 5 - Top right
134
VertexBuffer[5].x = 0xC00
135
VertexBuffer[5].y = 0x3000
136
VertexBuffer[5].z = 256
137
138
// 6 - Bottom left
139
VertexBuffer[6].x = -0xC800
140
VertexBuffer[6].y = -0xC800
141
VertexBuffer[6].z = 256
142
143
// 7 - Bottom right
144
VertexBuffer[7].x = 0xC00
145
VertexBuffer[7].y = -0xC800
146
VertexBuffer[7].z = 256
147
148
// Set the faces of the second rectangle
149
FaceBuffer[1].a = 4
150
FaceBuffer[1].b = 5
151
FaceBuffer[1].c = 6
152
FaceBuffer[1].d = 7
153
154
FaceBuffer[1].Flag = FACE_FLAG_COLOURED_3D
155
156
// Setting the color of the second rectangle, this one gets a cool orange (0xE0A060)
157
FaceBuffer[1].Color = 224
158
FaceBuffer[1].Color <<= 16
159
TempValue0 = 160
160
TempValue0 <<= 8
161
FaceBuffer[1].Color += TempValue0
162
FaceBuffer[1].Color += 96
163
FaceBuffer[1].Color += 0x7F000000 // Once again, half transparency
164
165
// And last but not least, set up the third rectangle
166
167
// 8 - Top left
168
VertexBuffer[8].x = 0xB00
169
VertexBuffer[8].y = 0xC800
170
VertexBuffer[8].z = 256
171
172
// 9 - Top right
173
VertexBuffer[9].x = 0xC800
174
VertexBuffer[9].y = 0xC800
175
VertexBuffer[9].z = 256
176
177
// 10 - Bottom left
178
VertexBuffer[10].x = 0xB00
179
VertexBuffer[10].y = -0xC800
180
VertexBuffer[10].z = 256
181
182
// 11 - Bottom right
183
VertexBuffer[11].x = 0xC800
184
VertexBuffer[11].y = -0xC800
185
VertexBuffer[11].z = 256
186
187
// Set the faces of the third rectangle
188
FaceBuffer[2].a = 8
189
FaceBuffer[2].b = 9
190
FaceBuffer[2].c = 10
191
FaceBuffer[2].d = 11
192
193
FaceBuffer[2].Flag = FACE_FLAG_COLOURED_3D
194
195
// Setting the color of the a rectangle one last time, the third one gets a nice blue (0x8080E0)
196
FaceBuffer[2].Color = 128
197
FaceBuffer[2].Color <<= 16
198
TempValue0 = 128
199
TempValue0 <<= 8
200
FaceBuffer[2].Color += TempValue0
201
FaceBuffer[2].Color += 224
202
FaceBuffer[2].Color += 0x7F000000
203
end sub
204
205
206
// ========================
207
// Editor Subs
208
// ========================
209
210
sub RSDKDraw
211
DrawSprite(0)
212
end sub
213
214
215
sub RSDKLoad
216
LoadSpriteSheet("Menu/MenuGfx1_EN.gif")
217
SpriteFrame(-160, -104, 320, 224, 0, 0) // Sonic Background
218
219
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
220
end sub
221
222