Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/VPlatformMedium.txt
1319 views
1
//--------------Sonic CD VPlatform Medium Script--------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Oscillation
7
#alias Object.Value1 : Object.PlatformY
8
#alias Object.Value2 : Object.ChangeY
9
#alias Object.Value3 : Object.Angle
10
11
// Time Period Aliases
12
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
13
14
#alias 0 : TIME_PRESENT
15
#alias 1 : TIME_PAST
16
#alias 2 : TIME_GOOD_FUTURE
17
#alias 3 : TIME_BAD_FUTURE
18
19
// Priority
20
#alias 3 : PRIORITY_XBOUNDS
21
22
// Property Values
23
#alias 0 : DOWNWARDS_PLAT
24
#alias 1 : DOWNWARDS_PLAT_UNUSED // Unused
25
#alias 2 : DOWNWARDS_PLAT_CONV
26
#alias 3 : UPWARDS_PLAT
27
#alias 4 : UPWARDS_PLAT_UNUSED // Unused
28
#alias 5 : UPWARDS_PLAT_CONV
29
30
31
sub ObjectMain
32
33
// Update the Platform's Oscillation used for its movement
34
// Do note, that because this Oscillation is stored as a local Object Value,
35
// all the platforms across the stage won't have their movements synced
36
Object.Oscillation++
37
if Object.Oscillation == 312
38
Object.Oscillation = 0
39
end if
40
41
// Get the Platform's Angle
42
// It'll range from 0 to 510
43
Object.Angle = Object.Oscillation
44
Object.Angle <<= 6
45
Object.Angle /= 39
46
47
// Use that Andle to get the base Y change for the Platform
48
Sin(Object.ChangeY, Object.Angle)
49
50
// And then invert that
51
FlipSign(Object.ChangeY)
52
53
switch Object.PropertyValue
54
case DOWNWARDS_PLAT
55
case DOWNWARDS_PLAT_CONV
56
// Upwards moving platform
57
Object.ChangeY *= 0x1800
58
Object.ChangeY += 0x300000
59
Object.ChangeY += Object.YPos
60
Object.ChangeY &= 0xFFFF0000 // Truncate the value
61
Object.ChangeY -= Object.PlatformY
62
break
63
64
case UPWARDS_PLAT
65
case UPWARDS_PLAT_CONV
66
// Downwards moving platform
67
Object.ChangeY *= -0x1800
68
Object.ChangeY -= 0x300000
69
Object.ChangeY += Object.YPos
70
Object.ChangeY &= 0xFFFF0000 // Truncate the value
71
Object.ChangeY -= Object.PlatformY
72
break
73
74
case DOWNWARDS_PLAT_UNUSED
75
// Unused duplicate of upwards version
76
Object.ChangeY *= 0x1800
77
Object.ChangeY += 0x300000
78
Object.ChangeY += Object.YPos
79
Object.ChangeY &= 0xFFFF0000 // Truncate the value
80
Object.ChangeY -= Object.PlatformY
81
break
82
83
case UPWARDS_PLAT_UNUSED
84
// Unused duplicate of downwards version
85
Object.ChangeY *= -0x1800
86
Object.ChangeY -= 0x300000
87
Object.ChangeY += Object.YPos
88
Object.ChangeY &= 0xFFFF0000 // Truncate the value
89
Object.ChangeY -= Object.PlatformY
90
break
91
92
end switch
93
94
end sub
95
96
97
sub ObjectPlayerInteraction
98
99
// Backup the Object's current position
100
TempValue0 = Object.YPos
101
102
// Move the Object to where the Platform is
103
Object.YPos = Object.PlatformY
104
105
switch Object.PropertyValue
106
case DOWNWARDS_PLAT
107
case UPWARDS_PLAT
108
// Standard Platform
109
PlayerObjectCollision(C_PLATFORM, -32, -16, 32, 12)
110
if CheckResult == true
111
// Move the Player vertically along with the Platform
112
Player.YPos += Object.ChangeY
113
end if
114
break
115
116
case DOWNWARDS_PLAT_CONV
117
case UPWARDS_PLAT_CONV
118
// Conveyor Platform
119
PlayerObjectCollision(C_PLATFORM, -32, -16, 32, 12)
120
if CheckResult == true
121
122
// Move the Player up or down with the Platform as needed to keep them on
123
Player.YPos += Object.ChangeY
124
125
// And them adjust them as needed with the Conveyor too
126
if ConveyorBelt_Flag == 0
127
Player.XPos += ConveyorBelt_Speed
128
else
129
Player.XPos -= ConveyorBelt_Speed
130
end if
131
132
end if
133
break
134
135
end switch
136
137
// Now restore the Object back to its base Position
138
Object.YPos = TempValue0
139
140
end sub
141
142
143
sub ObjectDraw
144
145
Sin(Object.PlatformY, Object.Angle)
146
FlipSign(Object.PlatformY)
147
148
switch Object.PropertyValue
149
case DOWNWARDS_PLAT
150
case DOWNWARDS_PLAT_UNUSED
151
// Standard, upwards Platform
152
Object.PlatformY *= 0x1800
153
Object.PlatformY += 0x300000
154
Object.PlatformY += Object.YPos
155
Object.PlatformY &= 0xFFFF0000 // Truncate the value
156
DrawSpriteXY(0, Object.XPos, Object.PlatformY)
157
break
158
159
case DOWNWARDS_PLAT_CONV
160
// Upwards Conveyor Platform
161
Object.PlatformY *= 0x1800
162
Object.PlatformY += 0x300000
163
Object.PlatformY += Object.YPos
164
Object.PlatformY &= 0xFFFF0000 // Truncate the value
165
DrawSpriteXY(0, Object.XPos, Object.PlatformY)
166
DrawSpriteXY(1, Object.XPos, Object.PlatformY)
167
break
168
169
case UPWARDS_PLAT
170
case UPWARDS_PLAT_UNUSED
171
// Standard, downwards Platform
172
Object.PlatformY *= -0x1800
173
Object.PlatformY -= 0x300000
174
Object.PlatformY += Object.YPos
175
Object.PlatformY &= 0xFFFF0000 // Truncate the value
176
DrawSpriteXY(0, Object.XPos, Object.PlatformY)
177
break
178
179
case UPWARDS_PLAT_CONV
180
// Downwards conveyor Platform
181
Object.PlatformY *= -0x1800
182
Object.PlatformY -= 0x300000
183
Object.PlatformY += Object.YPos
184
Object.PlatformY &= 0xFFFF0000 // Truncate the value
185
DrawSpriteXY(0, Object.XPos, Object.PlatformY)
186
DrawSpriteXY(1, Object.XPos, Object.PlatformY)
187
break
188
189
end switch
190
191
end sub
192
193
194
sub ObjectStartup
195
196
LoadSpriteSheet("R5/Objects.gif")
197
198
// Use different sprites based on the current Time Periods
199
switch HUD.CurrentTimePeriod
200
case TIME_PRESENT
201
LoadSpriteSheet("R5/Objects.gif")
202
SpriteFrame(-32, -16, 64, 32, 34, 51)
203
SpriteFrame(-32, -16, 64, 16, 1, 208)
204
break
205
206
case TIME_PAST
207
LoadSpriteSheet("R5/Objects3.gif")
208
SpriteFrame(-32, -16, 64, 32, 34, 170)
209
SpriteFrame(-32, -16, 64, 16, 159, 148)
210
break
211
212
case TIME_GOOD_FUTURE
213
LoadSpriteSheet("R5/Objects3.gif")
214
SpriteFrame(-32, -16, 64, 32, 34, 170)
215
SpriteFrame(-32, -16, 64, 16, 159, 182)
216
break
217
218
case TIME_BAD_FUTURE
219
LoadSpriteSheet("R5/Objects3.gif")
220
SpriteFrame(-32, -16, 64, 32, 34, 170)
221
SpriteFrame(-32, -16, 64, 16, 159, 216)
222
break
223
224
end switch
225
226
ArrayPos0 = 32
227
while ArrayPos0 < 1056
228
if Object[ArrayPos0].Type == TypeName[VPlatform Medium]
229
230
// Is the Platform's Property Value 6 or above?
231
if Object[ArrayPos0].PropertyValue > 5
232
233
// Bring it back down a bit
234
Object[ArrayPos0].PropertyValue -= 6
235
236
// It's a vertical platform type, so it should be updated regardless how far vertically it may be,
237
// since it may still be within rnage of the player in its cycle
238
Object[ArrayPos0].Priority = PRIORITY_XBOUNDS
239
240
end if
241
end if
242
243
ArrayPos0++
244
loop
245
246
end sub
247
248
249
// ========================
250
// Editor Subs
251
// ========================
252
253
// TODO: please test this, I think this may be a bit broken...
254
255
sub RSDKEdit
256
if Editor.ReturnVariable == true
257
switch Editor.VariableID
258
case EDIT_VAR_PROPVAL // Property Value
259
CheckResult = Object.PropertyValue
260
break
261
case 0 // Direction
262
CheckResult = Object.PropertyValue
263
CheckResult %= 6
264
break
265
case 1 // Priority
266
CheckGreater(Object.PropertyValue, 5)
267
break
268
end switch
269
else
270
switch Editor.VariableID
271
case EDIT_VAR_PROPVAL // Property Value
272
Object.PropertyValue = Editor.VariableValue
273
break
274
case 0 // Direction
275
// this is kinda shoddily-coded, very well could be improved...
276
if Object.PropertyValue > 5
277
Object.PropertyValue = Editor.VariableValue
278
Object.PropertyValue += 6
279
else
280
Object.PropertyValue = Editor.VariableValue
281
end if
282
break
283
case 1 // Priority
284
Object.PropertyValue %= 6
285
CheckNotEqual(Editor.VariableValue, false)
286
Editor.VariableValue *= 6
287
Object.PropertyValue += Editor.VariableValue
288
break
289
end switch
290
end if
291
end sub
292
293
294
sub RSDKDraw
295
TempValue2 = false
296
297
TempValue0 = Object.PropertyValue
298
TempValue0 %= 6
299
300
switch TempValue0
301
case 2
302
TempValue2 = true
303
case 0
304
TempValue0 = 0x1800
305
TempValue1 = 0x300000
306
break
307
308
case 5
309
TempValue2 = true
310
case 3
311
TempValue0 = -0x1800
312
TempValue1 = -0x300000
313
break
314
315
end switch
316
317
TempValue3 = Object.YPos
318
TempValue3 &= 0xFFFF0000 // Truncate the value
319
DrawSpriteXY(0, Object.XPos, TempValue3)
320
321
if TempValue2 == true
322
DrawSpriteXY(1, Object.XPos, TempValue3)
323
end if
324
325
if Editor.ShowGizmos == true
326
327
// Draw the path the Platform will follow
328
329
Sin(TempValue4, 128)
330
TempValue4 *= TempValue0
331
TempValue4 += TempValue1
332
TempValue4 += Object.YPos
333
TempValue4 &= 0xFFFF0000 // Truncate the value
334
335
Editor.DrawingOverlay = true
336
337
DrawLine(Object.XPos, TempValue3, Object.XPos, TempValue4, 255, 255, 255)
338
339
Editor.DrawingOverlay = false
340
341
end if
342
end sub
343
344
345
sub RSDKLoad
346
LoadSpriteSheet("R5/Objects.gif")
347
// TODO: using the present version here, but do other time periods
348
SpriteFrame(-32, -16, 64, 32, 34, 51)
349
SpriteFrame(-32, -16, 64, 16, 1, 208)
350
351
AddEditorVariable("Direction")
352
SetActiveVariable("Direction")
353
AddEnumVariable("Upwards", 0)
354
// 1 is unused
355
AddEnumVariable("Upwards (Conveyor)", 2)
356
AddEnumVariable("Downwards", 3)
357
// 4 is unused
358
AddEnumVariable("Downwards (Conveyor)", 5)
359
360
AddEditorVariable("Priority")
361
SetActiveVariable("Priority")
362
AddEnumVariable("Normal", 0)
363
AddEnumVariable("XBounds", 1)
364
end sub
365
366