Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/Dango.txt
1319 views
1
//-------------------Sonic CD Dango Script--------------------//
2
//--------Scripted by Christian Whitehead 'The Taxman'--------//
3
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//
4
5
// Aliases
6
#alias Object.Value0 : Object.Timer
7
#alias Object.Value1 : Object.XOriginPos
8
#alias Object.Value2 : Object.YOriginPos
9
#alias Object.Value3 : Object.XVelocity
10
#alias Object.Value4 : Object.ChaseChain
11
12
#alias Object.PropertyValue : Object.Quality
13
14
// States
15
#alias 0 : DANGO_WALK
16
#alias 1 : DANGO_CURL1
17
#alias 2 : DANGO_CURL2
18
#alias 3 : DANGO_CHARGEROLL
19
#alias 4 : DANGO_ROLLING
20
#alias 5 : DANGO_UNCURL1
21
#alias 6 : DANGO_UNCURL2
22
#alias 7 : DANGO_UNCURLED
23
#alias 8 : DANGO_OFFSCREEN // Unused
24
25
// Gravity
26
#alias 1 : GRAVITY_AIR
27
28
// Collision Sides
29
#alias 0 : CSIDE_FLOOR
30
#alias 1 : CSIDE_LWALL
31
#alias 2 : CSIDE_RWALL
32
33
// Badnik Quality / Property Values
34
#alias 0 : GOOD_QUALITY
35
#alias 1 : BAD_QUALITY
36
37
// Priority
38
#alias 0 : PRIORITY_BOUNDS
39
#alias 1 : PRIORITY_ACTIVE
40
41
42
sub ObjectMain
43
if Object.Quality == GOOD_QUALITY
44
switch Object.State
45
case DANGO_WALK
46
Object.Priority = PRIORITY_ACTIVE
47
48
Object.Frame = Object.Timer
49
Object.Frame /= 10
50
51
Object.Timer++
52
Object.Timer %= 20
53
54
Object.XPos += Object.XVelocity
55
56
if Object.Direction == FACING_RIGHT
57
ObjectTileGrip(CSIDE_FLOOR, -5, 15, 0)
58
else
59
ObjectTileGrip(CSIDE_FLOOR, 5, 15, 0)
60
end if
61
62
if CheckResult == false
63
FlipSign(Object.XVelocity)
64
Object.Direction++
65
Object.Direction &= FACING_LEFT
66
67
Object.ChaseChain = 0
68
else
69
if Object.XVelocity > 0
70
ObjectTileCollision(CSIDE_LWALL, 16, 8, 0)
71
if CheckResult == true
72
FlipSign(Object.XVelocity)
73
Object.Direction++
74
Object.Direction &= FACING_LEFT
75
76
Object.ChaseChain = 0
77
end if
78
else
79
ObjectTileCollision(CSIDE_RWALL, -16, 8, 0)
80
if CheckResult == true
81
FlipSign(Object.XVelocity)
82
Object.Direction++
83
Object.Direction &= FACING_LEFT
84
85
Object.ChaseChain = 0
86
end if
87
end if
88
end if
89
break
90
91
case DANGO_CURL1
92
Object.Frame = 4
93
if Object.Timer < 8
94
Object.Timer++
95
else
96
Object.Timer = 0
97
Object.State++
98
end if
99
break
100
101
case DANGO_CURL2
102
Object.Frame = 5
103
if Object.Timer < 6
104
Object.Timer++
105
else
106
Object.Timer = 0
107
Object.State++
108
end if
109
break
110
111
case DANGO_CHARGEROLL
112
Object.Frame = Object.AnimationTimer
113
Object.Frame /= 5
114
Object.Frame += 6
115
116
Object.AnimationTimer++
117
Object.AnimationTimer %= 10
118
119
if Object.Timer < 34
120
Object.Timer++
121
else
122
Object.Timer = 0
123
Object.State++
124
if Object.Direction == FACING_RIGHT
125
Object.XVelocity = -0x40000
126
else
127
Object.XVelocity = 0x40000
128
end if
129
end if
130
break
131
132
case DANGO_ROLLING
133
Object.Frame = Object.AnimationTimer
134
Object.Frame /= 5
135
Object.Frame += 6
136
137
Object.AnimationTimer++
138
Object.AnimationTimer %= 10
139
140
Object.XPos += Object.XVelocity
141
142
if Object.Direction == FACING_RIGHT
143
ObjectTileGrip(CSIDE_FLOOR, -5, 15, 0)
144
else
145
ObjectTileGrip(CSIDE_FLOOR, 5, 15, 0)
146
end if
147
148
if CheckResult == false
149
Object.State++
150
Object.ChaseChain++
151
else
152
if Object.XVelocity > 0
153
ObjectTileCollision(CSIDE_LWALL, 16, 8, 0)
154
if CheckResult == true
155
Object.State++
156
Object.ChaseChain++
157
end if
158
else
159
ObjectTileCollision(CSIDE_RWALL, -16, 8, 0)
160
if CheckResult == true
161
Object.State++
162
Object.ChaseChain++
163
end if
164
end if
165
end if
166
break
167
168
case DANGO_UNCURL1
169
Object.Frame = 5
170
if Object.Timer < 6
171
Object.Timer++
172
else
173
Object.Timer = 0
174
Object.State++
175
end if
176
break
177
178
case DANGO_UNCURL2
179
Object.Frame = 4
180
if Object.Timer < 8
181
Object.Timer++
182
else
183
Object.Timer = 0
184
Object.State++
185
end if
186
break
187
188
case DANGO_UNCURLED
189
Object.Frame = 0
190
if Object.Timer < 16
191
Object.Timer++
192
else
193
Object.Timer = 0
194
Object.State = DANGO_WALK
195
if Object.ChaseChain > 7
196
// Tried going in the same direction 8 times now...
197
// Even if the player's the other way, go ahead and change directions
198
199
Object.Direction++
200
Object.Direction &= FACING_LEFT
201
Object.ChaseChain = 0
202
end if
203
204
if Object.Direction == FACING_RIGHT
205
Object.XVelocity = -0x6000
206
else
207
Object.XVelocity = 0x6000
208
end if
209
end if
210
break
211
212
case DANGO_OFFSCREEN
213
// This state is unused, but it serves just about the same buffer purpose as it does with other badniks
214
if Object.OutOfBounds == true
215
Object.State = DANGO_WALK
216
Object.Priority = PRIORITY_BOUNDS
217
end if
218
break
219
220
end switch
221
else
222
switch Object.State
223
case DANGO_WALK
224
Object.Priority = PRIORITY_ACTIVE
225
226
Object.Frame = Object.Timer
227
Object.Frame /= 30
228
Object.Frame += 2
229
230
Object.Timer++
231
Object.Timer %= 60
232
233
Object.XPos += Object.XVelocity
234
235
if Object.Direction == FACING_RIGHT
236
ObjectTileGrip(CSIDE_FLOOR, -5, 15, 0)
237
else
238
ObjectTileGrip(CSIDE_FLOOR, 5, 15, 0)
239
end if
240
241
if CheckResult == false
242
FlipSign(Object.XVelocity)
243
Object.Direction++
244
Object.Direction &= FACING_LEFT
245
246
Object.ChaseChain = 0
247
else
248
if Object.XVelocity > 0
249
ObjectTileCollision(CSIDE_LWALL, 16, 8, 0)
250
if CheckResult == true
251
FlipSign(Object.XVelocity)
252
Object.Direction++
253
Object.Direction &= FACING_LEFT
254
255
Object.ChaseChain = 0
256
end if
257
else
258
ObjectTileCollision(CSIDE_RWALL, -16, 8, 0)
259
if CheckResult == true
260
FlipSign(Object.XVelocity)
261
Object.Direction++
262
Object.Direction &= FACING_LEFT
263
264
Object.ChaseChain = 0
265
end if
266
end if
267
end if
268
break
269
270
case DANGO_CURL1
271
Object.Frame = 4
272
if Object.Timer < 20
273
Object.Timer++
274
else
275
Object.Timer = 0
276
Object.State++
277
end if
278
break
279
280
case DANGO_CURL2
281
Object.Frame = 5
282
if Object.Timer < 12
283
Object.Timer++
284
else
285
Object.Timer = 0
286
Object.State++
287
end if
288
break
289
290
case DANGO_CHARGEROLL
291
Object.Frame = Object.AnimationTimer
292
Object.Frame /= 10
293
Object.Frame += 8
294
295
Object.AnimationTimer++
296
Object.AnimationTimer %= 20
297
298
if Object.Timer < 96
299
Object.Timer++
300
else
301
Object.Timer = 0
302
Object.State++
303
if Object.Direction == FACING_RIGHT
304
Object.XVelocity = -0x10000
305
else
306
Object.XVelocity = 0x10000
307
end if
308
end if
309
break
310
311
case DANGO_ROLLING
312
Object.Frame = Object.AnimationTimer
313
Object.Frame /= 10
314
Object.Frame += 8
315
316
Object.AnimationTimer++
317
Object.AnimationTimer %= 20
318
319
Object.XPos += Object.XVelocity
320
321
if Object.Direction == FACING_RIGHT
322
ObjectTileGrip(CSIDE_FLOOR, -5, 15, 0)
323
else
324
ObjectTileGrip(CSIDE_FLOOR, 5, 15, 0)
325
end if
326
327
if CheckResult == false
328
Object.State++
329
Object.ChaseChain++
330
else
331
if Object.XVelocity > 0
332
ObjectTileCollision(CSIDE_LWALL, 16, 8, 0)
333
if CheckResult == true
334
Object.State++
335
Object.ChaseChain++
336
end if
337
else
338
ObjectTileCollision(CSIDE_RWALL, -16, 8, 0)
339
if CheckResult == true
340
Object.State++
341
Object.ChaseChain++
342
end if
343
end if
344
end if
345
break
346
347
case DANGO_UNCURL1
348
Object.Frame = 5
349
if Object.Timer < 12
350
Object.Timer++
351
else
352
Object.Timer = 0
353
Object.State++
354
end if
355
break
356
357
case DANGO_UNCURL2
358
Object.Frame = 4
359
if Object.Timer < 20
360
Object.Timer++
361
else
362
Object.Timer = 0
363
Object.State++
364
end if
365
break
366
367
case DANGO_UNCURLED
368
Object.Frame = 2
369
if Object.Timer < 64
370
Object.Timer++
371
else
372
Object.Timer = 0
373
Object.State = DANGO_WALK
374
if Object.ChaseChain > 7
375
// Been going in the same direction for 8 cycles now...
376
// Even if it may be opposite of the player, go ahead and change directions because much isn't happening now anyway
377
378
Object.Direction++
379
Object.Direction &= FACING_LEFT
380
381
Object.ChaseChain = 0
382
end if
383
384
if Object.Direction == FACING_RIGHT
385
Object.XVelocity = -0x1000
386
else
387
Object.XVelocity = 0x1000
388
end if
389
end if
390
break
391
392
case DANGO_OFFSCREEN
393
// This state is unused as Dango uses a simpler OOB process instead
394
if Object.OutOfBounds == true
395
Object.State = DANGO_WALK
396
Object.Priority = PRIORITY_BOUNDS
397
end if
398
break
399
400
end switch
401
end if
402
403
// Standard Badnik stuff, make sure it shouldn't become a Flower automatically or anything
404
CallFunction(StageSetup_CheckGoodFuture)
405
406
// See if the Dango is out of bounds
407
if Object.OutOfBounds == true
408
409
// If it is, then see if its starting position is out of bounds too
410
TempValue0 = Object.XPos
411
TempValue1 = Object.YPos
412
413
Object.XPos = Object.XOriginPos
414
Object.YPos = Object.YOriginPos
415
416
if Object.OutOfBounds == true
417
// It is too, so in that case it's clear to restore the Dango to its original spot
418
Object.Priority = PRIORITY_BOUNDS
419
Object.State = DANGO_WALK
420
Object.Timer = 0
421
Object.Direction = FACING_RIGHT
422
423
Object.ChaseChain = 0
424
425
if Object.Quality == GOOD_QUALITY
426
Object.XVelocity = -0x6000
427
else
428
Object.XVelocity = -0x1000
429
end if
430
else
431
// Nope not ready yet, move back
432
433
Object.XPos = TempValue0
434
Object.YPos = TempValue1
435
end if
436
end if
437
438
end sub
439
440
441
sub ObjectPlayerInteraction
442
if Object.State == DANGO_WALK
443
// If the Dango's just wandering, then check to see if the player's stepped within activation range
444
if Object.Direction == FACING_RIGHT
445
PlayerObjectCollision(C_TOUCH, -112, -128, 0, 128)
446
else
447
PlayerObjectCollision(C_TOUCH, 0, -128, 112, 128)
448
end if
449
450
if CheckResult == true
451
// On the attack!
452
Object.State = DANGO_CURL1
453
end if
454
end if
455
456
switch Object.State
457
case DANGO_WALK
458
case DANGO_CURL1
459
case DANGO_CURL2
460
case DANGO_UNCURL1
461
case DANGO_UNCURL2
462
case DANGO_UNCURLED
463
// The Dango is in a breakable form, so just check for simple badnik breaking
464
#platform: Use_Standalone
465
PlayerObjectCollision(C_TOUCH, -14, -10, 14, 10)
466
#endplatform
467
#platform: Use_Origins
468
PlayerObjectCollision(C_ENEMY, -14, -10, 14, 10)
469
#endplatform
470
if CheckResult == true
471
CallFunction(Player_BadnikBreak)
472
end if
473
break
474
475
case DANGO_CHARGEROLL
476
#platform: Use_Standalone
477
PlayerObjectCollision(C_TOUCH, -14, -10, 14, 10)
478
#endplatform
479
#platform: Use_Origins
480
PlayerObjectCollision(C_ENEMY, -14, -10, 14, 10)
481
#endplatform
482
if CheckResult == true
483
CheckEqual(Player.Animation, ANI_JUMPING)
484
TempValue0 = CheckResult
485
CheckEqual(Player.Animation, ANI_SPINDASH)
486
TempValue0 |= CheckResult
487
if TempValue0 == true
488
// The player's rolled towards the Dango, so bounce the player back
489
Player.Speed = Player.XPos
490
Player.Speed -= Object.XPos
491
Player.Speed >>= 2
492
493
Player.XVelocity = Player.Speed
494
495
// Account for aerial bouncing too if needed
496
if Player.Gravity == GRAVITY_AIR
497
Player.YVelocity = Player.YPos
498
Player.YVelocity -= Object.YPos
499
Player.YVelocity >>= 2
500
end if
501
else
502
// Hurt the player
503
// (Note that there are edge cases with Tails where he may end up breaking the Dango with his tails, instead)
504
CallFunction(Player_BadnikBreak)
505
end if
506
end if
507
break
508
509
case DANGO_ROLLING
510
#platform: Use_Standalone
511
PlayerObjectCollision(C_TOUCH, -14, -10, 14, 10)
512
#endplatform
513
#platform: Use_Origins
514
PlayerObjectCollision(C_ENEMY, -14, -10, 14, 10)
515
#endplatform
516
if CheckResult == true
517
CheckEqual(Player.Animation, ANI_JUMPING)
518
TempValue0 = CheckResult
519
CheckEqual(Player.Animation, ANI_SPINDASH)
520
TempValue0 |= CheckResult
521
if TempValue0 == true
522
// The player's rolled towards the Dango, so recoil the both of them
523
524
Object.XVelocity = Player.XVelocity
525
Player.Speed = Player.XPos
526
Player.Speed -= Object.XPos
527
Player.Speed >>= 2
528
Player.XVelocity = Player.Speed
529
530
if Player.Gravity == GRAVITY_AIR
531
// Account for Y recoil, too
532
Player.YVelocity = Player.YPos
533
Player.YVelocity -= Object.YPos
534
Player.YVelocity >>= 2
535
else
536
// The player is on the ground, make them bounce back rolling
537
Player.State = Player_State_Roll
538
Player.Animation = ANI_JUMPING
539
end if
540
else
541
// Hurt the player
542
// (See above note about Tails's fluffy but dangerous parts)
543
CallFunction(Player_BadnikBreak)
544
end if
545
end if
546
break
547
548
end switch
549
550
end sub
551
552
553
sub ObjectDraw
554
if Object.State < DANGO_OFFSCREEN
555
DrawSpriteFX(Object.Frame, FX_FLIP, Object.XPos, Object.YPos)
556
end if
557
end sub
558
559
560
sub ObjectStartup
561
LoadSpriteSheet("R7/Objects.gif")
562
563
// Dango Frames
564
565
// 0-1 - Idle Animation, "Good" variant
566
SpriteFrame(-16, -7, 32, 24, 116, 121)
567
SpriteFrame(-16, -7, 32, 24, 149, 121)
568
569
// 2-3 - Idle Animation, "Bad" variant (version with the cracked shell frames)
570
SpriteFrame(-16, -7, 32, 24, 116, 146)
571
SpriteFrame(-16, -7, 32, 24, 149, 146)
572
573
// 4-5 - Curl
574
SpriteFrame(-16, -16, 32, 32, 51, 219)
575
SpriteFrame(-16, -16, 32, 32, 84, 219)
576
577
// 6-9 - Rolling Frames
578
SpriteFrame(-16, -15, 32, 32, 51, 186)
579
SpriteFrame(-16, -15, 32, 32, 117, 186)
580
SpriteFrame(-16, -16, 32, 32, 84, 186)
581
SpriteFrame(-16, -15, 32, 32, 51, 186)
582
583
// Cycle through the level and find all Dango objects
584
ArrayPos0 = 32
585
while ArrayPos0 < 1056
586
if Object[ArrayPos0].Type == TypeName[Dango]
587
588
// Set the Dango's initial positions
589
Object[ArrayPos0].XOriginPos = Object[ArrayPos0].XPos
590
Object[ArrayPos0].YOriginPos = Object[ArrayPos0].YPos
591
592
// Set its starting velocity too, "Bad" Dangos go slower than "Good" ones since they're, y'know, "Bad"
593
if Object[ArrayPos0].Quality == GOOD_QUALITY
594
// Speed of 0.375 pixels per frame
595
Object[ArrayPos0].XVelocity = -0x6000
596
else
597
// 0.0625 pixels per frame... that's hardly anything!
598
Object[ArrayPos0].XVelocity = -0x1000
599
end if
600
end if
601
602
ArrayPos0++
603
loop
604
605
end sub
606
607
608
// ========================
609
// Editor Subs
610
// ========================
611
612
sub RSDKEdit
613
if Editor.ReturnVariable == true
614
switch Editor.VariableID
615
case EDIT_VAR_PROPVAL // Property Value
616
case 0 // Condition
617
CheckResult = Object.PropertyValue
618
break
619
end switch
620
else
621
switch Editor.VariableID
622
case EDIT_VAR_PROPVAL // Property Value
623
case 0 // Condition
624
Object.PropertyValue = Editor.VariableValue
625
break
626
end switch
627
end if
628
end sub
629
630
631
sub RSDKDraw
632
DrawSprite(Object.Quality)
633
end sub
634
635
636
sub RSDKLoad
637
LoadSpriteSheet("R7/Objects.gif")
638
SpriteFrame(-16, -7, 32, 24, 116, 121) // Normal "Good" version
639
SpriteFrame(-16, -7, 32, 24, 116, 146) // Cracked "Bad" version
640
641
AddEditorVariable("Condition")
642
SetActiveVariable("Condition")
643
AddEnumVariable("Good", GOOD_QUALITY)
644
AddEnumVariable("Bad", BAD_QUALITY)
645
end sub
646
647