Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/SpringCage.txt
1319 views
1
//----------------Sonic CD 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
// Value2 is unused...
11
#alias Object.Value3 : Object.LaunchTimer
12
13
// R7 Spring Aliases
14
#alias Object.Value0 : Object.Timer
15
16
// States
17
#alias 0 : SPRINGCAGE_OPEN
18
#alias 1 : SPRINGCAGE_OCCUPIED
19
20
// Gravity
21
#alias 1 : GRAVITY_AIR
22
23
// Stage SFX
24
#alias 0 : SFX_S_LARGEBOOSTER // in origins, this SFX is Launcher
25
#alias 3 : SFX_S_LAUNCHER
26
27
// Property Values
28
#alias 0 : ROTATING_SPRING
29
// Could mention the rest, but they are all based on the normal springs so...
30
31
32
sub ObjectMain
33
if Object.State == SPRINGCAGE_OPEN
34
if Object.PropertyValue == ROTATING_SPRING
35
// Spin around
36
Object.FullAngle++
37
Object.FullAngle %= 48
38
39
Object.Angle = Object.FullAngle
40
Object.Angle /= 6
41
end if
42
43
// Update the content spring to show the correct sprite
44
switch Object.Angle
45
case 0
46
// Right
47
Object[+1].PropertyValue = 1
48
break
49
case 1
50
case 7
51
// Up right
52
Object[+1].PropertyValue = 4
53
break
54
case 2
55
case 6
56
// Up
57
Object[+1].PropertyValue = 0
58
break
59
case 3
60
case 5
61
// Up left
62
Object[+1].PropertyValue = 5
63
break
64
case 4
65
// Left
66
Object[+1].PropertyValue = 2
67
break
68
end switch
69
else
70
if Object.LaunchTimer < 90
71
if Player.State != Player_State_Death
72
Object.LaunchTimer++
73
74
if Object.LaunchTimer == 60
75
76
// Origins fixed the SFX the Cage uses
77
// This sound ID is only valid on Origins data files though, which is why we gotta separate it
78
#platform: Use_Origins
79
PlayStageSfx(SFX_S_LAUNCHER, false)
80
Player.State = Player_State_Air_NoDropDash
81
#endplatform
82
83
#platform: Use_Standalone
84
PlayStageSfx(SFX_S_LARGEBOOSTER, false)
85
Player.State = Player_State_Air
86
#endplatform
87
88
Player.Gravity = GRAVITY_AIR
89
Player.Timer = 0
90
91
// Activate the spring
92
Object[+1].Timer = 1
93
94
switch Object.Angle
95
case 0
96
Player.Speed = 0x100000
97
Player.XVelocity = 0x100000
98
Player.YVelocity = 0x000000
99
break
100
101
case 1
102
case 7
103
Player.Speed = 0x0C0000
104
Player.XVelocity = 0x0C0000
105
Player.YVelocity = -0x0B0000
106
break
107
108
case 2
109
case 6
110
Player.Speed = 0x000000
111
Player.XVelocity = 0x000000
112
Player.YVelocity = -0x100000
113
break
114
115
case 3
116
case 5
117
Player.Speed = -0x0C0000
118
Player.XVelocity = -0x0C0000
119
Player.YVelocity = -0x0B0000
120
break
121
122
case 4
123
Player.Speed = -0x100000
124
Player.XVelocity = -0x100000
125
Player.YVelocity = 0x000000
126
break
127
128
end switch
129
end if
130
else
131
Object.State = SPRINGCAGE_OPEN
132
Object.LaunchTimer = 0
133
end if
134
else
135
Object.State = SPRINGCAGE_OPEN
136
Object.LaunchTimer = 0
137
end if
138
end if
139
140
end sub
141
142
143
sub ObjectPlayerInteraction
144
if Object.State == SPRINGCAGE_OPEN
145
146
// See if the player's hopped in yet
147
PlayerObjectCollision(C_TOUCH, -28, -32, 28, 24)
148
if CheckResult == true
149
Object.State = SPRINGCAGE_OCCUPIED
150
151
// Move the player into the cage and set them up to be launched
152
Player.XPos = Object.XPos
153
Player.YPos = Object.YPos
154
Player.State = Player_State_Static
155
Player.Animation = ANI_JUMPING
156
Player.Speed = 0
157
Player.XVelocity = 0
158
Player.YVelocity = 0
159
160
// Make minor positioning corrections based on the cage's current angle
161
switch Object.Angle
162
case 0
163
Player.XPos += 0x200000 // 32 pixels right
164
break
165
case 1
166
case 7
167
Player.XPos += 0x180000 // 24 pixels right
168
Player.YPos -= 0x180000 // 24 pixels up
169
break
170
case 2
171
case 6
172
Player.YPos -= 0x200000 // 32 pixels up
173
break
174
case 3
175
case 5
176
Player.XPos -= 0x180000 // 24 pixels left
177
Player.YPos -= 0x180000 // 24 pixels up
178
break
179
case 4
180
Player.XPos -= 0x200000 // 32 pixels up
181
break
182
end switch
183
184
end if
185
end if
186
187
end sub
188
189
190
sub ObjectDraw
191
// Jump based on what angle the cage is currently
192
switch Object.Angle
193
case 0
194
// Facing right
195
DrawSprite(1)
196
Object.Direction = 2
197
DrawSpriteFX(1, FX_FLIP, Object.XPos, Object.YPos)
198
break
199
200
case 1
201
case 7
202
// Facing up-right
203
DrawSprite(2)
204
Object.Direction = 3
205
DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)
206
break
207
208
case 2
209
case 6
210
// Facing up
211
DrawSprite(4)
212
Object.Direction = FACING_LEFT
213
DrawSpriteFX(4, FX_FLIP, Object.XPos, Object.YPos)
214
break
215
216
case 3
217
case 5
218
// Facing up left
219
Object.Direction = FACING_LEFT
220
DrawSpriteFX(2, FX_FLIP, Object.XPos, Object.YPos)
221
Object.Direction = 2
222
DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)
223
break
224
225
case 4
226
// Facing left
227
DrawSprite(5)
228
Object.Direction = 2
229
DrawSpriteFX(5, FX_FLIP, Object.XPos, Object.YPos)
230
break
231
232
end switch
233
234
DrawSprite(0)
235
236
end sub
237
238
239
sub ObjectStartup
240
241
LoadSpriteSheet("R7/Objects.gif")
242
243
// Base Frame
244
SpriteFrame(-8, -8, 16, 16, 90, 52)
245
246
// Top Horizontal Half
247
SpriteFrame(-8, -28, 64, 24, 34, 96)
248
249
// Top Diagonal Half
250
SpriteFrame(-24, -56, 56, 56, 59, 121)
251
252
// Bottom Diagonal Half
253
SpriteFrame(-56, -24, 56, 56, 59, 121)
254
255
// Vertical Half
256
SpriteFrame(-28, -56, 24, 64, 34, 121)
257
258
// Bottom Horizontal Half
259
SpriteFrame(-56, -28, 64, 24, 34, 96)
260
261
ArrayPos0 = 32
262
while ArrayPos0 < 1056
263
if Object[ArrayPos0].Type == TypeName[Spring Cage]
264
ArrayPos1 = ArrayPos0
265
ArrayPos1++
266
switch Object[ArrayPos0].PropertyValue
267
case 1
268
Object[ArrayPos0].Angle = 4
269
Object[ArrayPos1].PropertyValue = 2
270
break
271
272
case 3
273
Object[ArrayPos0].Angle = 1
274
Object[ArrayPos1].PropertyValue = 1
275
break
276
277
case 4
278
Object[ArrayPos0].Angle = 2
279
Object[ArrayPos1].PropertyValue = 4
280
break
281
282
case 5
283
Object[ArrayPos0].Angle = 3
284
Object[ArrayPos1].PropertyValue = 5
285
break
286
287
case 6
288
Object[ArrayPos0].Angle = 0
289
Object[ArrayPos1].PropertyValue = 2
290
break
291
292
end switch
293
294
Object[ArrayPos0].DrawOrder = 4
295
296
// Move the spring to the cage
297
Object[ArrayPos1].XPos = Object[ArrayPos0].XPos
298
Object[ArrayPos1].YPos = Object[ArrayPos0].YPos
299
end if
300
301
ArrayPos0++
302
loop
303
304
end sub
305
306
307
// ========================
308
// Editor Subs
309
// ========================
310
311
sub RSDKEdit
312
if Editor.ReturnVariable == true
313
switch Editor.VariableID
314
case EDIT_VAR_PROPVAL // Property Value
315
CheckResult = Object.PropertyValue
316
break
317
case 0 // Direction
318
CheckResult = Object.PropertyValue
319
break
320
end switch
321
else
322
switch Editor.VariableID
323
case EDIT_VAR_PROPVAL // Property Value
324
Object.PropertyValue = Editor.VariableValue
325
break
326
case 0 // Direction
327
Object.PropertyValue = Editor.VariableValue
328
break
329
end switch
330
end if
331
end sub
332
333
334
sub RSDKDraw
335
switch Object.PropertyValue
336
case 1
337
DrawSprite(5)
338
Object.Direction = 2
339
DrawSpriteFX(5, FX_FLIP, Object.XPos, Object.YPos)
340
break
341
342
case 3
343
DrawSprite(2)
344
Object.Direction = 3
345
DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)
346
break
347
348
case 0
349
case 4
350
DrawSprite(4)
351
Object.Direction = FACING_LEFT
352
DrawSpriteFX(4, FX_FLIP, Object.XPos, Object.YPos)
353
break
354
355
case 5
356
Object.Direction = FACING_LEFT
357
DrawSpriteFX(2, FX_FLIP, Object.XPos, Object.YPos)
358
Object.Direction = 2
359
DrawSpriteFX(3, FX_FLIP, Object.XPos, Object.YPos)
360
break
361
362
case 6
363
DrawSprite(1)
364
Object.Direction = 2
365
DrawSpriteFX(1, FX_FLIP, Object.XPos, Object.YPos)
366
break
367
368
end switch
369
370
DrawSprite(0)
371
372
if Editor.ShowGizmos == true
373
GetObjectType(TempValue0, "R7 Spring")
374
375
ArrayPos1 = Object[+1].EntityNo
376
if Object[ArrayPos1].type != TempValue0
377
// Uh oh! The next object should be an R7 Spring object, but it isn't...
378
// Draw a bunch of red to let the user know
379
380
Editor.DrawingOverlay = true
381
382
DrawArrow(Object.XPos, Object.YPos, Object[ArrayPos1].XPos, Object[ArrayPos1].YPos, 255, 0, 0)
383
384
TempValue0 = Object[ArrayPos1].XPos
385
TempValue0 -= 0x100000
386
387
TempValue1 = Object[ArrayPos1].YPos
388
TempValue1 -= 0x100000
389
390
TempValue2 = Object[ArrayPos1].XPos
391
TempValue2 += 0x100000
392
393
TempValue3 = Object[ArrayPos1].YPos
394
TempValue3 += 0x100000
395
396
DrawLine(TempValue0, TempValue1, TempValue2, TempValue3, 255, 0, 0)
397
DrawLine(TempValue2, TempValue1, TempValue0, TempValue3, 255, 0, 0)
398
399
Editor.DrawingOverlay = false
400
end if
401
end if
402
end sub
403
404
405
sub RSDKLoad
406
LoadSpriteSheet("R7/Objects.gif")
407
SpriteFrame(-8, -8, 16, 16, 90, 52) // Base Frame
408
SpriteFrame(-8, -28, 64, 24, 34, 96) // Top Horizontal Half
409
SpriteFrame(-24, -56, 56, 56, 59, 121) // Top Diagonal Half
410
SpriteFrame(-56, -24, 56, 56, 59, 121) // Bottom Diagonal Half
411
SpriteFrame(-28, -56, 24, 64, 34, 121) // Vertical Half
412
SpriteFrame(-56, -28, 64, 24, 34, 96) // Bottom Horizontal Half
413
414
AddEditorVariable("Direction")
415
SetActiveVariable("Direction")
416
AddEnumVariable("Rotating", 0)
417
AddEnumVariable("Left", 1)
418
// 2 is pointing up dupe
419
AddEnumVariable("Up-Right", 3)
420
AddEnumVariable("Up", 4)
421
AddEnumVariable("Up-Left", 5)
422
AddEnumVariable("Right", 6)
423
end sub
424
425