Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R5/CPlatform.txt
1319 views
1
//-----------------Sonic CD CPlatform Script------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.LedgeLeft
7
#alias Object.Value1 : Object.LedgeRight
8
#alias Object.Value2 : Object.Timer
9
#alias Object.Value3 : Object.NoBlocks
10
#alias Object.Value4 : Object.YVelocity
11
12
// States
13
#alias 0 : CPLATFORM_ACTIVE
14
#alias 1 : CPLATFORM_WAIT_R
15
#alias 2 : CPLATFORM_WAIT_L
16
#alias 3 : CPLATFORM_CRUMBLE_L
17
#alias 4 : CPLATFORM_CRUMBLE_R
18
#alias 5 : CPLATFORM_RESPAWNWAIT
19
#alias 6 : CPLATFORM_FALLINGBLOCK
20
21
// Stage SFX
22
#alias 0 : SFX_S_CRUMBLE
23
24
// Priority
25
#alias 0 : PRIORITY_BOUNDS
26
#alias 1 : PRIORITY_ACTIVE
27
28
// Property Values
29
#alias 1 : PLATFORM_DEBRIS_1
30
#alias 2 : PLATFORM_DEBRIS_2
31
32
33
sub ObjectMain
34
35
switch Object.State
36
37
// Nothing for CPLATFORM_ACTIVE here
38
// Initial triggering of crumbling is all handled in ObjectPlayerInteraction instead
39
40
case CPLATFORM_WAIT_R
41
if Object.Timer > 0
42
Object.Timer--
43
else
44
PlayStageSfx(SFX_S_CRUMBLE, false)
45
46
Object.State = CPLATFORM_CRUMBLE_R
47
end if
48
break
49
50
case CPLATFORM_WAIT_L
51
if Object.Timer > 0
52
Object.Timer--
53
else
54
PlayStageSfx(SFX_S_CRUMBLE, false)
55
56
Object.State = CPLATFORM_CRUMBLE_L
57
end if
58
break
59
60
case CPLATFORM_CRUMBLE_L
61
Object.Timer++
62
if Object.Timer == 10
63
Object.Timer = 0
64
if Object.LedgeLeft < Object.LedgeRight
65
Object.NoBlocks--
66
Object.LedgeLeft += 16
67
68
// Start spawning fragments
69
70
// First, get the XPos to start at
71
TempValue0 = Object.LedgeLeft
72
TempValue0 -= 8
73
TempValue0 <<= 16
74
TempValue0 += Object.XPos
75
76
// Then get the YPos, 8 pixels above this base object
77
TempValue1 = Object.YPos
78
TempValue1 -= 0x80000
79
80
// Spawning of the First Fragment
81
CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)
82
Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK
83
Object[TempObjectPos].YVelocity = -0x10000
84
Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_1
85
86
// Put the second piece 16 pixels down
87
TempValue1 += 0x100000
88
89
// Spawning of the Second Fragment
90
CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)
91
Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK
92
Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_2
93
else
94
ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, 0, 0)
95
end if
96
end if
97
break
98
99
case CPLATFORM_CRUMBLE_R
100
Object.Timer++
101
if Object.Timer == 10
102
Object.Timer = 0
103
if Object.LedgeRight > Object.LedgeLeft
104
Object.NoBlocks--
105
Object.LedgeRight -= 16
106
107
// Start making the Fragments
108
109
// First, find the target XPos
110
TempValue0 = Object.LedgeRight
111
TempValue0 += 8
112
TempValue0 <<= 16
113
TempValue0 += Object.XPos
114
115
// Then, make the target YPos 8 pixels above this base object
116
TempValue1 = Object.YPos
117
TempValue1 -= 0x80000
118
119
// Create the first Fragment
120
CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)
121
Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK
122
Object[TempObjectPos].YVelocity = -0x10000
123
Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_1
124
125
// Second piece should be 16 pixels down
126
TempValue1 += 0x100000
127
128
// Create the second Fragment
129
CreateTempObject(TypeName[CPlatform], 0, TempValue0, TempValue1)
130
Object[TempObjectPos].State = CPLATFORM_FALLINGBLOCK
131
Object[TempObjectPos].PropertyValue = PLATFORM_DEBRIS_2
132
else
133
ResetObjectEntity(Object.EntityNo, TypeName[Blank Object], 0, 0, 0)
134
end if
135
end if
136
break
137
138
case CPLATFORM_RESPAWNWAIT
139
// This state acts as a buffer of sorts, so that the platform doesn't respawn while it's still visible to the player
140
// It also acts as a soft reset, of sorts
141
if Object.OutOfBounds == true
142
Object.State = CPLATFORM_ACTIVE
143
Object.NoBlocks = Object.PropertyValue
144
145
Object.LedgeLeft = Object.PropertyValue
146
Object.LedgeLeft <<= 3
147
148
Object.LedgeRight = Object.LedgeLeft
149
FlipSign(Object.LedgeLeft)
150
151
Object.Priority = PRIORITY_BOUNDS
152
Object.Timer = 0
153
end if
154
break
155
156
case CPLATFORM_FALLINGBLOCK
157
// Apply a gravity of 0.25 pixels per frame
158
Object.YVelocity += 0x4000
159
if Object.YVelocity > 0
160
Object.YPos += Object.YVelocity
161
end if
162
163
if Object.OutOfBounds == true
164
// Unload when no longer needed
165
Object.Type = TypeName[Blank Object]
166
end if
167
break
168
169
end switch
170
171
end sub
172
173
174
sub ObjectPlayerInteraction
175
176
if Object.State == CPLATFORM_ACTIVE
177
PlayerObjectCollision(C_PLATFORM, Object.LedgeLeft, -16, Object.LedgeRight, 16)
178
179
if CheckResult == true
180
Object.Timer = 1
181
Object.Priority = PRIORITY_ACTIVE
182
183
if Player.XPos > Object.XPos
184
Object.State = CPLATFORM_WAIT_R
185
else
186
Object.State = CPLATFORM_WAIT_L
187
end if
188
end if
189
else
190
PlayerObjectCollision(C_PLATFORM, Object.LedgeLeft, -16, Object.LedgeRight, 16)
191
end if
192
193
end sub
194
195
196
sub ObjectDraw
197
198
switch Object.State
199
case CPLATFORM_ACTIVE
200
case CPLATFORM_WAIT_R
201
case CPLATFORM_WAIT_L
202
case CPLATFORM_CRUMBLE_R
203
// Draw the Platform piece by piece, starting from the left
204
TempValue0 = 0
205
TempValue1 = Object.LedgeLeft
206
TempValue1 <<= 16
207
TempValue1 += 0x80000
208
TempValue1 += Object.XPos
209
while TempValue0 < Object.NoBlocks
210
DrawSpriteXY(0, TempValue1, Object.YPos)
211
TempValue0++
212
TempValue1 += 0x100000
213
loop
214
break
215
216
case CPLATFORM_CRUMBLE_L
217
// Draw the Platform piece by piece, starting from the right
218
TempValue0 = 0
219
TempValue1 = Object.LedgeRight
220
TempValue1 <<= 16
221
TempValue1 -= 0x80000
222
TempValue1 += Object.XPos
223
while TempValue0 < Object.NoBlocks
224
DrawSpriteXY(0, TempValue1, Object.YPos)
225
TempValue0++
226
TempValue1 -= 0x100000
227
loop
228
break
229
230
case CPLATFORM_FALLINGBLOCK
231
DrawSprite(Object.PropertyValue)
232
break
233
234
end switch
235
236
end sub
237
238
239
sub ObjectStartup
240
LoadSpriteSheet("R5/Objects.gif")
241
242
// Setup the Ledge Sizes for all CPlatform Objects present in the level
243
ArrayPos0 = 32
244
while ArrayPos0 < 1056
245
if Object[ArrayPos0].Type == TypeName[CPlatform]
246
Object[ArrayPos0].NoBlocks = Object[ArrayPos0].PropertyValue
247
248
Object[ArrayPos0].LedgeLeft = Object[ArrayPos0].PropertyValue
249
Object[ArrayPos0].LedgeLeft <<= 3
250
251
Object[ArrayPos0].LedgeRight = Object[ArrayPos0].LedgeLeft
252
253
FlipSign(Object[ArrayPos0].LedgeLeft)
254
end if
255
256
ArrayPos0++
257
loop
258
259
// Ledge Frame
260
SpriteFrame(-8, -16, 16, 32, 108, 51)
261
262
// Broken Ledge Frames
263
SpriteFrame(-8, -8, 16, 16, 108, 51)
264
SpriteFrame(-8, -8, 16, 16, 108, 67)
265
266
end sub
267
268
269
// ========================
270
// Editor Subs
271
// ========================
272
273
sub RSDKEdit
274
if Editor.ReturnVariable == true
275
switch Editor.VariableID
276
case EDIT_VAR_PROPVAL // Property Value
277
case 0 // BlocksNo
278
CheckResult = Object.PropertyValue
279
break
280
end switch
281
else
282
switch Editor.VariableID
283
case EDIT_VAR_PROPVAL // Property Value
284
case 0 // BlocksNo
285
Object.PropertyValue = Editor.VariableValue
286
break
287
end switch
288
end if
289
end sub
290
291
292
sub RSDKDraw
293
TempValue0 = 0
294
TempValue1 = Object.PropertyValue
295
TempValue1 <<= 19
296
TempValue1 -= 0x80000
297
TempValue1 += Object.XPos
298
while TempValue0 < Object.PropertyValue
299
DrawSpriteXY(0, TempValue1, Object.YPos)
300
TempValue0++
301
TempValue1 -= 0x100000
302
loop
303
end sub
304
305
306
sub RSDKLoad
307
LoadSpriteSheet("R5/Objects.gif")
308
SpriteFrame(-8, -16, 16, 32, 108, 51)
309
310
AddEditorVariable("BlocksNo")
311
SetActiveVariable("BlocksNo")
312
end sub
313
314