Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Special/BGEffects_S4.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 throughout 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, with 8 unique tiles in them, so
28
// 8 tiles need to be updated to change the entire sprite
29
Copy16x16Tile(328, 484)
30
Copy16x16Tile(329, 485)
31
Copy16x16Tile(330, 486)
32
Copy16x16Tile(331, 487)
33
Copy16x16Tile(332, 488)
34
Copy16x16Tile(333, 489)
35
Copy16x16Tile(334, 490)
36
Copy16x16Tile(335, 491)
37
break
38
39
case 1
40
Copy16x16Tile(328, 492)
41
Copy16x16Tile(329, 493)
42
Copy16x16Tile(330, 494)
43
Copy16x16Tile(331, 495)
44
Copy16x16Tile(332, 496)
45
Copy16x16Tile(333, 497)
46
Copy16x16Tile(334, 498)
47
Copy16x16Tile(335, 499)
48
break
49
50
case 2
51
Copy16x16Tile(328, 500)
52
Copy16x16Tile(329, 501)
53
Copy16x16Tile(330, 502)
54
Copy16x16Tile(331, 503)
55
Copy16x16Tile(332, 504)
56
Copy16x16Tile(333, 505)
57
Copy16x16Tile(334, 506)
58
Copy16x16Tile(335, 507)
59
break
60
61
end switch
62
end if
63
64
// Animate the palettes
65
Object.AnimationTimer++
66
if Object.AnimationTimer > 7
67
Object.AnimationTimer = 0
68
Object.ActivePalette++
69
Object.ActivePalette &= 3
70
SetActivePalette(Object.ActivePalette, 0, Screen.YSize)
71
end if
72
73
// Animate the Crunchers throughout the level
74
Object.CrunchersTimer++
75
if Object.CrunchersTimer > 5
76
Object.CrunchersTimer = 0
77
Object.CrunchersSprite++
78
Object.CrunchersSprite &= 3
79
switch Object.CrunchersSprite
80
case 0
81
// Crunchers are 2x2 tiles, so 4 tiles need to be updated
82
// in order to completely change their sprite
83
Copy16x16Tile(134, 508)
84
Copy16x16Tile(135, 509)
85
Copy16x16Tile(136, 512)
86
Copy16x16Tile(137, 513)
87
break
88
89
case 1
90
Copy16x16Tile(134, 510)
91
Copy16x16Tile(135, 511)
92
Copy16x16Tile(136, 514)
93
Copy16x16Tile(137, 515)
94
break
95
96
case 2
97
Copy16x16Tile(134, 516)
98
Copy16x16Tile(135, 517)
99
Copy16x16Tile(136, 520)
100
Copy16x16Tile(137, 521)
101
break
102
103
case 3
104
Copy16x16Tile(134, 518)
105
Copy16x16Tile(135, 519)
106
Copy16x16Tile(136, 522)
107
Copy16x16Tile(137, 523)
108
break
109
110
end switch
111
end if
112
113
// Find the difference between the current scoll position and the last scroll position
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
TempValue1 += 512
122
end if
123
else
124
TempValue3 = TempValue1
125
TempValue3 -= TempValue2
126
if TempValue3 > 256
127
TempValue2 += 512
128
end if
129
end if
130
131
TempValue0 = TempValue1
132
TempValue0 -= TempValue2
133
134
// Store the current angle for use next frame
135
Object.PrevAngle = TileLayer[0].Angle
136
137
// Scroll the BG in accordance with the difference from before
138
139
TempValue1 = 0x08000
140
TempValue2 = 0x10000
141
TempValue3 = 0x20000
142
143
TempValue1 *= TempValue0
144
TempValue2 *= TempValue0
145
TempValue3 *= TempValue0
146
147
HParallax[0].ScrollPos += TempValue1
148
HParallax[1].ScrollPos += TempValue2
149
HParallax[2].ScrollPos += TempValue3
150
151
end sub
152
153
154
sub ObjectStartup
155
156
// Set stage bounds
157
Stage.XBoundary1 = 0x3000000 // left bounds at 768 pixels
158
Stage.XBoundary2 = 0xD000000 // right bounds at 3328 pixels
159
Stage.YBoundary1 = 0x3800000 // upper bounds at 896 pixels
160
Stage.YBoundary2 = 0xC800000 // lower bounds at 3200 pixels
161
162
#platform: HW_Rendering
163
// Load the Special Stage map if needed for Hardware Rendering
164
165
LoadSpriteSheet("Special/SSMap4.gif")
166
#endplatform
167
168
// Setup all BGEffects in the level
169
ArrayPos0 = 32
170
while ArrayPos0 < 1056
171
if Object[ArrayPos0].Type == TypeName[BGEffects]
172
173
// Make the object always be run
174
Object[ArrayPos0].Priority = PRIORITY_ACTIVE
175
176
// The object should have its draw code run before others
177
Object[ArrayPos0].DrawOrder = 0
178
179
// Assuming Sonic's starting facing left, set the starting angle
180
Object[ArrayPos0].PrevAngle = 368
181
182
end if
183
184
ArrayPos0++
185
loop
186
187
// Setup the animated palettes
188
TempValue0 = 1
189
while TempValue0 < 4
190
RotatePalette(224, 227, true)
191
RotatePalette(240, 243, true)
192
CopyPalette(0, TempValue0)
193
TempValue0++
194
loop
195
196
// Rotate it one more time, to restore the palette to what it was originally
197
RotatePalette(224, 227, true)
198
RotatePalette(240, 243, true)
199
200
end sub
201
202
203
// ========================
204
// Editor Subs
205
// ========================
206
207
sub RSDKDraw
208
DrawSprite(0)
209
end sub
210
211
212
sub RSDKLoad
213
LoadSpriteSheet("Special/SSMap4.gif")
214
SpriteFrame(-256, -256, 512, 512, 0, 0)
215
216
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
217
end sub
218
219