Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/Special/HWBackG_S1.txt
1319 views
1
//---------------Sonic CD HW Background Script----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Do note, even if the Object's name implies that it's only to be used in HW mode,
6
// it always gets used, even in SW mode!
7
8
// Aliases
9
#alias Object.Value0 : Object.Timer
10
11
// These pair of values correspond to X coordinates on the sprite sheet
12
#alias Object.Value1 : Object.SpriteL
13
#alias Object.Value2 : Object.SpriteR
14
15
// These pair of values correspond to Y coodinates on the sprite sheet
16
// Value4 - SpriteB - is unused
17
#alias Object.Value3 : Object.SpriteT
18
#alias Object.Value4 : Object.SpriteB
19
20
// Oscillating value from 0 to 1023, used to determine the base X position/angle for the background
21
#alias Object.Value5 : Object.Oscillation
22
23
// The following values were changed between initial release and the current release
24
// -> The gist of it is, an extra face was added to smooth things out so some other
25
// stuff had to be adjusted accordingly too
26
27
// How many Faces & Vertexes there are in the Object
28
// Originally 5 and 20, respectivly, though one update changed it to make it a bit larger instead
29
#alias 6 : HWBACK_FACECOUNT
30
#alias 24 : HWBACK_VERTEXCOUNT
31
32
// The Offset used when wrapping around from the upper half to lower half Vertexes
33
// Similarly to the above, this was 15 before this object got updated
34
#alias 19 : HWBACK_VERTEXOFFSET
35
36
// Priority
37
#alias 1 : PRIORITY_ACTIVE
38
39
// Face Buffer Flags
40
#alias 1 : FACE_FLAG_TEXTURED_2D
41
42
43
sub ObjectDraw
44
Object.Timer++
45
if Object.Timer > 5
46
Object.Timer = 0
47
48
Object.Frame++
49
Object.Frame &= 31
50
51
// As needed, switch the current Palette to another one if needed
52
// Palette banks 0 and 1 are inverse of each other, for the background aspects, where
53
// red becomes blue and vise-versa
54
if Object.Frame > 15
55
SetActivePalette(1, 0, Screen.YSize)
56
else
57
SetActivePalette(0, 0, Screen.YSize)
58
end if
59
60
// Update the left bounds for the sprite to use
61
Object.SpriteL = Object.Frame
62
Object.SpriteL &= 3
63
Object.SpriteL <<= 7
64
65
// Each sprite is 128 pixels wide, so just take the left bounds and
66
// add 127 to that to get to the other side
67
Object.SpriteR = Object.SpriteL
68
Object.SpriteR += 127
69
70
// Also find the top bounds for the sprite to use
71
Object.SpriteT = Object.Frame
72
Object.SpriteT &= 15
73
Object.SpriteT >>= 2
74
Object.SpriteT <<= 7
75
76
// And then similarly, since the sprite is 128 pixels tall,
77
// just add 127 to the top bounds to get the bottom bounds
78
Object.SpriteB = Object.SpriteT
79
Object.SpriteB += 127
80
end if
81
82
// Update the Oscillation value, over a range of 1024
83
Object.Oscillation++
84
Object.Oscillation &= 1023
85
86
// Round down the Oscillation value to range from an angle of 0 through 511
87
TempValue4 = Object.Oscillation
88
TempValue4 >>= 1
89
90
// Get the base sprite Top for the following vertexes to use
91
TempValue1 = Object.SpriteT
92
93
// Starat from Vertex 0, in accordance to what was set to the Faces in ObjectStartup
94
ArrayPos0 = 0
95
96
// Get the value for the top of the vertexes to follow
97
Sin(TempValue3, TempValue4)
98
TempValue3 >>= 2
99
TempValue3 -= 128
100
101
// Inverse that value for the bottom of the vertexes to use
102
TempValue4 += 256
103
TempValue4 &= 511
104
105
// And now, update all the vertexes
106
107
// Vertex 0, top left of the first (top left rectangle)
108
VertexBuffer[ArrayPos0].u = Object.SpriteL
109
VertexBuffer[ArrayPos0].v = TempValue1
110
VertexBuffer[ArrayPos0].x = TempValue3
111
ArrayPos0++
112
113
// Move the X
114
TempValue3 += 128
115
116
// Vertex 1, top right of the first face (top left rectangle)
117
VertexBuffer[ArrayPos0].u = Object.SpriteR
118
VertexBuffer[ArrayPos0].v = TempValue1
119
VertexBuffer[ArrayPos0].x = TempValue3
120
ArrayPos0 += 3
121
122
// Vertex 4, top left of the second face
123
VertexBuffer[ArrayPos0].u = Object.SpriteL
124
VertexBuffer[ArrayPos0].v = TempValue1
125
VertexBuffer[ArrayPos0].x = TempValue3
126
ArrayPos0++
127
128
TempValue3 += 128
129
130
// Vertex 5, top right of the second face
131
VertexBuffer[ArrayPos0].u = Object.SpriteR
132
VertexBuffer[ArrayPos0].v = TempValue1
133
VertexBuffer[ArrayPos0].x = TempValue3
134
ArrayPos0 += 3
135
136
// Vertex 8, top left of the third face
137
VertexBuffer[ArrayPos0].u = Object.SpriteL
138
VertexBuffer[ArrayPos0].v = TempValue1
139
VertexBuffer[ArrayPos0].x = TempValue3
140
ArrayPos0++
141
142
TempValue3 += 128
143
144
// Vertex 9, top right of the third face
145
VertexBuffer[ArrayPos0].u = Object.SpriteR
146
VertexBuffer[ArrayPos0].v = TempValue1
147
VertexBuffer[ArrayPos0].x = TempValue3
148
ArrayPos0 += 3
149
150
// Vertex 12, top left of the fourth face
151
VertexBuffer[ArrayPos0].u = Object.SpriteL
152
VertexBuffer[ArrayPos0].v = TempValue1
153
VertexBuffer[ArrayPos0].x = TempValue3
154
ArrayPos0++
155
156
TempValue3 += 128
157
158
// Vertex 13, top right of the foruth face
159
VertexBuffer[ArrayPos0].u = Object.SpriteR
160
VertexBuffer[ArrayPos0].v = TempValue1
161
VertexBuffer[ArrayPos0].x = TempValue3
162
ArrayPos0 += 3
163
164
// Vertex 16, top left of the fifth face
165
VertexBuffer[ArrayPos0].u = Object.SpriteL
166
VertexBuffer[ArrayPos0].v = TempValue1
167
VertexBuffer[ArrayPos0].x = TempValue3
168
ArrayPos0++
169
170
TempValue3 += 128
171
172
// Vertex 17, top right of the fifth face
173
VertexBuffer[ArrayPos0].u = Object.SpriteR
174
VertexBuffer[ArrayPos0].v = TempValue1
175
VertexBuffer[ArrayPos0].x = TempValue3
176
177
// The following is for the sixth face, which isn't in the Steam version
178
179
ArrayPos0 += 3
180
181
// Vertex 20, top left of the sixth face
182
VertexBuffer[ArrayPos0].u = Object.SpriteL
183
VertexBuffer[ArrayPos0].v = TempValue1
184
VertexBuffer[ArrayPos0].x = TempValue3
185
ArrayPos0++
186
187
TempValue3 += 128
188
189
// Vertex 21, top right of the sixth face
190
VertexBuffer[ArrayPos0].u = Object.SpriteR
191
VertexBuffer[ArrayPos0].v = TempValue1
192
VertexBuffer[ArrayPos0].x = TempValue3
193
194
// And now, go back as needed to reach the vertexes for the bottom of the faces
195
ArrayPos0 -= HWBACK_VERTEXOFFSET
196
197
// Move the sprite Y position to now be at the actual bottom of the sprite
198
// (This is gonna make it SpriteB, essentially)
199
TempValue1 += 128
200
201
// Get the new, inverted x position
202
// -> TempValue4 was inverted above already
203
Sin(TempValue3, TempValue4)
204
TempValue3 >>= 2
205
TempValue3 -= 128
206
207
// Vertex 2, bottom left of the first face
208
VertexBuffer[ArrayPos0].u = Object.SpriteL
209
VertexBuffer[ArrayPos0].v = TempValue1
210
VertexBuffer[ArrayPos0].x = TempValue3
211
ArrayPos0++
212
213
TempValue3 += 128
214
215
// Vertex 3, bottom right of the first face
216
VertexBuffer[ArrayPos0].u = Object.SpriteR
217
VertexBuffer[ArrayPos0].v = TempValue1
218
VertexBuffer[ArrayPos0].x = TempValue3
219
ArrayPos0 += 3
220
221
// Vertex 6, bottom left of the second face
222
VertexBuffer[ArrayPos0].u = Object.SpriteL
223
VertexBuffer[ArrayPos0].v = TempValue1
224
VertexBuffer[ArrayPos0].x = TempValue3
225
ArrayPos0++
226
227
TempValue3 += 128
228
229
// Vertex 7, bottom right of the second face
230
VertexBuffer[ArrayPos0].u = Object.SpriteR
231
VertexBuffer[ArrayPos0].v = TempValue1
232
VertexBuffer[ArrayPos0].x = TempValue3
233
ArrayPos0 += 3
234
235
// Vertex 10, bottom left of the third face
236
VertexBuffer[ArrayPos0].u = Object.SpriteL
237
VertexBuffer[ArrayPos0].v = TempValue1
238
VertexBuffer[ArrayPos0].x = TempValue3
239
ArrayPos0++
240
241
TempValue3 += 128
242
243
// Vertex 11, bottom right of the third face
244
VertexBuffer[ArrayPos0].u = Object.SpriteR
245
VertexBuffer[ArrayPos0].v = TempValue1
246
VertexBuffer[ArrayPos0].x = TempValue3
247
ArrayPos0 += 3
248
249
// Vertex 14, bottom left of the fourth face
250
VertexBuffer[ArrayPos0].u = Object.SpriteL
251
VertexBuffer[ArrayPos0].v = TempValue1
252
VertexBuffer[ArrayPos0].x = TempValue3
253
ArrayPos0++
254
255
TempValue3 += 128
256
257
// Vertex 15, bottom right of the fourth face
258
VertexBuffer[ArrayPos0].u = Object.SpriteR
259
VertexBuffer[ArrayPos0].v = TempValue1
260
VertexBuffer[ArrayPos0].x = TempValue3
261
ArrayPos0 += 3
262
263
// Vertex 18, bottom left of the fifth face
264
VertexBuffer[ArrayPos0].u = Object.SpriteL
265
VertexBuffer[ArrayPos0].v = TempValue1
266
VertexBuffer[ArrayPos0].x = TempValue3
267
ArrayPos0++
268
269
TempValue3 += 128
270
271
// Vertex 19, bottom right of the fifth face
272
VertexBuffer[ArrayPos0].u = Object.SpriteR
273
VertexBuffer[ArrayPos0].v = TempValue1
274
VertexBuffer[ArrayPos0].x = TempValue3
275
276
// Extra sixth face, not in the original Steam release
277
278
ArrayPos0 += 3
279
280
// Vertex 22, bottom left of the sixth face
281
VertexBuffer[ArrayPos0].u = Object.SpriteL
282
VertexBuffer[ArrayPos0].v = TempValue1
283
VertexBuffer[ArrayPos0].x = TempValue3
284
ArrayPos0++
285
286
TempValue3 += 128
287
288
// Vertex 23, bottom right of the sixth face
289
VertexBuffer[ArrayPos0].u = Object.SpriteR
290
VertexBuffer[ArrayPos0].v = TempValue1
291
VertexBuffer[ArrayPos0].x = TempValue3
292
293
// And now, set the number of faces and vertexes as needed, so that
294
// the 3d Scene draw function will know how many things to draw
295
3DScene.NoVertices = HWBACK_VERTEXCOUNT
296
3DScene.NoFaces = HWBACK_FACECOUNT
297
298
Draw3DScene()
299
300
end sub
301
302
303
sub ObjectStartup
304
305
// Reset the 3d stuff to be normal
306
MatrixTranslateXYZ(MAT_WORLD, 0, 0, 0)
307
MatrixTranslateXYZ(MAT_VIEW, 0, 0, 0)
308
309
// Turn the background into the version with only the water, without the wave background
310
Stage.ActiveLayer[0] = 3
311
312
LoadSpriteSheet("Special/SSBG1.gif")
313
314
// Place an HW Background Object into the scene, in the last of the Reserved Object Slots
315
// This happens, regardless of if the game is in SW or HW render mode, despite the Object's name
316
Object[31].Type = TypeName[HW Background]
317
318
// Make it always active, so that it constantly runs
319
Object[31].Priority = PRIORITY_ACTIVE
320
321
// This is a Background, so make it draw as one of course
322
Object[31].DrawOrder = 0
323
324
// Set initial sprite bounds
325
// SpriteB is never referenced much, but set it here anyway
326
Object[31].SpriteL = 0
327
Object[31].SpriteR = 128
328
Object[31].SpriteT = 0
329
Object[31].SpriteB = 128
330
331
ArrayPos0 = 0
332
TempValue0 = 0
333
334
// Setup all the Faces for the background
335
while ArrayPos0 < HWBACK_FACECOUNT
336
337
// Set the Face's corners
338
// TempValue0 corresponds to a VertexBuffer ID
339
FaceBuffer[ArrayPos0].a = TempValue0
340
TempValue0++
341
FaceBuffer[ArrayPos0].b = TempValue0
342
TempValue0++
343
FaceBuffer[ArrayPos0].c = TempValue0
344
TempValue0++
345
FaceBuffer[ArrayPos0].d = TempValue0
346
TempValue0++
347
348
FaceBuffer[ArrayPos0].Flag = FACE_FLAG_TEXTURED_2D
349
350
// Move onto the next Face
351
352
ArrayPos0++
353
loop
354
355
// Set all Vertexes to have a z value of 1
356
// -> This doesn't matter too much really, as 2D Faces don't use the z value
357
ArrayPos0 = 0
358
while ArrayPos0 < HWBACK_VERTEXCOUNT
359
VertexBuffer[ArrayPos0].z = 1
360
ArrayPos0++
361
loop
362
363
// Set all the y positions for all the vertexes
364
365
TempValue0 = 0
366
ArrayPos0 = 0
367
while TempValue0 < 128
368
369
// First, set up all the upper vertexes, with a y value of 0
370
371
// First face
372
VertexBuffer[ArrayPos0].y = TempValue0
373
ArrayPos0++
374
VertexBuffer[ArrayPos0].y = TempValue0
375
ArrayPos0 += 3
376
377
// Second face
378
VertexBuffer[ArrayPos0].y = TempValue0
379
ArrayPos0++
380
VertexBuffer[ArrayPos0].y = TempValue0
381
ArrayPos0 += 3
382
383
// Third face
384
VertexBuffer[ArrayPos0].y = TempValue0
385
ArrayPos0++
386
VertexBuffer[ArrayPos0].y = TempValue0
387
ArrayPos0 += 3
388
389
// Fourth face
390
VertexBuffer[ArrayPos0].y = TempValue0
391
ArrayPos0++
392
VertexBuffer[ArrayPos0].y = TempValue0
393
ArrayPos0 += 3
394
395
// Fifth face
396
VertexBuffer[ArrayPos0].y = TempValue0
397
ArrayPos0++
398
VertexBuffer[ArrayPos0].y = TempValue0
399
400
// Extra Sixth face
401
ArrayPos0 += 3
402
VertexBuffer[ArrayPos0].y = TempValue0
403
ArrayPos0++
404
VertexBuffer[ArrayPos0].y = TempValue0
405
406
// Loop back to the lower half vertexes
407
ArrayPos0 -= HWBACK_VERTEXOFFSET
408
409
// Each vertex should be 128 pixels tall
410
TempValue0 += 128
411
412
// First face
413
VertexBuffer[ArrayPos0].y = TempValue0
414
ArrayPos0++
415
VertexBuffer[ArrayPos0].y = TempValue0
416
ArrayPos0 += 3
417
418
// Second face
419
VertexBuffer[ArrayPos0].y = TempValue0
420
ArrayPos0++
421
VertexBuffer[ArrayPos0].y = TempValue0
422
ArrayPos0 += 3
423
424
// Third face
425
VertexBuffer[ArrayPos0].y = TempValue0
426
ArrayPos0++
427
VertexBuffer[ArrayPos0].y = TempValue0
428
ArrayPos0 += 3
429
430
// Fourth face
431
VertexBuffer[ArrayPos0].y = TempValue0
432
ArrayPos0++
433
VertexBuffer[ArrayPos0].y = TempValue0
434
ArrayPos0 += 3
435
436
// Fifth face
437
VertexBuffer[ArrayPos0].y = TempValue0
438
ArrayPos0++
439
VertexBuffer[ArrayPos0].y = TempValue0
440
441
// Extra, sixth face
442
ArrayPos0 += 3
443
VertexBuffer[ArrayPos0].y = TempValue0
444
ArrayPos0++
445
VertexBuffer[ArrayPos0].y = TempValue0
446
447
ArrayPos0++
448
449
// Setup the alternate palette
450
451
// First, copy the current entire palette bank 0 over to palette bank 1
452
CopyPalette(0, 1)
453
454
// And now, load 32 colors from the external palette cycle file into
455
// palette bank 1, starting from slot 208
456
LoadPalette("SS1H_PalCycle.act", 1, 208, 0, 32)
457
loop
458
459
end sub
460
461
462
// ========================
463
// Editor Subs
464
// ========================
465
466
sub RSDKDraw
467
DrawSprite(0)
468
end sub
469
470
471
sub RSDKLoad
472
LoadSpriteSheet("Special/SSBG1.gif")
473
SpriteFrame(-32, -32, 64, 64, 1, 143)
474
475
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
476
end sub
477
478