Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/FallPlatform.txt
1319 views
1
//--------------Sonic CD Falling Platform Script--------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Stood
7
#alias Object.Value1 : Object.DipTimer
8
#alias Object.Value2 : Object.MoveY
9
#alias Object.Value3 : Object.Timer
10
#alias Object.Value4 : Object.YVelocity
11
#alias Object.Value5 : Object.StartPosY
12
13
// HUD Alias
14
#alias Object[24].PropertyValue : HUD.CurrentTimePeriod
15
16
// States
17
#alias 0 : FALLPLATFORM_FLOAT
18
#alias 1 : FALLPLATFORM_SUSPEND
19
#alias 2 : FALLPLATFORM_FALLING
20
#alias 3 : FALLPLATFORM_OFFSCREEN
21
22
// Time Period Aliases
23
#alias 0 : TIME_PRESENT
24
#alias 1 : TIME_PAST
25
#alias 2 : TIME_GOOD_FUTURE
26
#alias 3 : TIME_BAD_FUTURE
27
28
// Priority
29
#alias 0 : PRIORITY_BOUNDS
30
#alias 1 : PRIORITY_ACTIVE
31
32
33
sub ObjectMain
34
35
// Object.Stood is supposed to be set from last frame, by ObjectPlayerInteraction
36
37
if Object.Stood == true
38
if Object.State == FALLPLATFORM_FLOAT
39
Object.State = FALLPLATFORM_SUSPEND
40
end if
41
42
if Object.DipTimer < 16
43
// Sink down
44
45
Object.DipTimer++
46
47
TempValue0 = Object.DipTimer
48
TempValue0 &= 3
49
50
if TempValue0 == 3
51
// Dip a pixel down
52
Object.MoveY = 0x10000
53
else
54
Object.MoveY = 0
55
end if
56
else
57
Object.MoveY = 0
58
end if
59
else
60
if Object.DipTimer > 0
61
// Move back up
62
63
Object.DipTimer--
64
65
TempValue0 = Object.DipTimer
66
TempValue0 &= 3
67
68
if TempValue0 == 3
69
// Recover a pixel upwards again
70
Object.MoveY = -0x10000
71
else
72
Object.MoveY = 0
73
end if
74
else
75
Object.MoveY = 0
76
end if
77
end if
78
79
// Reset it, to be set in ObjectPlayerInteraction again later this frame
80
Object.Stood = false
81
82
switch Object.State
83
case FALLPLATFORM_SUSPEND
84
if Object.Timer < 30
85
// Hold for a moment before starting to fall
86
Object.Timer++
87
else
88
// Fall away!
89
90
Object.YVelocity = 0
91
Object.Timer = 0
92
Object.State = FALLPLATFORM_FALLING
93
94
// Make this Object always active, needed for its respawn process
95
Object.Priority = PRIORITY_ACTIVE
96
end if
97
break
98
99
case FALLPLATFORM_FALLING
100
// If the Object yet hasn't reached a Y Velocity of 4 pixels per frame,
101
// then accelerate at a rate of 0.125 pixels per frame
102
if Object.YVelocity < 0x40000
103
Object.YVelocity += 0x2000
104
end if
105
106
// Move the Platform
107
// (Via increasing its move value)
108
Object.MoveY += Object.YVelocity
109
110
// Has the Object fallen out of range now?
111
if Object.OutOfBounds == true
112
113
// Move the Platform back to its base Position
114
Object.YPos = Object.StartPosY
115
116
// Reset to the Buffer State
117
Object.State = FALLPLATFORM_OFFSCREEN
118
Object.YVelocity = 0
119
120
end if
121
break
122
123
case FALLPLATFORM_OFFSCREEN
124
if Object.OutOfBounds == true
125
// Now that the Platform is out of the Player's view, reset all the way back to normal
126
Object.State = FALLPLATFORM_FLOAT
127
Object.Priority = PRIORITY_BOUNDS
128
end if
129
break
130
131
end switch
132
133
end sub
134
135
136
sub ObjectPlayerInteraction
137
138
if Object.State < FALLPLATFORM_OFFSCREEN
139
140
// Support for different Platform sizes
141
// This also supports Conveyor Platforms, in a way, but the Player isn't moved along the Conveyor
142
switch Object.PropertyValue
143
case 0
144
// Small Platform
145
PlayerObjectCollision(C_PLATFORM, -16, -16, 16, 12)
146
if CheckResult == true
147
Object.Stood = true
148
Player.YPos += Object.MoveY
149
end if
150
break
151
152
case 1
153
// Medium-sized Platform
154
PlayerObjectCollision(C_PLATFORM, -32, -16, 32, 12)
155
if CheckResult == true
156
Object.Stood = true
157
Player.YPos += Object.MoveY
158
end if
159
break
160
161
case 2
162
// Large Platform
163
PlayerObjectCollision(C_PLATFORM, -48, -16, 48, 12)
164
if CheckResult == true
165
Object.Stood = true
166
Player.YPos += Object.MoveY
167
end if
168
break
169
170
case 3
171
// Small Conveyor Platform
172
PlayerObjectCollision(C_PLATFORM, -16, -16, 16, 12)
173
if CheckResult == true
174
Object.Stood = true
175
Player.YPos += Object.MoveY
176
end if
177
break
178
179
case 4
180
// Medium-sized Conveyor Platform
181
PlayerObjectCollision(C_PLATFORM, -32, -16, 32, 12)
182
if CheckResult == true
183
Object.Stood = true
184
Player.YPos += Object.MoveY
185
end if
186
break
187
188
case 5
189
// Large Conveyor Platform
190
PlayerObjectCollision(C_PLATFORM, -48, -16, 48, 12)
191
if CheckResult == true
192
Object.Stood = true
193
Player.YPos += Object.MoveY
194
end if
195
break
196
197
end switch
198
199
end if
200
201
end sub
202
203
204
sub ObjectDraw
205
206
Object.YPos += Object.MoveY
207
208
if Object.State < FALLPLATFORM_OFFSCREEN
209
switch Object.PropertyValue
210
case 0
211
case 1
212
case 2
213
// Normal Platform
214
DrawSprite(Object.PropertyValue)
215
break
216
217
case 3
218
// Small Conveyor Platform
219
DrawSprite(0)
220
DrawSprite(3)
221
break
222
223
case 4
224
// Medium-sized Coneyor Platform
225
DrawSprite(1)
226
DrawSprite(4)
227
break
228
229
case 5
230
// Large Conveyor Platform
231
DrawSprite(2)
232
DrawSprite(5)
233
break
234
235
end switch
236
end if
237
238
end sub
239
240
241
sub ObjectStartup
242
LoadSpriteSheet("R5/Objects.gif")
243
244
// All the Time Periods get unique platform sprites
245
switch HUD.CurrentTimePeriod
246
case TIME_PRESENT
247
LoadSpriteSheet("R5/Objects.gif")
248
SpriteFrame(-16, -16, 32, 32, 1, 51)
249
SpriteFrame(-32, -16, 64, 32, 34, 51)
250
SpriteFrame(-48, -16, 96, 32, 1, 84)
251
SpriteFrame(-16, -16, 32, 16, 65, 208)
252
SpriteFrame(-32, -16, 64, 16, 1, 208)
253
SpriteFrame(-48, -16, 96, 16, 1, 191)
254
break
255
256
case TIME_PAST
257
LoadSpriteSheet("R5/Objects3.gif")
258
SpriteFrame(-16, -16, 32, 32, 1, 170)
259
SpriteFrame(-32, -16, 64, 32, 34, 170)
260
SpriteFrame(-48, -16, 96, 32, 1, 203)
261
SpriteFrame(-16, -16, 32, 16, 223, 148)
262
SpriteFrame(-32, -16, 64, 16, 159, 148)
263
SpriteFrame(-48, -16, 96, 16, 159, 131)
264
break
265
266
case TIME_GOOD_FUTURE
267
LoadSpriteSheet("R5/Objects3.gif")
268
SpriteFrame(-16, -16, 32, 32, 1, 170)
269
SpriteFrame(-32, -16, 64, 32, 34, 170)
270
SpriteFrame(-48, -16, 96, 32, 1, 203)
271
SpriteFrame(-16, -16, 32, 16, 223, 182)
272
SpriteFrame(-32, -16, 64, 16, 159, 182)
273
SpriteFrame(-48, -16, 96, 16, 159, 165)
274
break
275
276
case TIME_BAD_FUTURE
277
LoadSpriteSheet("R5/Objects3.gif")
278
SpriteFrame(-16, -16, 32, 32, 1, 170)
279
SpriteFrame(-32, -16, 64, 32, 34, 170)
280
SpriteFrame(-48, -16, 96, 32, 1, 203)
281
SpriteFrame(-16, -16, 32, 16, 223, 216)
282
SpriteFrame(-32, -16, 64, 16, 159, 216)
283
SpriteFrame(-48, -16, 96, 16, 159, 199)
284
break
285
286
end switch
287
288
// Loop through all Objects in the Stage and find all Falling Platforms
289
ArrayPos0 = 32
290
while ArrayPos0 < 1056
291
if Object[ArrayPos0].Type == TypeName[Falling Platform]
292
293
// Store the Falling Platform's starting Position, needed for when it'll respawn
294
Object[ArrayPos0].StartPosY = Object[ArrayPos0].YPos
295
296
end if
297
298
ArrayPos0++
299
loop
300
301
end sub
302
303
304
// ========================
305
// Editor Subs
306
// ========================
307
308
sub RSDKEdit
309
if Editor.ReturnVariable == true
310
switch Editor.VariableID
311
case EDIT_VAR_PROPVAL // Property Value
312
CheckResult = Object.PropertyValue
313
break
314
case 0 // Type
315
CheckResult = Object.PropertyValue
316
break
317
end switch
318
else
319
switch Editor.VariableID
320
case EDIT_VAR_PROPVAL // Property Value
321
Object.PropertyValue = Editor.VariableValue
322
break
323
case 0 // Type
324
Object.PropertyValue = Editor.VariableValue
325
break
326
end switch
327
end if
328
end sub
329
330
331
sub RSDKDraw
332
if Object.PropertyValue >= 3
333
TempValue0 = -3
334
TempValue0 += Object.PropertyValue
335
DrawSprite(TempValue0)
336
end if
337
338
DrawSprite(Object.PropertyValue)
339
340
if Editor.ShowGizmos == true
341
Editor.DrawingOverlay = true
342
343
// Draw an arrow pointing down to show that this Platform is of the falling type
344
345
TempValue0 = Object.YPos
346
TempValue0 += 0x300000
347
348
DrawArrow(Object.XPos, Object.YPos, Object.XPos, TempValue0, 255, 255, 255)
349
350
Editor.DrawingOverlay = false
351
end if
352
end sub
353
354
355
sub RSDKLoad
356
// sticking with the R5A version of the sprites here...
357
// TODO: support for other time periods
358
LoadSpriteSheet("R5/Objects.gif")
359
SpriteFrame(-16, -16, 32, 32, 1, 51)
360
SpriteFrame(-32, -16, 64, 32, 34, 51)
361
SpriteFrame(-48, -16, 96, 32, 1, 84)
362
SpriteFrame(-16, -16, 32, 16, 65, 208)
363
SpriteFrame(-32, -16, 64, 16, 1, 208)
364
SpriteFrame(-48, -16, 96, 16, 1, 191)
365
366
AddEditorVariable("Type")
367
SetActiveVariable("Type")
368
AddEnumVariable("Small", 0)
369
AddEnumVariable("Medium", 1)
370
AddEnumVariable("Large", 2)
371
AddEnumVariable("Small Conveyor", 3)
372
AddEnumVariable("Medium Conveyor", 4)
373
AddEnumVariable("Large Conveyor", 5)
374
end sub
375
376