Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R8/MechaBu.txt
1319 views
1
//-----------------Sonic CD Mecha Bu 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
8
#alias Object.Value2 : Object.XOriginPos
9
#alias Object.Value3 : Object.YOriginPos
10
#alias Object.Value4 : Object.HornTimer
11
#alias Object.Value5 : Object.SFXTimer
12
13
#alias Object.PropertyValue : Object.Quality
14
15
// States
16
#alias 0 : MECHABU_FINDGROUND
17
#alias 1 : MECHABU_BACKTRACK
18
#alias 2 : MECHABU_ADVANCE
19
20
// Stage SFX
21
#alias 1 : SFX_S_BUZZSAW
22
23
// Badnik Quality / Property Values
24
#alias 0 : GOOD_QUALITY
25
#alias 1 : BAD_QUALITY
26
27
// Collision Sides
28
#alias 0 : CSIDE_FLOOR
29
30
31
sub ObjectMain
32
switch Object.State
33
case MECHABU_FINDGROUND
34
// See if there's any ground to be found at the Bu's current position
35
ObjectTileCollision(CSIDE_FLOOR, 0, 15, 0)
36
37
if CheckResult == true
38
// Floor detected, go to the normal movement states now
39
40
Object.State = MECHABU_BACKTRACK
41
else
42
// The Bu's still in the air, so move a pixel down
43
44
Object.YPos += 0x10000
45
end if
46
break
47
48
case MECHABU_BACKTRACK
49
if Object.Timer < 416
50
Object.Timer++
51
52
// Move 0.3125 pixels right (opposite of the direction the Bu's currently towards)
53
Object.XPos += 0x5000
54
else
55
// Change direction, start going ahead now
56
57
Object.Timer = 0
58
Object.State = MECHABU_ADVANCE
59
end if
60
61
// Stay with the ground even when going backwards, quite the fancy moonwalk!
62
ObjectTileGrip(CSIDE_FLOOR, 0, 15, 0)
63
break
64
65
case MECHABU_ADVANCE
66
if Object.Timer < 416
67
Object.Timer++
68
69
// Move 0.3125 pixels to the left (in the direction the Bu is facing)
70
Object.XPos -= 0x5000
71
else
72
// Change direction once again, start going backwards
73
74
Object.Timer = 0
75
Object.State = MECHABU_BACKTRACK
76
end if
77
78
// Track the ground, the Bu should always be grounded
79
ObjectTileGrip(CSIDE_FLOOR, 0, 15, 0)
80
break
81
82
end switch
83
84
// See if the Bu should become a Flower instead
85
CallFunction(StageSetup_CheckGoodFuture)
86
87
end sub
88
89
90
sub ObjectPlayerInteraction
91
// Huh, it doesn't seem like the Mecha Bu ever reaches state 3, so this check
92
// is effectivly useless
93
if Object.State < 3
94
95
// Check collision with the main Mecha Bu
96
#platform: Use_Standalone
97
PlayerObjectCollision(C_TOUCH, -16, -14, 16, 14)
98
#endplatform
99
#platform: Use_Origins
100
PlayerObjectCollision(C_ENEMY, -16, -14, 16, 14)
101
#endplatform
102
if CheckResult == true
103
CallFunction(Player_BadnikBreak)
104
end if
105
106
// Make sure the Bu hasn't become a Flower (destroyed) before checking for other parts
107
if Object.Type == TypeName[Mecha Bu]
108
109
// Bug Details:
110
// The PlayerObjectCollision boxes here for MechaBu are swapped for both positions of its horn.
111
// As to how this happened is unclear, most likely a programming oversight.
112
if Object.HornTimer > 59
113
PlayerObjectCollision(C_TOUCH, -30, -32, -8, 0) // Timer is over 59 frames, use "Lower" Hitbox
114
if CheckResult == true
115
CallFunction(Player_Hit)
116
end if
117
else
118
PlayerObjectCollision(C_TOUCH, -36, -16, -14, 16) // Timer is under 59 frames, use "Raised" Hitbox
119
if CheckResult == true
120
CallFunction(Player_Hit)
121
end if
122
end if
123
end if
124
end if
125
126
end sub
127
128
129
sub ObjectDraw
130
Object.SFXTimer++
131
if Object.SFXTimer == 48
132
Object.SFXTimer = 0
133
PlayStageSfx(SFX_S_BUZZSAW, false)
134
end if
135
136
TempValue0 = Object.AnimationTimer
137
TempValue0 /= 3
138
139
Object.AnimationTimer++
140
Object.AnimationTimer %= 6
141
142
if Object.Quality == GOOD_QUALITY
143
144
// Bug Details:
145
// MechaBu has it's saw rendering behind its body. Another programming oversight...?
146
if Object.HornTimer > 59
147
TempValue0 += 5
148
DrawSpriteFX(TempValue0, FX_FLIP, Object.XPos, Object.YPos) // Draw Raised Saw Sprite
149
DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos) // Draw Body Sprite
150
DrawSpriteFX(4, FX_FLIP, Object.XPos, Object.YPos) // Draw Raised Arm Sprite
151
else
152
TempValue0 += 2
153
DrawSpriteFX(TempValue0, FX_FLIP, Object.XPos, Object.YPos) // Draw Lower Saw Sprite
154
DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos) // Draw Body Sprite
155
DrawSpriteFX(1, FX_FLIP, Object.XPos, Object.YPos) // Draw Lower Arm Sprite
156
end if
157
158
// Start the HornTimer, reset every 120 frames
159
Object.HornTimer++
160
Object.HornTimer %= 120
161
else
162
TempValue0 += 5
163
DrawSpriteFX(TempValue0, FX_FLIP, Object.XPos, Object.YPos) // Draw Raised Saw Sprite
164
DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos) // Draw Body Sprite
165
DrawSpriteFX(4, FX_FLIP, Object.XPos, Object.YPos) // Draw Raised Arm Sprite
166
end if
167
168
end sub
169
170
171
sub ObjectStartup
172
173
LoadSpriteSheet("R8/Objects.gif")
174
175
SpriteFrame(-24, -16, 48, 32, 173, 140) // #0 - Mecha Bu body
176
177
SpriteFrame(-23, -17, 16, 24, 156, 177) // #1 - Mecha Bu Horn frame 0
178
SpriteFrame(-31, -32, 24, 32, 230, 1) // #2 - Mecha Bu Saw frame 0
179
SpriteFrame(-31, -32, 24, 32, 173, 173) // #3 - Mecha Bu Saw frame 1
180
181
SpriteFrame(-33, -8, 24, 16, 131, 177) // #4 - Mecha Bu Horn frame 1
182
SpriteFrame(-37, -16, 24, 32, 230, 1) // #5 - Mecha Bu Saw frame 0
183
SpriteFrame(-37, -16, 24, 32, 173, 173) // #6 - Mecha Bu Saw frame 1
184
185
// Cycle through all Objects in the level and find all Mecha Bu's
186
ArrayPos0 = 32
187
while ArrayPos0 < 1056
188
if Object[ArrayPos0].Type == TypeName[Mecha Bu]
189
190
// Store their its starting position
191
// (These don't ever seem to be used, though?)
192
193
Object[ArrayPos0].XOriginPos = Object[ArrayPos0].XPos
194
Object[ArrayPos0].YOriginPos = Object[ArrayPos0].YPos
195
196
end if
197
198
ArrayPos0++
199
loop
200
201
end sub
202
203
204
// ========================
205
// Editor Subs
206
// ========================
207
208
sub RSDKEdit
209
if Editor.ReturnVariable == true
210
switch Editor.VariableID
211
case EDIT_VAR_PROPVAL // Property Value
212
CheckResult = Object.PropertyValue
213
CheckResult &= 1
214
break
215
case 0 // condition
216
CheckResult = Object.PropertyValue
217
CheckResult &= 1
218
break
219
end switch
220
else
221
switch Editor.VariableID
222
case EDIT_VAR_PROPVAL // Property Value
223
Object.PropertyValue = Editor.VariableValue
224
Object.PropertyValue &= 1
225
break
226
case 0 // condition
227
Object.PropertyValue = Editor.VariableValue
228
Object.PropertyValue &= 1
229
break
230
end switch
231
end if
232
end sub
233
234
sub RSDKDraw
235
if Object.PropertyValue == GOOD_QUALITY
236
DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos) // Draw Body Sprite
237
DrawSpriteFX(2, FX_FLIP, Object.XPos, Object.YPos) // Draw Lower Saw Sprite
238
DrawSpriteFX(1, FX_FLIP, Object.XPos, Object.YPos) // Draw Lower Arm Sprite
239
else
240
DrawSpriteFX(0, FX_FLIP, Object.XPos, Object.YPos) // Draw Body Sprite
241
DrawSpriteFX(5, FX_FLIP, Object.XPos, Object.YPos) // Draw Raised Saw Sprite
242
DrawSpriteFX(4, FX_FLIP, Object.XPos, Object.YPos) // Draw Raised Arm Sprite
243
end if
244
end sub
245
246
247
sub RSDKLoad
248
249
LoadSpriteSheet("R8/Objects.gif")
250
251
SpriteFrame(-24, -16, 48, 32, 173, 140) // #0 - Mecha Bu body
252
253
SpriteFrame(-23, -17, 16, 24, 156, 177) // #1 - Mecha Bu Horn frame 0
254
SpriteFrame(-31, -32, 24, 32, 230, 1) // #2 - Mecha Bu Saw frame 0
255
SpriteFrame(-31, -32, 24, 32, 173, 173) // #3 - Mecha Bu Saw frame 1
256
257
SpriteFrame(-33, -8, 24, 16, 131, 177) // #4 - Mecha Bu Horn frame 1
258
SpriteFrame(-37, -16, 24, 32, 230, 1) // #5 - Mecha Bu Saw frame 0
259
SpriteFrame(-37, -16, 24, 32, 173, 173) // #6 - Mecha Bu Saw frame 1
260
261
AddEditorVariable("condition")
262
SetActiveVariable("condition")
263
AddEnumVariable("Good Quality", GOOD_QUALITY)
264
AddEnumVariable("Bad Quality", BAD_QUALITY)
265
end sub
266
267