Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Special/BGEffects_S5.txt
1319 views
1
//-----------------Sonic CD BGEffects Script------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
// Values 0-1 are unused...
7
#alias Object.Value2 : Object.PrevAngle
8
#alias Object.Value3 : Object.FansTimer
9
#alias Object.Value4 : Object.CrunchersTimer
10
#alias Object.Value5 : Object.FansSprite
11
#alias Object.Value6 : Object.CrunchersSprite
12
13
// Priority
14
#alias 1 : PRIORITY_ACTIVE
15
16
17
sub ObjectDraw
18
// Animate the Fan tiles throughout the level
19
Object.FansTimer++
20
if Object.FansTimer > 2
21
Object.FansTimer = 0
22
Object.FansSprite++
23
Object.FansSprite %= 3
24
switch Object.FansSprite
25
case 0
26
// Fans are 4x4 tiles, comprised of 8 unique tiles, so
27
// 8 individual tiles need to be updated to change the entire sprite
28
Copy16x16Tile(174, 472)
29
Copy16x16Tile(175, 473)
30
Copy16x16Tile(176, 474)
31
Copy16x16Tile(177, 475)
32
Copy16x16Tile(183, 476)
33
Copy16x16Tile(184, 477)
34
Copy16x16Tile(185, 478)
35
Copy16x16Tile(186, 479)
36
break
37
38
case 1
39
Copy16x16Tile(174, 480)
40
Copy16x16Tile(175, 481)
41
Copy16x16Tile(176, 482)
42
Copy16x16Tile(177, 483)
43
Copy16x16Tile(183, 484)
44
Copy16x16Tile(184, 485)
45
Copy16x16Tile(185, 486)
46
Copy16x16Tile(186, 487)
47
break
48
49
case 2
50
Copy16x16Tile(174, 488)
51
Copy16x16Tile(175, 489)
52
Copy16x16Tile(176, 490)
53
Copy16x16Tile(177, 491)
54
Copy16x16Tile(183, 492)
55
Copy16x16Tile(184, 493)
56
Copy16x16Tile(185, 494)
57
Copy16x16Tile(186, 495)
58
break
59
60
end switch
61
end if
62
63
// Animate the Crunching tiles in the level
64
Object.CrunchersTimer++
65
if Object.CrunchersTimer > 5
66
Object.CrunchersTimer = 0
67
Object.CrunchersSprite++
68
Object.CrunchersSprite &= 3
69
switch Object.CrunchersSprite
70
case 0
71
// Crunchers are 2x2 tiles, each tile unique,
72
// so 4 tiles need to be updated in order to completely change their sprite
73
Copy16x16Tile(76, 496)
74
Copy16x16Tile(77, 497)
75
Copy16x16Tile(82, 500)
76
Copy16x16Tile(83, 501)
77
break
78
79
case 1
80
Copy16x16Tile(76, 498)
81
Copy16x16Tile(77, 499)
82
Copy16x16Tile(82, 502)
83
Copy16x16Tile(83, 503)
84
break
85
86
case 2
87
Copy16x16Tile(76, 504)
88
Copy16x16Tile(77, 505)
89
Copy16x16Tile(82, 508)
90
Copy16x16Tile(83, 509)
91
break
92
93
case 3
94
Copy16x16Tile(76, 506)
95
Copy16x16Tile(77, 507)
96
Copy16x16Tile(82, 510)
97
Copy16x16Tile(83, 511)
98
break
99
100
end switch
101
end if
102
103
// Find the difference from the last and current scroll pos
104
105
TempValue1 = Object.PrevAngle
106
TempValue2 = TileLayer[0].Angle
107
108
// Acount for looping before doing the actual calculations
109
if TempValue1 < TempValue2
110
TempValue3 = TempValue2
111
TempValue3 -= TempValue1
112
if TempValue3 > 256
113
TempValue1 += 512
114
end if
115
else
116
TempValue3 = TempValue1
117
TempValue3 -= TempValue2
118
if TempValue3 > 256
119
TempValue2 += 512
120
end if
121
end if
122
123
// The actual finding of the difference
124
TempValue0 = TempValue1
125
TempValue0 -= TempValue2
126
127
// Store the current scroll pos for use next frame
128
Object.PrevAngle = TileLayer[0].Angle
129
130
// Move the other BG layers based on the difference found
131
132
TempValue1 = 0x10000
133
TempValue2 = 0x20000
134
135
TempValue1 *= TempValue0
136
137
HParallax[0].ScrollPos += TempValue1
138
139
TempValue2 *= TempValue0
140
HParallax[2].ScrollPos += TempValue2
141
142
// Make it only move 96 pixels max, otherwise wrap around
143
HParallax[2].ScrollPos %= 0x600000
144
145
// And move the third layer to match
146
HParallax[3].ScrollPos = HParallax[2].ScrollPos
147
HParallax[3].ScrollPos >>= 16
148
149
// Now, update the pseudo-3d-ness of the BG red bars using deformation
150
// Process is done from the bottom of the screen -> upwards
151
152
// - ArrayPos0 is the current line, starting off as the number of lines to change
153
// - TempValue2 is the starting offset
154
// - TempValue3 gets applied to the offset after every line in order to make the top of the screen move less drastically to the bottom
155
156
ArrayPos0 = 128
157
TempValue2 = 0x4000
158
TempValue3 = 0
159
while ArrayPos0 > -1
160
TempValue4 = HParallax[3].ScrollPos
161
TempValue4 *= TempValue2
162
163
// Shift it by different amounts depending on the current renderer
164
// 14 is used for when using Software Rendering, 10 is used for Hardware
165
// Do note - swapping them around WILL crash the game!
166
// These values must've been picked with great care in order for that to happen
167
168
#platform: HW_Rendering
169
TempValue4 >>= 10
170
#endplatform
171
172
#platform: SW_Rendering
173
TempValue4 >>= 14
174
#endplatform
175
176
Stage.DeformationData2[ArrayPos0] = TempValue4
177
TempValue2 -= TempValue3
178
TempValue3++
179
180
ArrayPos0--
181
loop
182
183
#platform: HW_Rendering
184
// If using the hardware render, draw the BG as a sprite & rect here
185
186
DrawSpriteScreenFX(0, FX_SCALE, 0, 0)
187
188
// Draw a black rectagle across the screen
189
DrawRect(296, 0, 256, 128, 0, 0, 0, 255)
190
#endplatform
191
192
end sub
193
194
195
sub ObjectStartup
196
197
// Set the stage's bounds
198
Stage.XBoundary1 = 0x3000000 // left bounds @ 768 pixels
199
Stage.XBoundary2 = 0xD000000 // right bounds @ 3328 pixels
200
Stage.YBoundary1 = 0x3000000 // upper bounds @ 768 pixels
201
Stage.YBoundary2 = 0xD000000 // lower bounds @ 3328 pixels
202
203
#platform: HW_Rendering
204
// If needed, do some setup for hardware rendering
205
LoadSpriteSheet("Special/SSMap5.gif")
206
207
// Seems to be a random patch in the middle of nowhere?
208
SpriteFrame(0, 0, 32, 48, 107, 384)
209
#endplatform
210
211
// Set starting scroll positions
212
213
// Make the first parallax layer start at 176 pixels from its base position
214
HParallax[0].ScrollPos = 0xB00000
215
216
// Set the other starting scroll position, but with respect to the screen's size to make it start in the right place
217
TempValue0 = Screen.XSize
218
TempValue0 -= 320
219
TempValue0 <<= 15
220
221
// Base position of 96 pixels
222
HParallax[1].ScrollPos = 0x600000
223
224
// And then subtract from that as needed
225
HParallax[1].ScrollPos -= TempValue0
226
227
// Setup all BGEffect objects in the level
228
ArrayPos0 = 32
229
while ArrayPos0 < 1056
230
if Object[ArrayPos0].Type == TypeName[BGEffects]
231
232
// Make it always active
233
Object[ArrayPos0].Priority = PRIORITY_ACTIVE
234
235
// It should the first object to have its draw code run
236
Object[ArrayPos0].DrawOrder = 0
237
238
// Set the starting angle... but why is this 192? All other ones are 368 instead...
239
Object[ArrayPos0].PrevAngle = 192
240
241
// Set the scale for the object to draw at
242
// (Only used for hardware rendering)
243
Object[ArrayPos0].Scale = 1536
244
245
end if
246
247
ArrayPos0++
248
loop
249
250
end sub
251
252
253
// ========================
254
// Editor Subs
255
// ========================
256
257
sub RSDKDraw
258
DrawSprite(0)
259
end sub
260
261
262
sub RSDKLoad
263
LoadSpriteSheet("Special/SSMap5.gif")
264
SpriteFrame(-256, -256, 512, 512, 0, 0)
265
266
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
267
end sub
268
269