Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/Bridge.txt
1319 views
1
//-------------------Sonic CD Bridge Script-------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.PropertyValue : Object.Length
7
8
#alias Object.Value0 : Object.WalkedOn
9
#alias Object.Value1 : Object.Depress
10
#alias Object.Value2 : Object.MidPoint
11
#alias Object.Value3 : Object.MidHeight
12
#alias Object.Value4 : Object.MidYPos
13
#alias Object.Value5 : Object.PlayerNo
14
#alias Object.Value6 : Object.Left
15
#alias Object.Value7 : Object.Right
16
17
// Time Period Aliases
18
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
19
20
// Flailing states, v4 names explains this much better
21
#alias Player.Flailing[0] : Player.FloorSensorL
22
#alias Player.Flailing[1] : Player.FloorSensorC
23
#alias Player.Flailing[2] : Player.FloorSensorR
24
25
// Gravity
26
#alias 0 : GRAVITY_GROUND
27
28
// Time Periods
29
#alias 0 : TIME_PRESENT
30
#alias 1 : TIME_PAST
31
#alias 2 : TIME_GOOD_FUTURE
32
#alias 3 : TIME_BAD_FUTURE
33
34
35
// Note: This Object supports multiple players, but CD's locked to 1 Player anyway so all that logic goes unused in a way
36
37
38
sub ObjectPlayerInteraction
39
40
if Player.XPos > Object.Left
41
if Player.XPos < Object.Right
42
if Stage.ActivePlayer == Object.PlayerNo
43
44
Object.MidPoint = Player.XPos
45
Object.MidPoint -= Object.Left
46
47
TempValue0 = Object.MidPoint
48
TempValue0 >>= 8
49
50
TempValue1 = Object.Right
51
TempValue1 -= Object.Left
52
53
TempValue2 = TempValue1
54
TempValue2 >>= 16
55
56
TempValue0 /= TempValue2
57
58
Sin(Object.MidHeight, TempValue0)
59
TempValue1 >>= 13
60
Object.MidHeight *= TempValue1
61
62
TempValue0 = Object.YPos
63
TempValue0 -= 0x300000
64
if Player.YPos > TempValue0
65
if Player.YVelocity >= 0
66
TempValue2 = Player.CollisionBottom
67
FlipSign(TempValue2)
68
TempValue2 <<= 16
69
TempValue2 += Object.MidYPos
70
TempValue2 -= 0x80000
71
72
Object.WalkedOn++
73
Player.YPos = Object.YPos
74
Player.YPos += TempValue2
75
Player.Gravity = 0
76
Player.YVelocity = 0
77
78
Player.FloorSensorL = true
79
Player.FloorSensorR = true
80
Player.FloorSensorC = true
81
end if
82
end if
83
84
else
85
86
if Player.YVelocity >= 0
87
88
TempValue0 = Player.XPos
89
TempValue0 -= Object.Left
90
91
if TempValue0 > Object.MidPoint
92
TempValue0 = Object.Right
93
TempValue0 -= Player.XPos
94
95
TempValue3 = Object.Right
96
TempValue3 -= Object.Left
97
TempValue3 -= Object.MidPoint
98
99
TempValue1 = TempValue0
100
TempValue1 <<= 7
101
TempValue1 /= TempValue3
102
else
103
TempValue1 = TempValue0
104
TempValue1 <<= 7
105
TempValue1 /= Object.MidPoint
106
end if
107
108
Sin(TempValue2, TempValue1)
109
TempValue2 *= Object.MidYPos
110
TempValue2 >>= 9
111
TempValue2 -= 0x80000
112
113
if Player.YVelocity < 0x8000
114
TempValue3 = TempValue2
115
TempValue3 >>= 16
116
TempValue4 = TempValue3
117
TempValue3 -= 8
118
else
119
TempValue3 = TempValue2
120
TempValue3 >>= 16
121
TempValue4 = TempValue3
122
TempValue4 += 8
123
end if
124
125
PlayerObjectCollision(C_TOUCH, -1024, TempValue3, 1024, TempValue4)
126
127
if CheckResult == true
128
Object.WalkedOn++
129
Player.YPos = Player.CollisionBottom
130
FlipSign(Player.YPos)
131
Player.YPos <<= 16
132
Player.YPos += Object.YPos
133
Player.YPos += TempValue2
134
135
Player.FloorSensorL = true
136
Player.FloorSensorR = true
137
Player.FloorSensorC = true
138
139
if Player.YVelocity < 256
140
Object.Depress = 128
141
end if
142
143
Player.Gravity = GRAVITY_GROUND
144
Player.YVelocity = 0
145
146
// This check is always gonna be true, since CD only has P1 active ever
147
if Stage.ActivePlayer == 0
148
Object.PlayerNo = 0
149
end if
150
end if
151
152
end if
153
154
end if
155
end if
156
end if
157
158
end sub
159
160
161
sub ObjectDraw
162
163
TempValue0 = 0
164
165
TempValue1 = Object.Left
166
TempValue1 += 0x80000
167
168
TempValue4 = 0x80000
169
170
TempValue5 = Object.MidPoint
171
TempValue5 >>= 20
172
173
while TempValue0 < TempValue5
174
175
TempValue3 = TempValue4
176
TempValue3 <<= 7
177
TempValue3 /= Object.MidPoint
178
179
Sin(TempValue2, TempValue3)
180
TempValue2 *= Object.MidYPos
181
TempValue2 >>= 9
182
183
TempValue2 += Object.YPos
184
185
DrawSpriteXY(0, TempValue1, TempValue2)
186
TempValue1 += 0x100000
187
TempValue4 += 0x100000
188
TempValue0++
189
190
loop
191
192
TempValue2 = Object.MidYPos
193
TempValue2 += Object.YPos
194
DrawSpriteXY(0, TempValue1, TempValue2)
195
TempValue1 += 0x100000
196
TempValue0++
197
198
TempValue5 = Object.Right
199
TempValue5 -= Object.Left
200
TempValue5 -= Object.MidPoint
201
202
TempValue1 = Object.Right
203
TempValue1 -= 0x80000
204
205
TempValue4 = 0x80000
206
207
while TempValue0 < Object.Length
208
209
TempValue3 = TempValue4
210
TempValue3 <<= 7
211
TempValue3 /= TempValue5
212
213
Sin(TempValue2, TempValue3)
214
TempValue2 *= Object.MidYPos
215
TempValue2 >>= 9
216
217
TempValue2 += Object.YPos
218
219
DrawSpriteXY(0, TempValue1, TempValue2)
220
TempValue1 -= 0x100000
221
TempValue4 += 0x100000
222
TempValue0++
223
224
loop
225
226
if Object.WalkedOn > 0
227
if Object.Depress < 128
228
Object.Depress += 8
229
end if
230
else
231
if Object.Depress > 0
232
Object.Depress -= 8
233
Object.PlayerNo = -1
234
else
235
Object.MidHeight = 0
236
end if
237
end if
238
239
Object.MidYPos = Object.MidHeight
240
Object.MidYPos *= Object.Depress
241
Object.MidYPos >>= 7
242
243
Object.WalkedOn = 0
244
245
end sub
246
247
248
sub ObjectStartup
249
LoadSpriteSheet("R5/Objects.gif")
250
251
// Load different Sprite Frames for the different Time Periods
252
switch HUD.CurrentTimePeriod
253
case TIME_PRESENT
254
SpriteFrame(-8, -8, 16, 16, 35, 1)
255
break
256
257
case TIME_PAST
258
SpriteFrame(-8, -8, 16, 16, 67, 174)
259
break
260
261
case TIME_GOOD_FUTURE
262
SpriteFrame(-8, -8, 16, 16, 83, 174)
263
break
264
265
case TIME_BAD_FUTURE
266
SpriteFrame(-8, -8, 16, 16, 83, 158)
267
break
268
269
end switch
270
271
// Setup the Bridge Sizes for all Bridge Objects in the level
272
ArrayPos0 = 32
273
while ArrayPos0 < 1056
274
if Object[ArrayPos0].Type == TypeName[Bridge]
275
Object[ArrayPos0].Left = Object[ArrayPos0].Length
276
Object[ArrayPos0].Left <<= 19
277
Object[ArrayPos0].Right = Object[ArrayPos0].Left
278
279
FlipSign(Object[ArrayPos0].Left)
280
Object[ArrayPos0].Left += Object[ArrayPos0].XPos
281
Object[ArrayPos0].Right += Object[ArrayPos0].XPos
282
283
Object[ArrayPos0].PlayerNo = -1
284
end if
285
286
ArrayPos0++
287
loop
288
289
end sub
290
291
292
// ========================
293
// Editor Subs
294
// ========================
295
296
sub RSDKDraw
297
TempValue0 = Object.Length
298
TempValue2 = TempValue0
299
TempValue0 <<= 19
300
FlipSign(TempValue0)
301
TempValue0 += Object.XPos
302
TempValue0 += 0x80000
303
304
TempValue1 = 0
305
while TempValue1 < TempValue2
306
DrawSpriteXY(0, TempValue0, Object.YPos)
307
TempValue0 += 0x100000
308
TempValue1++
309
loop
310
311
if TempValue1 == 0
312
DrawSprite(0)
313
end if
314
end sub
315
316
317
sub RSDKLoad
318
LoadSpriteSheet("R5/Objects.gif")
319
320
// TODO: support other time periods
321
// Surely there's a better way to do it than 10 separate checkCurrentStageFolder checks?
322
SpriteFrame(-8, -8, 16, 16, 35, 1)
323
324
SetVariableAlias(ALIAS_VAR_PROPVAL, "length")
325
end sub
326
327