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/Special/SpecialSetup.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Special Setup Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
private alias object.value0 : object.timer
13
private alias object.value1 : object.bgClr.r
14
private alias object.value2 : object.bgClr.g
15
private alias object.value3 : object.bgClr.b
16
private alias object.value4 : object.bgClr.a
17
18
// Player Aliases
19
private alias object.xpos : player.xpos
20
private alias object.ypos : player.ypos
21
private alias object.xvel : player.xvel
22
private alias object.yvel : player.yvel
23
private alias object.collisionLeft : player.collisionLeft
24
private alias object.collisionTop : player.collisionTop
25
private alias object.collisionRight : player.collisionRight
26
private alias object.collisionBottom : player.collisionBottom
27
28
private alias object.value11 : player.collisionFlags
29
30
// Game Modes
31
public alias 1 : MODE_SAVEGAME
32
public alias 2 : MODE_TIMEATTACK
33
34
// Tracks
35
private alias 0 : TRACK_STAGE
36
private alias 1 : TRACK_ACTFINISH
37
38
// Reserved object slots
39
private alias 0 : SLOT_PLAYER1
40
private alias 9 : SLOT_HUD
41
42
43
// ========================
44
// Function Declarations
45
// ========================
46
47
reserve function SpecialSetup_CopyAniTiles
48
reserve function SpecialSetup_ProcessHScroll
49
reserve function SpecialSetup_GetBlockPos
50
reserve function SpecialSetup_PlayerBlockCol
51
52
53
// ========================
54
// Static Values
55
// ========================
56
57
public value SpecialSetup_gemBlockTimer = 0
58
public value SpecialSetup_gemBlockBusy = 0
59
public value SpecialSetup_blockTimer = 0
60
61
62
// ========================
63
// Tables
64
// ========================
65
66
private table SpecialSetup_replay_attract_STK
67
0x00F00000, 0x00340000
68
0x00, 68
69
0x30, 1
70
0x20, 2
71
0x24, 25
72
0x04, 12
73
0x00, 8
74
0x08, 28
75
0x00, 53
76
0x30, 1
77
0x20, 30
78
0x28, 8
79
0x08, 2
80
0x00, 3
81
0x04, 35
82
0x00, 85
83
0x04, 21
84
0x00, 66
85
0x04, 19
86
0x00, 68
87
0x38, 1
88
0x28, 24
89
0x08, 20
90
0x38, 1
91
0x28, 12
92
0x08, 124
93
0x00, 73
94
0x08, 12
95
0x38, 1
96
0x28, 7
97
0x08, 6
98
0x00, 7
99
0x04, 31
100
0x00, 31
101
0x30, 1
102
0x20, 5
103
0x00, 30
104
0x08, 24
105
0x00, 21
106
0x38, 1
107
0x28, 8
108
0x08, 6
109
0x00, 17
110
0x08, 43
111
0x38, 1
112
0x28, 12
113
0x08, 27
114
end table
115
116
117
// ========================
118
// Function Definitions
119
// ========================
120
121
public function SpecialSetup_CopyAniTiles
122
temp0 = 0
123
while temp0 < 16
124
Copy16x16Tile(temp1, temp2)
125
temp1++
126
temp2++
127
temp0++
128
loop
129
end function
130
131
132
public function SpecialSetup_ProcessHScroll
133
temp0 = oscillation
134
temp0 <<= 1
135
Sin(hParallax[8].scrollPos, temp0)
136
hParallax[8].scrollPos <<= 10
137
138
temp0 = oscillation
139
temp0 <<= 2
140
Sin(hParallax[9].scrollPos, temp0)
141
hParallax[9].scrollPos <<= 9
142
143
temp0 = oscillation
144
temp0 <<= 1
145
temp0 += 256
146
Sin(hParallax[10].scrollPos, temp0)
147
hParallax[10].scrollPos <<= 11
148
149
temp0 = oscillation
150
temp0 <<= 2
151
temp0 += 128
152
Sin(hParallax[11].scrollPos, temp0)
153
hParallax[11].scrollPos <<= 9
154
end function
155
156
157
public function SpecialSetup_GetBlockPos
158
// This code is kinda hard to read, so here's what it'd look like in a more C-like syntax
159
// sx = (object.xpos - player[0].xpos) >> 8
160
// sy = (object.ypos - player[0].ypos) >> 8
161
// x = ((Sin(Player_stageRotation) * sx + Cos(Player_stageRotation) * sy) >> 1) + player[0].xpos
162
// y = ((Cos(Player_stageRotation) * sy - Sin(Player_stageRotation) * sx) >> 1) + player[0].ypos
163
164
temp2 = object.xpos
165
temp2 -= player[0].xpos
166
temp2 >>= 8
167
temp3 = object.ypos
168
temp3 -= player[0].ypos
169
temp3 >>= 8
170
171
Sin(temp4, Player_stageRotation)
172
temp4 *= temp3
173
Cos(temp5, Player_stageRotation)
174
temp5 *= temp2
175
temp0 = temp4
176
temp0 += temp5
177
temp0 >>= 1
178
temp0 += player[0].xpos
179
180
Cos(temp4, Player_stageRotation)
181
temp4 *= temp3
182
Sin(temp5, Player_stageRotation)
183
temp5 *= temp2
184
temp1 = temp4
185
temp1 -= temp5
186
temp1 >>= 1
187
temp1 += player[0].ypos
188
189
object.rotation = 512
190
object.rotation -= Player_stageRotation
191
end function
192
193
194
public function SpecialSetup_PlayerBlockCol
195
BoxCollisionTest(C_SOLID2, object.entityPos, -12, -12, 12, 12, 0, C_BOX, C_BOX, C_BOX, C_BOX)
196
if checkResult != COL_NONE
197
SetBit(player[0].collisionFlags, checkResult, true)
198
else
199
BoxCollisionTest(C_TOUCH, object.entityPos, -10, -10, 10, 10, 0, C_BOX, C_BOX, C_BOX, C_BOX)
200
if checkResult == true
201
temp0 = player[0].xvel
202
temp1 = player[0].yvel
203
Abs(temp0)
204
Abs(temp1)
205
206
if temp0 > temp1
207
if player[0].xvel > 0
208
SetBit(player[0].collisionFlags, 2, true)
209
player[0].xpos = player[0].collisionLeft
210
player[0].xpos -= 12
211
player[0].xpos <<= 16
212
else
213
SetBit(player[0].collisionFlags, 3, true)
214
player[0].xpos = player[0].collisionRight
215
player[0].xpos += 12
216
player[0].xpos <<= 16
217
end if
218
219
player[0].xpos += object.xpos
220
else
221
if player[0].yvel > 0
222
SetBit(player[0].collisionFlags, 1, true)
223
player[0].ypos = player[0].collisionTop
224
player[0].ypos -= 12
225
player[0].ypos <<= 16
226
else
227
SetBit(player[0].collisionFlags, 4, true)
228
player[0].ypos = player[0].collisionBottom
229
player[0].ypos += 12
230
player[0].ypos <<= 16
231
end if
232
233
player[0].ypos += object.ypos
234
end if
235
end if
236
end if
237
end function
238
239
240
// ========================
241
// Events
242
// ========================
243
244
event ObjectUpdate
245
if Player_rotateDir == 0
246
switch Player_rotateSpeed
247
case 0
248
temp0 = oscillation
249
temp0 &= 1
250
Player_stageRotation -= temp0
251
if Player_stageRotation < 0
252
Player_stageRotation += 512
253
end if
254
break
255
256
case 1
257
Player_stageRotation--
258
if Player_stageRotation < 0
259
Player_stageRotation += 512
260
end if
261
break
262
end switch
263
else
264
switch Player_rotateSpeed
265
case 0
266
temp0 = oscillation
267
temp0 &= 1
268
Player_stageRotation += temp0
269
Player_stageRotation &= 511
270
break
271
272
case 1
273
Player_stageRotation++
274
Player_stageRotation &= 511
275
break
276
end switch
277
end if
278
279
oscillation++
280
oscillation &= 511
281
SpecialSetup_gemBlockTimer++
282
SpecialSetup_gemBlockTimer %= 20
283
SpecialSetup_blockTimer++
284
SpecialSetup_blockTimer &= 63
285
286
// These aren't exactly the type of states that are in-depth and deserving of proper names so I hope you enjoy numbers
287
switch object.state
288
case 0
289
object.timer++
290
if object.timer == 8
291
object.timer = 0
292
object.bgClr.r = 0x00
293
object.bgClr.g = 0xA0
294
object.bgClr.b = 0xA0
295
object.bgClr.a = 0xFF
296
temp1 = 184
297
temp2 = 264
298
CallFunction(SpecialSetup_CopyAniTiles)
299
object.state++
300
end if
301
break
302
303
case 1
304
object.timer++
305
if object.timer == 4
306
object.timer = 0
307
object.bgClr.r = 0x00
308
object.bgClr.g = 0x60
309
object.bgClr.b = 0x80
310
object.bgClr.a = 0xFF
311
object.state++
312
end if
313
break
314
315
case 2
316
object.timer++
317
if object.timer == 4
318
object.timer = 0
319
object.bgClr.r = 0x00
320
object.bgClr.g = 0x40
321
object.bgClr.b = 0x60
322
object.bgClr.a = 0xFF
323
object.state++
324
end if
325
break
326
327
case 3
328
object.timer++
329
if object.timer == 4
330
object.timer = 0
331
object.bgClr.r = 0x00
332
object.bgClr.g = 0x00
333
object.bgClr.b = 0x40
334
object.bgClr.a = 0xFF
335
object.state++
336
end if
337
break
338
339
case 4
340
object.timer++
341
if object.timer == 4
342
object.timer = 0
343
stage.activeLayer[0] = 1
344
object.bgClr.r = 0x00
345
object.bgClr.g = 0x00
346
object.bgClr.b = 0x40
347
object.bgClr.a = 0xE0
348
temp1 = 104
349
temp2 = 136
350
CallFunction(SpecialSetup_CopyAniTiles)
351
object.state++
352
end if
353
break
354
355
case 5
356
if object.bgClr.a > 0x00
357
object.bgClr.a -= 0x10
358
end if
359
360
object.timer++
361
if object.timer == 8
362
object.timer = 0
363
temp1 = 104
364
temp2 = 152
365
CallFunction(SpecialSetup_CopyAniTiles)
366
object.state++
367
end if
368
break
369
370
case 6
371
if object.bgClr.a > 0x00
372
object.bgClr.a -= 0x10
373
end if
374
375
object.timer++
376
if object.timer == 8
377
object.timer = 0
378
stage.activeLayer[1] = 4
379
hParallax[0].scrollSpeed = -0x10000
380
object.state++
381
end if
382
break
383
384
case 7
385
object.timer++
386
if object.timer == 1020
387
object.timer = 0
388
stage.activeLayer[1] = 3
389
hParallax[0].scrollSpeed = 0
390
object.state++
391
end if
392
break
393
394
case 8
395
if object.bgClr.a < 0x00
396
object.bgClr.a += 0x10
397
end if
398
399
object.timer++
400
if object.timer == 8
401
object.timer = 0
402
403
temp1 = 104
404
temp2 = 136
405
CallFunction(SpecialSetup_CopyAniTiles)
406
object.state++
407
end if
408
break
409
410
case 9
411
if object.bgClr.a < 0x00
412
object.bgClr.a += 0x10
413
end if
414
415
object.timer++
416
if object.timer == 8
417
object.timer = 0
418
object.bgClr.r = 0x00
419
object.bgClr.g = 0x00
420
object.bgClr.b = 0x40
421
object.bgClr.a = 0xFF
422
temp1 = 104
423
temp2 = 120
424
CallFunction(SpecialSetup_CopyAniTiles)
425
object.state++
426
end if
427
break
428
429
case 10
430
object.timer++
431
if object.timer == 4
432
object.timer = 0
433
object.bgClr.r = 0x00
434
object.bgClr.g = 0x40
435
object.bgClr.b = 0x60
436
object.bgClr.a = 0xFF
437
object.state++
438
end if
439
break
440
441
case 11
442
object.timer++
443
if object.timer == 4
444
object.timer = 0
445
object.bgClr.r = 0x00
446
object.bgClr.g = 0x60
447
object.bgClr.b = 0x80
448
object.bgClr.a = 0xFF
449
object.state++
450
end if
451
break
452
453
case 12
454
object.timer++
455
if object.timer == 4
456
object.timer = 0
457
object.bgClr.r = 0x00
458
object.bgClr.g = 0xA0
459
object.bgClr.b = 0xA0
460
object.bgClr.a = 0xFF
461
object.state++
462
end if
463
break
464
465
case 13
466
object.timer++
467
if object.timer == 4
468
object.timer = 0
469
object.bgClr.a = 0x00
470
471
temp1 = 184
472
temp2 = 200
473
CallFunction(SpecialSetup_CopyAniTiles)
474
object.state++
475
end if
476
break
477
478
case 14
479
object.timer++
480
if object.timer == 8
481
object.timer = 0
482
object.bgClr.r = 0x60
483
object.bgClr.g = 0xC0
484
object.bgClr.b = 0x40
485
object.bgClr.a = 0xFF
486
temp1 = 104
487
temp2 = 264
488
CallFunction(SpecialSetup_CopyAniTiles)
489
object.state++
490
end if
491
break
492
493
case 15
494
object.timer++
495
if object.timer == 4
496
object.timer = 0
497
object.bgClr.r = 0x40
498
object.bgClr.g = 0x80
499
object.bgClr.b = 0x40
500
object.bgClr.a = 0xFF
501
object.state++
502
end if
503
break
504
505
case 16
506
object.timer++
507
if object.timer == 4
508
object.timer = 0
509
object.bgClr.r = 0x20
510
object.bgClr.g = 0x40
511
object.bgClr.b = 0x40
512
object.bgClr.a = 0xFF
513
object.state++
514
end if
515
break
516
517
case 17
518
object.timer++
519
if object.timer == 4
520
object.timer = 0
521
object.bgClr.r = 0x00
522
object.bgClr.g = 0x00
523
object.bgClr.b = 0x40
524
object.bgClr.a = 0xFF
525
object.state++
526
end if
527
break
528
529
case 18
530
object.timer++
531
if object.timer == 4
532
object.timer = 0
533
stage.activeLayer[0] = 2
534
object.bgClr.r = 0x00
535
object.bgClr.g = 0x00
536
object.bgClr.b = 0x40
537
object.bgClr.a = 0xE0
538
539
temp1 = 184
540
temp2 = 216
541
CallFunction(SpecialSetup_CopyAniTiles)
542
object.state++
543
end if
544
break
545
546
case 19
547
CallFunction(SpecialSetup_ProcessHScroll)
548
if object.bgClr.a > 0x00
549
object.bgClr.a -= 0x10
550
end if
551
552
object.timer++
553
if object.timer == 8
554
object.timer = 0
555
556
temp1 = 184
557
temp2 = 232
558
CallFunction(SpecialSetup_CopyAniTiles)
559
object.state++
560
end if
561
break
562
563
case 20
564
CallFunction(SpecialSetup_ProcessHScroll)
565
if object.bgClr.a > 0x00
566
object.bgClr.a -= 0x10
567
end if
568
569
object.timer++
570
if object.timer == 8
571
object.timer = 0
572
stage.activeLayer[1] = 5
573
hParallax[0].scrollSpeed = 0x10000
574
object.state++
575
end if
576
break
577
578
case 21
579
CallFunction(SpecialSetup_ProcessHScroll)
580
object.timer++
581
if object.timer == 1020
582
object.timer = 0
583
stage.activeLayer[1] = 3
584
hParallax[0].scrollSpeed = 0
585
object.state++
586
end if
587
break
588
589
case 22
590
CallFunction(SpecialSetup_ProcessHScroll)
591
if object.bgClr.a < 0x00
592
object.bgClr.a += 0x10
593
end if
594
595
object.timer++
596
if object.timer == 8
597
object.timer = 0
598
599
temp1 = 184
600
temp2 = 216
601
CallFunction(SpecialSetup_CopyAniTiles)
602
object.state++
603
end if
604
break
605
606
case 23
607
CallFunction(SpecialSetup_ProcessHScroll)
608
if object.bgClr.a < 0x00
609
object.bgClr.a += 0x10
610
end if
611
612
object.timer++
613
if object.timer == 8
614
object.timer = 0
615
object.bgClr.r = 0x00
616
object.bgClr.g = 0x00
617
object.bgClr.b = 0x40
618
object.bgClr.a = 0xFF
619
620
temp1 = 184
621
temp2 = 200
622
CallFunction(SpecialSetup_CopyAniTiles)
623
object.state++
624
end if
625
break
626
627
case 24
628
object.timer++
629
if object.timer == 4
630
object.timer = 0
631
object.bgClr.r = 0x20
632
object.bgClr.g = 0x40
633
object.bgClr.b = 0x40
634
object.bgClr.a = 0xFF
635
object.state++
636
end if
637
break
638
639
case 25
640
object.timer++
641
if object.timer == 4
642
object.timer = 0
643
object.bgClr.r = 0x40
644
object.bgClr.g = 0x80
645
object.bgClr.b = 0x40
646
object.bgClr.a = 0xFF
647
object.state++
648
end if
649
break
650
651
case 26
652
object.timer++
653
if object.timer == 4
654
object.timer = 0
655
object.bgClr.r = 0x60
656
object.bgClr.g = 0xC0
657
object.bgClr.b = 0x40
658
object.bgClr.a = 0xFF
659
object.state++
660
end if
661
break
662
663
case 27
664
object.timer++
665
if object.timer == 4
666
object.timer = 0
667
object.bgClr.a = 0x00
668
temp1 = 104
669
temp2 = 120
670
CallFunction(SpecialSetup_CopyAniTiles)
671
object.state = 0
672
end if
673
break
674
675
end switch
676
677
ringTimer++
678
if ringTimer == 4
679
ringTimer = 0
680
ringFrame++
681
ringFrame &= 7
682
end if
683
684
#platform: USE_ORIGINS
685
if game.coinMode != false
686
game.hudEnable = HUDENABLE_ON // There's no HUD in the Special Stage, even with this enabled. What's the point of this?
687
end if
688
#endplatform
689
end event
690
691
692
event ObjectDraw
693
screen.xoffset = player[0].xpos
694
screen.xoffset >>= 16
695
screen.xoffset -= screen.xcenter
696
697
screen.yoffset = player[0].ypos
698
screen.yoffset >>= 16
699
screen.yoffset -= 104
700
701
DrawRect(0, 0, screen.xsize, screen.ysize, object.bgClr.r, object.bgClr.g, object.bgClr.b, object.bgClr.a)
702
end event
703
704
705
event ObjectStartup
706
SetMusicTrack("Specialstage.ogg", TRACK_STAGE, true)
707
SetMusicTrack("ActComplete.ogg", TRACK_ACTFINISH, false)
708
709
if options.gameMode == MODE_TIMEATTACK
710
object[SLOT_HUD].type = TypeName[HUD]
711
object[SLOT_HUD].priority = PRIORITY_ACTIVE
712
object[SLOT_HUD].drawOrder = 6
713
714
// Wait huh, arrayPos0? Where'd that come from?
715
// This code might've just been copied from the standard Stage Setup code, where the HUD is set up within a foreach
716
object[SLOT_HUD].propertyValue = object[arrayPos0].propertyValue
717
718
#platform: USE_STANDALONE
719
stage.timeEnabled = true
720
#endplatform
721
end if
722
723
#platform: USE_ORIGINS
724
stage.timeEnabled = true
725
#endplatform
726
727
object[19].type = TypeName[Special Setup]
728
object[19].priority = PRIORITY_ACTIVE
729
object[19].drawOrder = 1
730
731
object[20].type = TypeName[Fade In]
732
object[20].priority = PRIORITY_ACTIVE
733
734
stage.activeLayer[0] = 9
735
stage.activeLayer[1] = 3
736
stage.activeLayer[2] = 9
737
stage.activeLayer[3] = 9
738
739
if options.attractMode == false
740
#platform: USE_ORIGINS
741
// This is likely "platform: STANDARD" instead, given how this condition was also in 2013, but technically we can't 100% confirm that...
742
stage.pauseEnabled = true
743
#endplatform
744
else
745
stage.pauseEnabled = false
746
options.touchControls = false
747
end if
748
749
ringExtraLife = 100
750
SpecialSetup_gemBlockTimer = 0
751
SpecialSetup_gemBlockBusy = false
752
SpecialSetup_blockTimer = 0
753
Player_rotateSpeed = 0
754
Player_rotateDir = 0
755
756
if options.attractMode == true
757
Player_attractTable = SpecialSetup_replay_attract_STK
758
Player_attractTableSize = 94
759
Player_attractDuration = 1200
760
CallFunction(Player_SetupAttractDemo)
761
end if
762
end event
763
764
765
// ========================
766
// Editor Events
767
// ========================
768
769
event RSDKDraw
770
DrawSprite(0)
771
end event
772
773
774
event RSDKLoad
775
LoadSpriteSheet("Global/Display.gif")
776
SpriteFrame(-16, -16, 32, 32, 1, 143)
777
778
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
779
end event
780
781