Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Special/BGEffects_S3.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
#alias Object.Value7 : Object.ActivePalette
13
14
// Priority
15
#alias 1 : PRIORITY_ACTIVE
16
17
18
sub ObjectDraw
19
// Animate the Fans in the level
20
Object.FansTimer++
21
if Object.FansTimer > 2
22
Object.FansTimer = 0
23
Object.FansSprite++
24
Object.FansSprite %= 3
25
switch Object.FansSprite
26
case 0
27
// Fans are 4x4 tiles, comprised of 8 unique tiles, so
28
// 8 individual tiles need to be updated to change the entire sprite
29
Copy16x16Tile(296, 520)
30
Copy16x16Tile(297, 521)
31
Copy16x16Tile(298, 522)
32
Copy16x16Tile(299, 523)
33
Copy16x16Tile(300, 524)
34
Copy16x16Tile(301, 525)
35
Copy16x16Tile(302, 526)
36
Copy16x16Tile(303, 527)
37
break
38
39
case 1
40
Copy16x16Tile(296, 528)
41
Copy16x16Tile(297, 529)
42
Copy16x16Tile(298, 530)
43
Copy16x16Tile(299, 531)
44
Copy16x16Tile(300, 532)
45
Copy16x16Tile(301, 533)
46
Copy16x16Tile(302, 534)
47
Copy16x16Tile(303, 535)
48
break
49
50
case 2
51
Copy16x16Tile(296, 536)
52
Copy16x16Tile(297, 537)
53
Copy16x16Tile(298, 538)
54
Copy16x16Tile(299, 539)
55
Copy16x16Tile(300, 540)
56
Copy16x16Tile(301, 541)
57
Copy16x16Tile(302, 542)
58
Copy16x16Tile(303, 543)
59
break
60
61
end switch
62
end if
63
64
// Animate the Crunchers in the level
65
Object.CrunchersTimer++
66
if Object.CrunchersTimer > 5
67
Object.CrunchersTimer = 0
68
Object.CrunchersSprite++
69
Object.CrunchersSprite &= 3
70
switch Object.CrunchersSprite
71
case 0
72
// Crunchers are 2x2 tiles, so 4 tiles need to be updated
73
// in order to completely change their sprite
74
Copy16x16Tile(189, 544)
75
Copy16x16Tile(190, 545)
76
Copy16x16Tile(191, 548)
77
Copy16x16Tile(192, 549)
78
break
79
80
case 1
81
Copy16x16Tile(189, 546)
82
Copy16x16Tile(190, 547)
83
Copy16x16Tile(191, 550)
84
Copy16x16Tile(192, 551)
85
break
86
87
case 2
88
Copy16x16Tile(189, 552)
89
Copy16x16Tile(190, 553)
90
Copy16x16Tile(191, 556)
91
Copy16x16Tile(192, 557)
92
break
93
94
case 3
95
Copy16x16Tile(189, 554)
96
Copy16x16Tile(190, 555)
97
Copy16x16Tile(191, 558)
98
Copy16x16Tile(192, 559)
99
break
100
101
end switch
102
end if
103
104
// Handle the palette animation
105
Object.AnimationTimer++
106
if Object.AnimationTimer > 7
107
Object.AnimationTimer = 0
108
Object.ActivePalette++
109
Object.ActivePalette &= 3
110
SetActivePalette(Object.ActivePalette, 0, Screen.YSize)
111
end if
112
113
// Find the difference between the current scroll pos and last scroll pos
114
TempValue1 = Object.PrevAngle
115
TempValue2 = TileLayer[0].Angle
116
117
if TempValue1 < TempValue2
118
TempValue3 = TempValue2
119
TempValue3 -= TempValue1
120
if TempValue3 > 256
121
// Account for looping
122
TempValue1 += 512
123
end if
124
else
125
TempValue3 = TempValue1
126
TempValue3 -= TempValue2
127
if TempValue3 > 256
128
// Account for looping
129
TempValue2 += 512
130
end if
131
end if
132
133
TempValue0 = TempValue1
134
TempValue0 -= TempValue2
135
136
// Store the current angle for calculations next frame
137
Object.PrevAngle = TileLayer[0].Angle
138
139
// Move the other BG layers in accordance with the difference found
140
141
TempValue1 = 0x40000
142
TempValue2 = 0x30000
143
TempValue3 = 0x10000
144
TempValue4 = 0x20000
145
146
TempValue1 *= TempValue0
147
TempValue2 *= TempValue0
148
TempValue3 *= TempValue0
149
TempValue4 *= TempValue0
150
151
HParallax[1].ScrollPos += TempValue1
152
HParallax[2].ScrollPos += TempValue2
153
HParallax[3].ScrollPos += TempValue3
154
HParallax[4].ScrollPos += TempValue4
155
156
end sub
157
158
159
sub ObjectStartup
160
161
// Set stage bounds
162
Stage.XBoundary1 = 0x3400000 // 832 pixels to the left
163
Stage.XBoundary2 = 0xCC00000 // 3264 pixels to the right
164
Stage.YBoundary1 = 0x3400000 // 832 pixels upwards
165
Stage.YBoundary2 = 0xCC00000 // 3264 pixels downwards
166
167
#platform: HW_Rendering
168
// Load the map sheet if needed for HW rendering
169
170
LoadSpriteSheet("Special/SSMap3.gif")
171
#endplatform
172
173
// Setup all BGEffects in the level
174
ArrayPos0 = 32
175
while ArrayPos0 < 1056
176
if Object[ArrayPos0].Type == TypeName[BGEffects]
177
178
// Set the object to always active
179
Object[ArrayPos0].Priority = PRIORITY_ACTIVE
180
181
// Make the object among the first to have its draw code be run
182
Object[ArrayPos0].DrawOrder = 0
183
184
// Set the starting angle
185
// (Assuming Sonic starts facing left)
186
Object[ArrayPos0].PrevAngle = 368
187
188
end if
189
190
ArrayPos0++
191
loop
192
193
// Setup the alternate palettes
194
TempValue0 = 1
195
while TempValue0 < 4
196
// Shift the palette a bit between loops
197
RotatePalette(202, 205, true)
198
CopyPalette(0, TempValue0)
199
TempValue0++
200
loop
201
202
// And shift it one last time, to restore the palette to what it was originally
203
RotatePalette(202, 205, true)
204
205
end sub
206
207
208
// ========================
209
// Editor Subs
210
// ========================
211
212
sub RSDKDraw
213
DrawSprite(0)
214
end sub
215
216
217
sub RSDKLoad
218
LoadSpriteSheet("Special/SSMap3.gif")
219
SpriteFrame(-256, -256, 512, 512, 0, 0)
220
221
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
222
end sub
223
224