Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/CBSwitch.txt
1319 views
1
//------------------Sonic CD CBSwitch Script------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Timer
7
#alias Object.Value1 : Object.PrevResult
8
9
// HUD Alias
10
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
11
12
// States
13
#alias 0 : CBSWITCH_POINTRIGHT_MAIN
14
#alias 4 : CBSWITCH_POINTRIGHT_START
15
#alias 5 : CBSWITCH_POINTRIGHT_TRANSITION
16
17
#alias 3 : CBSWITCH_POINTLEFT_MAIN
18
#alias 1 : CBSWITCH_POINTLEFT_START
19
#alias 2 : CBSWITCH_POINTLEFT_TRANSITION
20
21
// Stage SFX
22
#alias 3 : SFX_S_SWITCH
23
24
// Time Period Aliases
25
#alias 1 : TIME_PAST
26
27
28
sub ObjectPlayerInteraction
29
30
// Only do checks if the Player wasn't already in the Switch last frame
31
if Object.PrevResult == false
32
if Player.XPos > Object.XPos
33
PlayerObjectCollision(C_TOUCH, 0, -12, 16, 16)
34
35
// Regardless of what it is, store the current result for next frame
36
Object.PrevResult = CheckResult
37
38
// Now that it's been stored, take a look at the actual result
39
if CheckResult == true
40
switch Object.State
41
case CBSWITCH_POINTRIGHT_MAIN
42
case CBSWITCH_POINTLEFT_MAIN
43
PlayStageSfx(SFX_S_SWITCH, false)
44
45
#platform: Use_Haptics
46
HapticEffect(20, 0, 0, 0)
47
#endplatform
48
49
if ConveyorBelt_Flag == 0
50
ConveyorBelt_Flag = 3
51
Object.State = CBSWITCH_POINTLEFT_START
52
else
53
ConveyorBelt_Flag = 0
54
Object.State = CBSWITCH_POINTRIGHT_START
55
end if
56
break // not from the original scripts and unnecesary, but the syntax will look wrong otherwise
57
end switch
58
end if
59
else
60
PlayerObjectCollision(C_TOUCH, -16, -12, 0, 16)
61
62
// Store the result for next frame
63
Object.PrevResult = CheckResult
64
65
// And now look at the actual result
66
if CheckResult == true
67
switch Object.State
68
case CBSWITCH_POINTRIGHT_MAIN
69
case CBSWITCH_POINTLEFT_MAIN
70
PlayStageSfx(SFX_S_SWITCH, false)
71
72
#platform: Use_Haptics
73
HapticEffect(20, 0, 0, 0)
74
#endplatform
75
76
if ConveyorBelt_Flag == 0
77
ConveyorBelt_Flag = 3
78
Object.State = CBSWITCH_POINTLEFT_START
79
else
80
ConveyorBelt_Flag = 0
81
Object.State = CBSWITCH_POINTRIGHT_START
82
end if
83
84
break // not from the original scripts and unnecesary, but the syntax will look wrong otherwise
85
end switch
86
end if
87
end if
88
else
89
// The Player's still touched the Switch right after a, well, Switch
90
// so just hold and wait for them to move away
91
if Player.XPos > Object.XPos
92
PlayerObjectCollision(C_TOUCH, 0, -12, 16, 16)
93
Object.PrevResult = CheckResult
94
else
95
PlayerObjectCollision(C_TOUCH, -16, -12, 0, 16)
96
Object.PrevResult = CheckResult
97
end if
98
end if
99
100
end sub
101
102
103
104
105
sub ObjectDraw
106
107
switch Object.State
108
case CBSWITCH_POINTLEFT_START
109
if Object.Timer < 7
110
Object.Timer++
111
else
112
Object.Timer = 0
113
ConveyorBelt_Frame = 1
114
Object.State = CBSWITCH_POINTLEFT_TRANSITION
115
end if
116
break
117
118
case CBSWITCH_POINTLEFT_TRANSITION
119
if Object.Timer < 7
120
Object.Timer++
121
else
122
Object.Timer = 0
123
ConveyorBelt_Frame = 2
124
Object.State = CBSWITCH_POINTLEFT_MAIN
125
end if
126
break
127
128
case CBSWITCH_POINTRIGHT_START
129
if Object.Timer < 7
130
Object.Timer++
131
else
132
Object.Timer = 0
133
ConveyorBelt_Frame = 1
134
Object.State = CBSWITCH_POINTRIGHT_TRANSITION
135
end if
136
break
137
138
case CBSWITCH_POINTRIGHT_TRANSITION
139
if Object.Timer < 7
140
Object.Timer++
141
else
142
Object.Timer = 0
143
ConveyorBelt_Frame = 0
144
Object.State = CBSWITCH_POINTRIGHT_MAIN
145
end if
146
break
147
148
end switch
149
150
DrawSprite(ConveyorBelt_Frame)
151
152
end sub
153
154
155
sub ObjectStartup
156
LoadSpriteSheet("R5/Objects.gif")
157
158
if HUD.CurrentTimePeriod == TIME_PAST
159
// The Past gets different Sprite Frames
160
161
SpriteFrame(-4, -16, 32, 28, 1, 225)
162
SpriteFrame(-8, -36, 16, 48, 206, 207)
163
SpriteFrame(-28, -16, 32, 28, 34, 225)
164
else
165
SpriteFrame(-4, -16, 32, 28, 1, 18)
166
SpriteFrame(-8, -36, 16, 48, 125, 1)
167
SpriteFrame(-28, -16, 32, 28, 34, 18)
168
end if
169
170
end sub
171
172
173
// ========================
174
// Editor Subs
175
// ========================
176
177
sub RSDKDraw
178
DrawSprite(0)
179
end sub
180
181
182
sub RSDKLoad
183
LoadSpriteSheet("R5/Objects.gif")
184
SpriteFrame(-4, -16, 32, 28, 1, 18)
185
186
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
187
end sub
188
189