Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/RSpringCage.txt
1319 views
1
//---------------Sonic CD R Spring Cage Script----------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Note - Object[+1] should be an R7Spring object
6
7
// Aliases
8
#alias Object.Value0 : Object.FullAngle
9
#alias Object.Value1 : Object.Angle
10
#alias Object.Value3 : Object.RightArmOffset
11
12
// R7 Spring Aliases
13
#alias Object.Value0 : Object.Timer
14
15
// States
16
#alias 0 : RSPRINGCAGE_IDLE
17
#alias 1 : RSPRINGCAGE_LOCKINPLAYER
18
#alias 2 : RSPRINGCAGE_SHOOTPLAYER
19
#alias 3 : RSPRINGCAGE_RESTORE
20
21
// Gravity
22
#alias 1 : GRAVITY_AIR
23
24
// Stage SFX
25
#alias 0 : SFX_S_LARGEBOOSTER // In origins, this SFX is Launcher
26
#alias 1 : SFX_S_SWITCH
27
28
// Property Values
29
#alias 0 : ROTATING_CAGE
30
#alias 1 : STATIC_CAGE
31
32
33
sub ObjectMain
34
switch Object.State
35
case RSPRINGCAGE_IDLE
36
if Object.PropertyValue == ROTATING_CAGE
37
Object.FullAngle++
38
Object.FullAngle %= 48
39
40
Object.Angle = Object.FullAngle
41
Object.Angle /= 6
42
end if
43
break
44
45
case RSPRINGCAGE_LOCKINPLAYER
46
if Object.RightArmOffset > 0
47
// Close it in, 2 pixels per frame
48
Object.RightArmOffset -= 0x20000
49
else
50
PlayStageSfx(SFX_S_SWITCH, false)
51
Object.State++
52
end if
53
break
54
55
case RSPRINGCAGE_SHOOTPLAYER
56
if Player.State != Player_State_Death
57
if Object.PropertyValue == ROTATING_CAGE
58
Object.FullAngle++
59
Object.FullAngle %= 48
60
Object.Angle = Object.FullAngle
61
Object.Angle /= 6
62
end if
63
64
Player.Animation = ANI_JUMPING
65
66
Player.XPos = Object.XPos
67
Player.YPos = Object.YPos
68
69
switch Object.Angle
70
case 0
71
Player.XPos += 0x200000 // Offset of 32 pixels right
72
break
73
case 1
74
Player.XPos += 0x180000 // Offset of 24 pixels right
75
Player.YPos -= 0x180000 // Offset of 24 pixels up
76
break
77
case 2
78
Player.YPos -= 0x200000 // Offset of 32 pixels up
79
break
80
case 3
81
Player.XPos -= 0x180000 // Offset of 24 pixels left
82
Player.YPos -= 0x180000 // Offset of 24 pixels up
83
break
84
case 4
85
Player.XPos -= 0x200000 // Offset of 32 pixels left
86
break
87
case 5
88
Player.XPos -= 0x180000 // Offset of 24 pixels left
89
Player.YPos += 0x180000 // Offset of 24 pixels down
90
break
91
case 6
92
Player.YPos += 0x200000 // Offset of 32 pixels down
93
break
94
case 7
95
Player.XPos += 0x180000 // Offset of 24 pixels right
96
Player.YPos += 0x180000 // Offset of 24 pixels down
97
break
98
end switch
99
100
if Player.JumpPress == true
101
PlayStageSfx(SFX_S_LARGEBOOSTER, false)
102
103
#platform: Use_Origins
104
Player.State = Player_State_Air_NoDropDash
105
#endplatform
106
107
#platform: Use_Standalone
108
Player.State = Player_State_Air
109
#endplatform
110
Player.Gravity = GRAVITY_AIR
111
Player.Timer = 0
112
113
// Tell the spring to start animating
114
Object[+1].Timer = 1
115
116
Object.State++
117
switch Object.Angle
118
case 0
119
Player.Speed = 0x100000
120
Player.XVelocity = 0x100000
121
Player.YVelocity = 0
122
break
123
case 1
124
Player.Speed = 0xC0000
125
Player.XVelocity = 0xC0000
126
Player.YVelocity = -720896
127
break
128
case 2
129
Player.Speed = 0
130
Player.XVelocity = 0
131
Player.YVelocity = -0x100000
132
break
133
case 3
134
Player.Speed = -0xC0000
135
Player.XVelocity = -0xC0000
136
Player.YVelocity = -720896
137
break
138
case 4
139
Player.Speed = -0x100000
140
Player.XVelocity = -0x100000
141
Player.YVelocity = 0
142
break
143
case 5
144
Player.Speed = -0xC0000
145
Player.XVelocity = -0xC0000
146
Player.YVelocity = 720896
147
break
148
case 6
149
Player.Speed = 0
150
Player.XVelocity = 0
151
Player.YVelocity = 0x100000
152
break
153
case 7
154
Player.Speed = 0xC0000
155
Player.XVelocity = 0xC0000
156
Player.YVelocity = 720896
157
break
158
end switch
159
end if
160
else
161
Object.State = RSPRINGCAGE_RESTORE
162
end if
163
break
164
165
case RSPRINGCAGE_RESTORE
166
if Object[+1].Timer == 0
167
if Object.RightArmOffset < 0x300000
168
// Opening it back up, 8 pixels per frame
169
Object.RightArmOffset += 0x80000
170
else
171
Object.State = RSPRINGCAGE_IDLE
172
end if
173
end if
174
break
175
176
end switch
177
178
// Change the spring's angle
179
180
switch Object.Angle
181
case 0
182
Object[+1].Direction = FACING_RIGHT
183
Object[+1].PropertyValue = 1
184
break
185
case 1
186
Object[+1].Direction = FACING_RIGHT
187
Object[+1].PropertyValue = 4
188
break
189
case 2
190
Object[+1].Direction = FACING_RIGHT
191
Object[+1].PropertyValue = 0
192
break
193
case 3
194
Object[+1].Direction = FACING_RIGHT
195
Object[+1].PropertyValue = 5
196
break
197
case 4
198
Object[+1].Direction = FACING_RIGHT
199
Object[+1].PropertyValue = 2
200
break
201
case 5
202
Object[+1].Direction = 2
203
Object[+1].PropertyValue = 5
204
break
205
case 6
206
Object[+1].Direction = FACING_RIGHT
207
Object[+1].PropertyValue = 3
208
break
209
case 7
210
Object[+1].Direction = 2
211
Object[+1].PropertyValue = 4
212
break
213
end switch
214
215
end sub
216
217
218
sub ObjectPlayerInteraction
219
220
if Object.State == RSPRINGCAGE_IDLE
221
PlayerObjectCollision(C_TOUCH, -24, -24, 24, 24)
222
if CheckResult == true
223
Object.State = RSPRINGCAGE_LOCKINPLAYER
224
225
// Put the player inside the cage
226
Player.XPos = Object.XPos
227
Player.YPos = Object.YPos
228
Player.State = Player_State_Static
229
Player.Animation = ANI_JUMPING
230
Player.Speed = 0
231
Player.XVelocity = 0
232
Player.YVelocity = 0
233
234
// 8 possible directions, 8 possible jump locations~
235
switch Object.Angle
236
case 0
237
Player.XPos += 0x200000 // Offset of 32 pixels right
238
break
239
case 1
240
Player.XPos += 0x180000 // Offset of 24 pixels right
241
Player.YPos -= 0x180000 // Offset of 24 pixels up
242
break
243
case 2
244
Player.YPos -= 0x200000 // Offset of 32 pixels up
245
break
246
case 3
247
Player.XPos -= 0x180000 // Offset of 24 pixels left
248
Player.YPos -= 0x180000 // Offset of 24 pixels up
249
break
250
case 4
251
Player.XPos -= 0x200000 // Offset of 32 pixels left
252
break
253
case 5
254
Player.XPos -= 0x180000 // Offset of 24 pixels left
255
Player.YPos += 0x180000 // Offset of 24 pixels down
256
break
257
case 6
258
Player.YPos += 0x200000 // Offset of 32 pixels down
259
break
260
case 7
261
Player.XPos += 0x180000 // Offset of 24 pixels right
262
Player.YPos += 0x180000 // Offset of 24 pixels down
263
break
264
end switch
265
end if
266
end if
267
268
end sub
269
270
271
sub ObjectDraw
272
273
// Different draw routines for the 8 possible directions
274
275
switch Object.Angle
276
case 0
277
DrawSprite(1)
278
Object.Direction = 2
279
TempValue0 = Object.XPos
280
TempValue0 -= Object.RightArmOffset
281
DrawSpriteFX(1, FX_FLIP, TempValue0, Object.YPos)
282
break
283
284
case 1
285
DrawSprite(2)
286
Object.Direction = 3
287
TempValue2 = Object.RightArmOffset
288
TempValue2 >>= 1
289
TempValue0 = Object.XPos
290
TempValue0 -= TempValue2
291
TempValue1 = Object.YPos
292
TempValue1 += TempValue2
293
DrawSpriteFX(3, FX_FLIP, TempValue0, TempValue1)
294
break
295
296
case 2
297
DrawSprite(4)
298
Object.Direction = FACING_LEFT
299
TempValue1 = Object.YPos
300
TempValue1 += Object.RightArmOffset
301
DrawSpriteFX(4, FX_FLIP, Object.XPos, TempValue1)
302
break
303
304
case 3
305
Object.Direction = FACING_LEFT
306
TempValue2 = Object.RightArmOffset
307
TempValue2 >>= 1
308
TempValue0 = Object.XPos
309
TempValue0 += TempValue2
310
TempValue1 = Object.YPos
311
TempValue1 += TempValue2
312
DrawSpriteFX(2, FX_FLIP, TempValue0, TempValue1)
313
Object.Direction = 2
314
DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)
315
break
316
317
case 4
318
TempValue0 = Object.XPos
319
TempValue0 += Object.RightArmOffset
320
DrawSpriteXY(5, TempValue0, Object.YPos)
321
Object.Direction = 2
322
DrawSpriteFX(5, FX_FLIP, Object.XPos, Object.YPos)
323
break
324
325
case 5
326
Object.Direction = 3
327
DrawSpriteFX(2, FX_FLIP, Object.XPos, Object.YPos)
328
Object.Direction = FACING_RIGHT
329
TempValue2 = Object.RightArmOffset
330
TempValue2 >>= 1
331
TempValue0 = Object.XPos
332
TempValue0 += TempValue2
333
TempValue1 = Object.YPos
334
TempValue1 -= TempValue2
335
DrawSpriteFX(3, FX_FLIP, TempValue0, TempValue1)
336
break
337
338
case 6
339
Object.Direction = 2
340
TempValue1 = Object.YPos
341
TempValue1 -= Object.RightArmOffset
342
DrawSpriteFX(4, FX_FLIP, Object.XPos, TempValue1)
343
Object.Direction = 3
344
DrawSpriteFX(4, FX_FLIP, Object.XPos, Object.YPos)
345
break
346
347
case 7
348
Object.Direction = 2
349
TempValue2 = Object.RightArmOffset
350
TempValue2 >>= 1
351
TempValue0 = Object.XPos
352
TempValue0 -= TempValue2
353
TempValue1 = Object.YPos
354
TempValue1 -= TempValue2
355
DrawSpriteFX(2, FX_FLIP, TempValue0, TempValue1)
356
Object.Direction = FACING_LEFT
357
DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)
358
break
359
360
end switch
361
362
DrawSprite(0)
363
364
end sub
365
366
367
sub ObjectStartup
368
369
LoadSpriteSheet("R7/Objects.gif")
370
371
// Cage Frames
372
373
// Pivot Post Frame
374
SpriteFrame(-8, -8, 16, 16, 90, 52)
375
376
// Top Horizontal Half
377
SpriteFrame(-8, -28, 64, 24, 34, 96)
378
379
// Top Diagonal Half
380
SpriteFrame(-24, -56, 56, 56, 59, 121)
381
382
// Bottom Diagonal Half
383
SpriteFrame(-56, -24, 56, 56, 59, 121)
384
385
// (Shared) Vertical Half
386
SpriteFrame(-28, -56, 24, 64, 34, 121)
387
388
// Bottom Horizontal Half
389
SpriteFrame(-56, -28, 64, 24, 34, 96)
390
391
// Setup all Rotating Cage objects within the level
392
ArrayPos0 = 32
393
while ArrayPos0 < 1056
394
if Object[ArrayPos0].Type == TypeName[R Spring Cage]
395
396
// Focus on the Cage's corresponding R7 Spring object
397
ArrayPos1 = ArrayPos0
398
ArrayPos1++
399
400
Object[ArrayPos0].DrawOrder = 4
401
402
// Set the right arm to start 48 pixels back
403
Object[ArrayPos0].RightArmOffset = 0x300000
404
405
// Move the spring to the Cage's position too
406
Object[ArrayPos1].XPos = Object[ArrayPos0].XPos
407
Object[ArrayPos1].YPos = Object[ArrayPos0].YPos
408
end if
409
410
ArrayPos0++
411
loop
412
413
end sub
414
415
416
// ========================
417
// Editor Subs
418
// ========================
419
420
sub RSDKEdit
421
if Editor.ReturnVariable == true
422
switch Editor.VariableID
423
case EDIT_VAR_PROPVAL // Property Value
424
CheckResult = Object.PropertyValue
425
break
426
case 0 // Type
427
CheckResult = Object.PropertyValue
428
break
429
end switch
430
else
431
switch Editor.VariableID
432
case EDIT_VAR_PROPVAL // Property Value
433
Object.PropertyValue = Editor.VariableValue
434
break
435
case 0 // Type
436
Object.PropertyValue = Editor.VariableValue
437
break
438
end switch
439
end if
440
end sub
441
442
443
sub RSDKDraw
444
DrawSprite(0)
445
Object.Direction = FACING_LEFT
446
TempValue1 = Object.YPos
447
TempValue1 += 0x300000
448
DrawSpriteFX(0, FX_FLIP, Object.XPos, TempValue1)
449
450
if Editor.ShowGizmos == true
451
GetObjectType(TempValue0, "R7 Spring")
452
453
ArrayPos1 = Object[+1].EntityNo
454
if Object[ArrayPos1].type != TempValue0
455
// Uh oh! The next object is supposed to be a special spring, but here it isn't...
456
// Gotta let the user know!
457
458
Editor.DrawingOverlay = true
459
460
// First draw a red line from the cage to the invalid object
461
DrawArrow(Object.XPos, Object.YPos, Object[ArrayPos1].XPos, Object[ArrayPos1].YPos, 255, 0, 0)
462
463
// And now draw an X
464
465
TempValue0 = Object[ArrayPos1].XPos
466
TempValue0 -= 0x100000
467
468
TempValue1 = Object[ArrayPos1].YPos
469
TempValue1 -= 0x100000
470
471
TempValue2 = Object[ArrayPos1].XPos
472
TempValue2 += 0x100000
473
474
TempValue3 = Object[ArrayPos1].YPos
475
TempValue3 += 0x100000
476
477
DrawLine(TempValue0, TempValue1, TempValue2, TempValue3, 255, 0, 0)
478
DrawLine(TempValue2, TempValue1, TempValue0, TempValue3, 255, 0, 0)
479
480
Editor.DrawingOverlay = false
481
end if
482
end if
483
end sub
484
485
486
sub RSDKLoad
487
LoadSpriteSheet("R7/Objects.gif")
488
SpriteFrame(-28, -56, 24, 64, 34, 121)
489
490
AddEditorVariable("Type")
491
SetActiveVariable("Type")
492
AddEnumVariable("Rotate", 0)
493
AddEnumVariable("Static", 1)
494
end sub
495
496