Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/SBZ/SBZSetup.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: SBZ Setup Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
// value0 is inused
13
private alias object.value1 : object.processBG
14
15
private alias object.value2 : object.aniTilesTimerA
16
private alias object.value3 : object.aniTilesTimerB
17
18
private alias object.value4 : object.palRotateTimerAct1
19
20
private alias object.value5 : object.palTimerA
21
private alias object.value6 : object.palTimerB
22
private alias object.value7 : object.palTimerC
23
private alias object.value8 : object.palTimerD
24
private alias object.value9 : object.palTimerE
25
// value10 is unused
26
private alias object.value11 : object.palTimerF
27
private alias object.value12 : object.palTimerG
28
29
private alias object.value13 : object.palIndexA
30
private alias object.value14 : object.palIndexB
31
private alias object.value15 : object.palIndexC
32
private alias object.value16 : object.palIndexD
33
private alias object.value17 : object.palIndexE
34
// value18 is unused
35
private alias object.value19 : object.palIndexF
36
private alias object.value20 : object.palIndexG
37
38
// Tile Flag Aliases
39
private alias 1 : TILE_CONVEYORBELT
40
41
// Tile Info ID Aliases
42
private alias 1 : TILEINFO_DIRECTION
43
private alias 8 : TILEINFO_ANGLEB
44
45
// Tracks
46
private alias 0 : TRACK_STAGE
47
private alias 2 : TRACK_INVINCIBLE
48
49
// Reserved object slots
50
private alias 10 : SLOT_ZONESETUP
51
private alias 25 : SLOT_MUSICEVENT_CHANGE
52
53
private alias 2 : MUSICEVENT_TRANSITION
54
55
private alias 0 : MUSICEVENT_FLAG_NOCHANGE
56
private alias 1 : MUSICEVENT_FLAG_SPEEDUP
57
private alias 2 : MUSICEVENT_FLAG_SLOWDOWN
58
59
// Player Aliases
60
private alias object.xpos : player.xpos
61
private alias object.ypos : player.ypos
62
private alias object.gravity : player.gravity
63
private alias object.collisionLeft : player.collisionLeft
64
private alias object.collisionRight : player.collisionRight
65
private alias object.collisionBottom : player.collisionBottom
66
67
// Music Loops
68
private alias 1 : MUSIC_LOOP_SBZ
69
private alias 1 : MUSIC_LOOP_SBZ_F
70
71
private alias 84680 : MUSIC_LOOP_FINAL
72
73
private alias 39528 : MUSIC_LOOP_INV
74
private alias 30436 : MUSIC_LOOP_INV_F
75
76
77
// ========================
78
// Function Declarations
79
// ========================
80
81
reserve function SBZSetup_BGEffectsAct1
82
reserve function SBZSetup_BGEffectsAct2
83
reserve function SBZSetup_SpeedUpMusic
84
reserve function SBZSetup_SlowDownMusic
85
86
87
// ========================
88
// Static Values
89
// ========================
90
91
public value SBZSetup_electricOrbFrame = 0
92
public value SBZSetup_electricOrbTimer = 0
93
public value SBZSetup_platformTimer = 0
94
95
96
// ========================
97
// Tables
98
// ========================
99
100
private table SBZSetup_palTableB_1
101
0x404000, 0x00A0E0, 0x404000, 0x00A0E0, 0x80E000, 0x80E000, 0x404000, 0xE040E0
102
end table
103
104
private table SBZSetup_palTableC_1
105
0xE0E000, 0xE08000, 0xE00000, 0x800000, 0x800000, 0xE00000, 0xE08000, 0xE0E000
106
end table
107
108
private table SBZSetup_palTableD_1
109
0xA00000, 0xA00000, 0x800000, 0x600000, 0x400000, 0x400000, 0x600000, 0x800000
110
end table
111
112
private table SBZSetup_palTableE_1
113
0xE00000, 0xE00000, 0xA00000, 0x800000, 0x600000, 0x600000, 0x800000, 0xA00000
114
end table
115
116
private table SBZSetup_palTableB_2
117
0x60E0C0, 0x60E0C0, 0x40C0A0, 0x20A080, 0x008060, 0x008060, 0x20A080, 0x40C0A0
118
end table
119
120
private table SBZSetup_palTableF_1
121
0x00A0E0, 0x6080E0, 0xA060E0, 0xE040E0, 0xE08080, 0xE0A040, 0xE0C020, 0xE0E000
122
0xE0E000, 0xE0C020, 0xE0A040, 0xE08080, 0xE040E0, 0xA060E0, 0x6080E0, 0x00A0E0
123
end table
124
125
private table SBZSetup_palTableG_1
126
0x00A0E0, 0x00A0E0, 0x4060A0, 0xA04060, 0xE00000, 0xE00000, 0xA04060, 0x4060A0
127
end table
128
129
private table SBZSetup_electricOrbDelayTable
130
20, 3, 1, 2, 3, 3
131
20, 3, 1, 2, 3, 3
132
20, 3, 1, 2, 3, 3
133
20, 3, 1, 2, 3, 3
134
end table
135
136
private table SBZSetup_palTableA_1
137
0xE0A0E0, 0xE040E0, 0x800080
138
end table
139
140
private table SBZSetup_palTableA_2
141
0xE040E0, 0x800080, 0xE0A0E0
142
end table
143
144
private table SBZSetup_palTableA_3
145
0x800080, 0xE0A0E0, 0xE040E0
146
end table
147
148
private table SBZSetup_replay_credits_STK_2
149
0x15700000, 0x16C0000
150
0x00, 6
151
0x04, 194
152
0x00, 187
153
0x04, 35
154
0x00, 14
155
0x04, 10
156
0x00, 24
157
0x04, 29
158
0x00, 11
159
0x08, 198
160
end table
161
162
private table SBZSetup_replay_credits_STK_1
163
0x1B00000, 0x72C0000
164
0x00, 63
165
0x08, 18
166
0x00, 113
167
0x08, 46
168
0x38, 1
169
0x28, 7
170
0x08, 96
171
0x02, 47
172
0x00, 43
173
0x08, 34
174
0x38, 1
175
0x28, 16
176
0x20, 8
177
0x28, 55
178
end table
179
180
181
// ========================
182
// Function Definitions
183
// ========================
184
185
private function SBZSetup_BGEffectsAct1
186
if object.aniTilesTimerA < 65
187
temp0 = object.aniTilesTimerA
188
temp0 &= 7
189
if temp0 == 0
190
temp0 = object.aniTilesTimerA
191
temp0 &= 63
192
temp0 >>= 3
193
temp0 <<= 2
194
temp0 += 604
195
Copy16x16Tile(592, temp0)
196
temp0++
197
Copy16x16Tile(593, temp0)
198
temp0++
199
Copy16x16Tile(594, temp0)
200
end if
201
end if
202
object.aniTilesTimerA++
203
object.aniTilesTimerA %= 192
204
205
if object.aniTilesTimerB < 65
206
temp0 = object.aniTilesTimerB
207
temp0 &= 7
208
if temp0 == 0
209
temp0 = object.aniTilesTimerB
210
temp0 &= 63
211
temp0 >>= 3
212
temp0 <<= 2
213
temp0 += 604
214
Copy16x16Tile(596, temp0)
215
temp0++
216
Copy16x16Tile(597, temp0)
217
temp0++
218
Copy16x16Tile(598, temp0)
219
end if
220
end if
221
object.aniTilesTimerB++
222
object.aniTilesTimerB %= 144
223
224
object.palRotateTimerAct1++
225
if object.palRotateTimerAct1 == 2
226
object.palRotateTimerAct1 = 0
227
RotatePalette(0, 172, 174, true)
228
end if
229
230
object.palTimerD++
231
if object.palTimerD == 15
232
object.palTimerD = 0
233
object.palIndexD++
234
object.palIndexD &= 7
235
GetTableValue(temp0, object.palIndexD, SBZSetup_palTableD_1)
236
SetPaletteEntry(0, 183, temp0)
237
end if
238
239
object.palTimerE++
240
if object.palTimerE == 12
241
object.palTimerE = 0
242
object.palIndexE++
243
object.palIndexE &= 7
244
GetTableValue(temp0, object.palIndexE, SBZSetup_palTableE_1)
245
SetPaletteEntry(0, 184, temp0)
246
end if
247
248
object.palTimerF++
249
if object.palTimerF == 29
250
object.palTimerF = 0
251
object.palIndexF++
252
object.palIndexF &= 15
253
GetTableValue(temp0, object.palIndexF, SBZSetup_palTableF_1)
254
SetPaletteEntry(0, 191, temp0)
255
end if
256
end function
257
258
259
private function SBZSetup_BGEffectsAct2
260
RotatePalette(0, 172, 174, true)
261
262
object.palTimerG++
263
if object.palTimerG == 10
264
object.palTimerG = 0
265
object.palIndexG++
266
object.palIndexG &= 7
267
GetTableValue(temp0, object.palIndexG, SBZSetup_palTableG_1)
268
SetPaletteEntry(0, 184, temp0)
269
end if
270
271
// Process Conveyor Belts
272
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
273
if player[currentPlayer].gravity == 0
274
temp2 = player[currentPlayer].ypos
275
temp2 >>= 16
276
temp2 += player[currentPlayer].collisionBottom
277
temp2 += 2
278
temp1 = player[currentPlayer].xpos
279
temp1 >>= 16
280
temp1 += player[currentPlayer].collisionLeft
281
temp3 = 0
282
Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_ANGLEB)
283
if temp0 == TILE_CONVEYORBELT
284
Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_DIRECTION)
285
if temp0 == FLIP_NONE
286
temp3 += 0x20000
287
else
288
temp3 -= 0x20000
289
end if
290
end if
291
292
temp1 = player[currentPlayer].xpos
293
temp1 >>= 16
294
temp1 += player[currentPlayer].collisionRight
295
Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_ANGLEB)
296
if temp0 == TILE_CONVEYORBELT
297
Get16x16TileInfo(temp0, temp1, temp2, TILEINFO_DIRECTION)
298
if temp0 == FLIP_NONE
299
temp3 += 0x20000
300
if temp3 > 0x20000
301
temp3 = 0x20000
302
end if
303
else
304
temp3 -= 0x20000
305
if temp3 < -0x20000
306
temp3 = -0x20000
307
end if
308
end if
309
end if
310
311
player[currentPlayer].xpos += temp3
312
end if
313
next
314
end function
315
316
317
private function SBZSetup_SpeedUpMusic
318
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].type, TypeName[Music Event])
319
temp0 = checkResult
320
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].propertyValue, MUSICEVENT_TRANSITION)
321
temp0 &= checkResult
322
CheckEqual(stage.musicFlag, MUSICEVENT_FLAG_NOCHANGE)
323
temp0 &= checkResult
324
if temp0 == false
325
switch music.currentTrack
326
case TRACK_STAGE
327
SetMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV_F)
328
SwapMusicTrack("ScrapBrain_F.ogg", TRACK_STAGE, MUSIC_LOOP_SBZ_F, 8000)
329
break
330
331
case TRACK_INVINCIBLE
332
SetMusicTrack("ScrapBrain_F.ogg", TRACK_STAGE, MUSIC_LOOP_SBZ_F)
333
SwapMusicTrack("Invincibility_F.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV_F, 8000)
334
break
335
336
// While other stage setups have a `case TRACK_BOSS` here, SBZ doesn't need it because the boss music never plays there
337
end switch
338
else
339
stage.musicFlag = MUSICEVENT_FLAG_SPEEDUP
340
end if
341
end function
342
343
344
private function SBZSetup_SlowDownMusic
345
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].type, TypeName[Music Event])
346
temp0 = checkResult
347
CheckEqual(object[SLOT_MUSICEVENT_CHANGE].propertyValue, MUSICEVENT_TRANSITION)
348
temp0 &= checkResult
349
CheckEqual(stage.musicFlag, MUSICEVENT_FLAG_NOCHANGE)
350
temp0 &= checkResult
351
if temp0 == false
352
switch music.currentTrack
353
case TRACK_STAGE
354
SetMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV)
355
SwapMusicTrack("ScrapBrain.ogg", TRACK_STAGE, MUSIC_LOOP_SBZ, 12500)
356
break
357
358
case TRACK_INVINCIBLE
359
SetMusicTrack("ScrapBrain.ogg", TRACK_STAGE, MUSIC_LOOP_SBZ)
360
SwapMusicTrack("Invincibility.ogg", TRACK_INVINCIBLE, MUSIC_LOOP_INV, 12500)
361
break
362
363
// While other stage setups have a `case TRACK_BOSS` here, SBZ doesn't need it because the boss music never plays here
364
end switch
365
else
366
stage.musicFlag = MUSICEVENT_FLAG_SLOWDOWN
367
end if
368
end function
369
370
371
// ========================
372
// Events
373
// ========================
374
375
event ObjectUpdate
376
CallFunction(object.processBG)
377
378
SBZSetup_platformTimer++
379
if SBZSetup_electricOrbTimer > 1
380
SBZSetup_electricOrbTimer--
381
else
382
SBZSetup_electricOrbFrame++
383
SBZSetup_electricOrbFrame %= 24
384
GetTableValue(SBZSetup_electricOrbTimer, SBZSetup_electricOrbFrame, SBZSetup_electricOrbDelayTable)
385
end if
386
387
object.palTimerA++
388
if object.palTimerA == 4
389
object.palTimerA = 0
390
object.palIndexA++
391
object.palIndexA %= 3
392
GetTableValue(temp0, object.palIndexA, SBZSetup_palTableA_1)
393
SetPaletteEntry(0, 188, temp0)
394
GetTableValue(temp0, object.palIndexA, SBZSetup_palTableA_2)
395
SetPaletteEntry(0, 189, temp0)
396
GetTableValue(temp0, object.palIndexA, SBZSetup_palTableA_3)
397
SetPaletteEntry(0, 190, temp0)
398
end if
399
400
object.palTimerB++
401
if object.palTimerB == 8
402
object.palTimerB = 0
403
object.palIndexB++
404
object.palIndexB &= 7
405
GetTableValue(temp0, object.palIndexB, SBZSetup_palTableB_1)
406
SetPaletteEntry(0, 168, temp0)
407
GetTableValue(temp0, object.palIndexB, SBZSetup_palTableB_2)
408
SetPaletteEntry(0, 185, temp0)
409
end if
410
411
object.palTimerC++
412
if object.palTimerC == 14
413
object.palTimerC = 0
414
object.palIndexC++
415
object.palIndexC &= 7
416
GetTableValue(temp0, object.palIndexC, SBZSetup_palTableC_1)
417
SetPaletteEntry(0, 169, temp0)
418
end if
419
end event
420
421
422
event ObjectStartup
423
if stage.actNum < 5
424
// If in acts 1-4, then play the SBZ music
425
SetMusicTrack("ScrapBrain.ogg", TRACK_STAGE, MUSIC_LOOP_SBZ)
426
SpeedUpMusic = SBZSetup_SpeedUpMusic
427
SlowDownMusic = SBZSetup_SlowDownMusic
428
else
429
// Act 5, play the Final Zone music
430
SetMusicTrack("Final.ogg", TRACK_STAGE, MUSIC_LOOP_FINAL)
431
end if
432
433
// Cucky and Pocky are the animals that appear in Scrap Brain
434
animalType1 = TypeName[Cucky]
435
animalType2 = TypeName[Pocky]
436
437
object[SLOT_ZONESETUP].type = TypeName[SBZ Setup]
438
object[SLOT_ZONESETUP].priority = PRIORITY_ACTIVE
439
object[SLOT_ZONESETUP].drawOrder = 0
440
441
// Init aniTiles
442
Copy16x16Tile(592, 604)
443
Copy16x16Tile(593, 605)
444
Copy16x16Tile(594, 606)
445
Copy16x16Tile(596, 604)
446
Copy16x16Tile(597, 605)
447
Copy16x16Tile(598, 606)
448
449
// Use different palette cycles and such based on the act
450
switch stage.actNum
451
case 1
452
object[SLOT_ZONESETUP].processBG = SBZSetup_BGEffectsAct1
453
break
454
455
case 2
456
case 5 // Act 5 is Final Zone
457
SetPaletteEntry(0, 172, 0xC0E0E0)
458
SetPaletteEntry(0, 173, 0x60A0A0)
459
SetPaletteEntry(0, 174, 0x006060)
460
object[SLOT_ZONESETUP].processBG = SBZSetup_BGEffectsAct2
461
break
462
463
end switch
464
465
SBZSetup_electricOrbFrame = 0
466
GetTableValue(SBZSetup_electricOrbTimer, SBZSetup_electricOrbFrame, SBZSetup_electricOrbDelayTable)
467
468
if options.attractMode == true
469
if credits.screen == 6
470
Player_attractTable = SBZSetup_replay_credits_STK_2 // All Characters
471
Player_attractTableSize = 22
472
else
473
Player_attractTable = SBZSetup_replay_credits_STK_1 // All Characters
474
Player_attractTableSize = 30
475
end if
476
477
Player_attractDuration = 540
478
CallFunction(Player_SetupAttractDemo)
479
end if
480
end event
481
482
483
// ========================
484
// Editor Events
485
// ========================
486
487
event RSDKDraw
488
DrawSprite(0)
489
end event
490
491
492
event RSDKLoad
493
LoadSpriteSheet("Global/Display.gif")
494
SpriteFrame(-16, -16, 32, 32, 1, 143)
495
496
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
497
end event
498
499