Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R3/MetalSonic.txt
1319 views
1
//----------------Sonic CD Metal Sonic 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.BaseY // (Metal Sonic's Y position without the oscillating effect)
8
// (Value2 is unused)
9
#alias Object.Value3 : Object.Speed
10
#alias Object.Value4 : Object.FrameTimer
11
12
// Spike Debris Aliases
13
#alias Object.iXPos : Debris.iXPos
14
#alias Object.iYPos : Debris.iYPos
15
#alias Object.Value0 : Debris.XVelocity
16
#alias Object.Value1 : Debris.YVelocity
17
18
// Amy Aliases
19
#alias Object[-1].XPos : Amy.XPos
20
#alias Object[-1].YPos : Amy.YPos
21
#alias Object[-1].Direction : Amy.Direction
22
#alias Object[-1].Frame : Amy.Frame
23
#alias Object[-1].State : Amy.State
24
25
// States
26
#alias 0 : METALSONIC_WAIT
27
#alias 1 : METALSONIC_APPROACH
28
#alias 2 : METALSONIC_CATCH_AMY
29
#alias 3 : METALSONIC_RISE
30
#alias 4 : METALSONIC_HOVER
31
#alias 5 : METALSONIC_FLEE
32
33
// Amy States
34
#alias 4 : AMY_KIDNAP
35
36
// Stage SFX
37
#alias 8 : SFX_S_CRUMBLE
38
#alias 9 : SFX_S_AMYCAPTURED
39
40
41
sub ObjectMain
42
switch Object.State
43
case METALSONIC_WAIT // Starts in this state, gets switched to METALSONIC_APPROACH by Amy
44
break
45
46
case METALSONIC_APPROACH
47
Object.XPos -= 0x30000
48
Object.Frame++
49
Object.Frame &= 1
50
51
TempValue0 = 0
52
53
ArrayPos0 = Object.EntityNo
54
ArrayPos0++
55
while TempValue0 < 3
56
if Object[ArrayPos0].Type > TypeName[Blank Object]
57
TempValue1 = Object[ArrayPos0].XPos
58
TempValue1 += 0x240000
59
60
if Object.XPos < TempValue1
61
// Destroy Spikes
62
Object[ArrayPos0].Type = TypeName[Blank Object]
63
TempValue2 = Object[ArrayPos0].PropertyValue
64
TempValue2 <<= 2
65
66
// Create Debris
67
CreateTempObject(TypeName[Spike Debris], TempValue2, Object[ArrayPos0].XPos, Object[ArrayPos0].YPos)
68
Debris[TempObjectPos].iXPos -= 9
69
Debris[TempObjectPos].iYPos -= 9
70
Debris[TempObjectPos].XVelocity = -0x10000
71
Debris[TempObjectPos].YVelocity = -0x30000
72
TempValue2++
73
74
CreateTempObject(TypeName[Spike Debris], TempValue2, Object[ArrayPos0].XPos, Object[ArrayPos0].YPos)
75
Debris[TempObjectPos].iXPos += 8
76
Debris[TempObjectPos].iYPos -= 9
77
Debris[TempObjectPos].XVelocity = 0x10000
78
Debris[TempObjectPos].YVelocity = -0x30000
79
TempValue2++
80
81
CreateTempObject(TypeName[Spike Debris], TempValue2, Object[ArrayPos0].XPos, Object[ArrayPos0].YPos)
82
Debris[TempObjectPos].iXPos -= 9
83
Debris[TempObjectPos].iYPos += 8
84
Debris[TempObjectPos].XVelocity = -0x10000
85
Debris[TempObjectPos].YVelocity = -0x18000
86
TempValue2++
87
88
CreateTempObject(TypeName[Spike Debris], TempValue2, Object[ArrayPos0].XPos, Object[ArrayPos0].YPos)
89
Debris[TempObjectPos].iXPos += 8
90
Debris[TempObjectPos].iYPos += 8
91
Debris[TempObjectPos].XVelocity = 0x10000
92
Debris[TempObjectPos].YVelocity = -0x18000
93
TempValue2++
94
95
96
PlayStageSfx(SFX_S_CRUMBLE, false)
97
98
#platform: Use_Haptics
99
HapticEffect(96, 0, 0, 0)
100
#endplatform
101
end if
102
end if
103
104
ArrayPos0++
105
TempValue0++
106
loop
107
108
TempValue0 = Amy.XPos
109
TempValue0 += 0x200000
110
if Object.XPos < TempValue0
111
Object.State = METALSONIC_CATCH_AMY
112
Object.Frame = 2
113
Object.BaseY = Object.YPos
114
Amy.Frame = 8
115
Amy.State = AMY_KIDNAP
116
PlayStageSfx(SFX_S_AMYCAPTURED, false)
117
end if
118
break
119
120
case METALSONIC_CATCH_AMY
121
if Object.Timer > 8
122
if Player.XPos < Object.XPos
123
Object.Direction = FACING_LEFT
124
else
125
Object.Direction = FACING_RIGHT
126
end if
127
end if
128
129
Sin(Object.YPos, Object.Timer)
130
Object.YPos <<= 9
131
Object.YPos += Object.BaseY
132
133
Object.Timer += 8
134
if Object.Timer > 607
135
Object.State = METALSONIC_RISE
136
Object.Timer = 0
137
end if
138
break
139
140
case METALSONIC_RISE
141
if Player.XPos < Object.XPos
142
Object.Direction = FACING_LEFT
143
else
144
Object.Direction = FACING_RIGHT
145
end if
146
147
if Object.Timer < 40
148
Object.Timer++
149
Object.BaseY -= 0x20000
150
Object.YPos -= 0x20000
151
else
152
Object.State = METALSONIC_HOVER
153
Object.Timer = 256
154
end if
155
break
156
157
case METALSONIC_HOVER
158
if Player.XPos < Object.XPos
159
Object.Direction = FACING_LEFT
160
else
161
Object.Direction = FACING_RIGHT
162
end if
163
164
Sin(Object.YPos, Object.Timer)
165
Object.YPos <<= 9
166
Object.YPos += Object.BaseY
167
168
Object.Timer += 8
169
if Object.Timer > 976
170
Object.State = METALSONIC_FLEE
171
Object.Direction = FACING_RIGHT
172
end if
173
break
174
175
case METALSONIC_FLEE
176
if Object.Speed < 0x60000
177
Object.Speed += 0x2000
178
end if
179
Object.XPos += Object.Speed
180
181
if Object.OutOfBounds == true
182
// Erase Metal
183
TempValue0 = Object.EntityNo
184
ResetObjectEntity(TempValue0, TypeName[Blank Object], 0, 0, 0)
185
// Erase Amy
186
TempValue0--
187
ResetObjectEntity(TempValue0, TypeName[Blank Object], 0, 0, 0)
188
end if
189
break
190
end switch
191
end sub
192
193
194
sub ObjectDraw
195
if Object.State < METALSONIC_CATCH_AMY
196
DrawSprite(Object.Frame)
197
else
198
Amy.XPos = Object.XPos
199
Amy.YPos = Object.YPos
200
Amy.Direction = Object.Direction
201
202
TempValue0 = Object.FrameTimer
203
TempValue0 >>= 1
204
TempValue0 += 3
205
DrawSpriteFX(TempValue0, FX_FLIP, Object.XPos, Object.YPos)
206
207
Object.FrameTimer++
208
Object.FrameTimer &= 7
209
DrawSpriteFX(Object.Frame, FX_FLIP, Object.XPos, Object.YPos)
210
end if
211
end sub
212
213
214
sub ObjectStartup
215
LoadSpriteSheet("R3/Objects.gif")
216
217
// Overdrive Attack
218
SpriteFrame(-24, -16, 48, 32, 67, 68) // #0 - Overdrive Attack Frame 0
219
SpriteFrame(-24, -16, 48, 32, 116, 68) // #1 - Overdrive Attack Frame 1
220
221
// Metal Idle
222
SpriteFrame(-16, -24, 32, 48, 1, 108) // #2 - Idle
223
224
// Booster
225
SpriteFrame(-24, -12, 24, 24, 214, 43) // #3 - Booster Frame 0
226
SpriteFrame(0, 0, 2, 2, 165, 68) // #4 - Booster Frame 1 / Cheat Sprite
227
SpriteFrame(-28, -16, 32, 32, 165, 68) // #5 - Booster Frame 2
228
SpriteFrame(0, 0, 2, 2, 165, 68) // #6 - Booster Frame 3 / Cheat Sprite
229
end sub
230
231
232
// ========================
233
// Editor Subs
234
// ========================
235
236
sub RSDKDraw
237
DrawSprite(0)
238
end sub
239
240
241
sub RSDKLoad
242
LoadSpriteSheet("R3/Objects.gif")
243
244
SpriteFrame(-24, -16, 48, 32, 67, 68) // #0 - Overdrive Attack Frame 0
245
246
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
247
end sub
248
249