Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-CD-2011-Script-Decompilation
Path: blob/main/Scripts/R7/Kabasira.txt
1319 views
1
//------------------Sonic CD Kabasira 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.Angle
8
#alias Object.Value2 : Object.StartPosX
9
#alias Object.Value3 : Object.StartPosY
10
#alias Object.Value4 : Object.DrawPosX
11
#alias Object.Value5 : Object.DrawPosY
12
13
#alias Object.PropertyValue : Object.Quality
14
15
// Kabasira Shot Aliases
16
#alias Object.Value1 : Object.XVelocity
17
#alias Object.Value2 : Object.YVelocity
18
19
// States 0-1 are never used, aside from state 0 being the default state
20
#alias 2 : KABASIRA_INACTIVE
21
22
// Ink Effect
23
#alias 2 : INK_ALPHA
24
25
// Stage SFX
26
#alias 2 : SFX_S_SHOT
27
28
// Badnik Quality / Property Values
29
#alias 0 : GOOD_QUALITY
30
#alias 1 : BAD_QUALITY
31
32
33
sub ObjectMain
34
if Object.OutOfBounds == true
35
// The object is out of bounds, reset it
36
Object.State = KABASIRA_INACTIVE
37
Object.Timer = 0
38
39
// Neutral angle, right between 512 and 000
40
Object.Angle = 256
41
42
// The object never seems to refrence its direction, nor does it use FX_FLIP, so I believe this is effectively unused?
43
Object.Direction = FACING_RIGHT
44
45
// Move it back to its starting position
46
// (Although, normally there's a check to make sure the starting position is OOB too to prevent visible teleporting, why isn't there a check like that this time?)
47
Object.XPos = Object.StartPosX
48
Object.YPos = Object.StartPosY
49
end if
50
51
if Object.Quality == GOOD_QUALITY
52
// Good variant of the object, able to attack
53
54
Object.Angle += 2
55
Object.Angle &= 511
56
Object.Frame = Object.AnimationTimer
57
Object.Frame >>= 3
58
Object.AnimationTimer++
59
Object.AnimationTimer &= 15
60
61
if Object.Timer == 0
62
Object.Timer = 240
63
64
// Shoot a shot at the player
65
66
PlayStageSfx(SFX_S_SHOT, false)
67
68
// Different shot subtypes based on the player's position relative to the Kabasira
69
if Player.XPos > Object.XPos
70
CreateTempObject(TypeName[Kabasira Shot], 0, Object.XPos, Object.YPos)
71
else
72
CreateTempObject(TypeName[Kabasira Shot], 1, Object.XPos, Object.YPos)
73
end if
74
75
Object[TempObjectPos].InkEffect = INK_ALPHA
76
Object[TempObjectPos].Alpha = 192
77
78
// Find the velocities to send the shot at
79
80
TempValue0 = Player.XPos
81
TempValue0 -= Object.XPos
82
TempValue1 = Player.YPos
83
TempValue1 -= Object.YPos
84
85
ATan2(TempValue2, TempValue0, TempValue1)
86
87
Cos256(Object[TempObjectPos].XVelocity, TempValue2)
88
Sin256(Object[TempObjectPos].YVelocity, TempValue2)
89
Object[TempObjectPos].XVelocity <<= 9
90
Object[TempObjectPos].YVelocity <<= 9
91
else
92
Object.Timer--
93
end if
94
else
95
// Peaceful variant of the object, no attacking the player needed so just float around
96
Object.Angle++
97
Object.Angle &= 511
98
99
Object.Frame = Object.AnimationTimer
100
Object.Frame >>= 4
101
Object.AnimationTimer++
102
Object.AnimationTimer &= 31
103
end if
104
105
Cos(Object.YPos, Object.Angle)
106
Object.YPos <<= 13
107
Object.YPos += Object.StartPosY
108
109
TempValue0 = Object.Angle
110
TempValue0 <<= 1
111
112
Sin(Object.XPos, TempValue0)
113
Object.XPos *= 0xA00
114
Object.XPos += Object.StartPosX
115
116
CallFunction(StageSetup_CheckGoodFuture)
117
118
end sub
119
120
121
sub ObjectPlayerInteraction
122
// Check if the player's touched the head
123
#platform: Use_Standalone
124
PlayerObjectCollision(C_TOUCH, -6, -6, 6, 6)
125
#endplatform
126
#platform: Use_Origins
127
PlayerObjectCollision(C_ENEMY, -6, -6, 6, 6)
128
#endplatform
129
130
if CheckResult == true
131
CallFunction(Player_BadnikBreak)
132
end if
133
134
// (No collision checks for the rest of the body)
135
136
end sub
137
138
139
sub ObjectDraw
140
if Object.State < KABASIRA_INACTIVE
141
142
// First, draw each body part
143
TempValue0 = 0
144
TempValue1 = 488
145
TempValue3 = Object.Angle
146
TempValue3 += 464
147
TempValue3 &= 511
148
Object.Alpha = 64
149
150
while TempValue0 < 4
151
TempValue2 = Object.Angle
152
TempValue2 += TempValue1
153
TempValue2 &= 511
154
TempValue2 /= 42
155
TempValue2 %= 12
156
157
Cos(Object.DrawPosY, TempValue3)
158
Object.DrawPosY <<= 13
159
Object.DrawPosY += Object.StartPosY
160
161
TempValue4 = TempValue3
162
TempValue4 <<= 1
163
164
Sin(Object.DrawPosX, TempValue4)
165
Object.DrawPosX *= 0xA00
166
Object.DrawPosX += Object.StartPosX
167
168
switch TempValue2
169
case 0
170
case 6
171
DrawSpriteFX(TempValue2, FX_INK, Object.DrawPosX, Object.DrawPosY)
172
DrawSpriteFX(0, FX_INK, Object.DrawPosX, Object.DrawPosY)
173
TempValue2 = 6
174
TempValue2 += Object.Frame
175
break
176
177
case 1
178
case 7
179
DrawSpriteFX(TempValue2, FX_INK, Object.DrawPosX, Object.DrawPosY)
180
DrawSpriteFX(1, FX_INK, Object.DrawPosX, Object.DrawPosY)
181
TempValue2 = 8
182
TempValue2 += Object.Frame
183
break
184
185
case 2
186
case 8
187
DrawSpriteFX(TempValue2, FX_INK, Object.DrawPosX, Object.DrawPosY)
188
DrawSpriteFX(2, FX_INK, Object.DrawPosX, Object.DrawPosY)
189
TempValue2 = 10
190
TempValue2 += Object.Frame
191
break
192
193
case 3
194
case 9
195
DrawSpriteFX(3, FX_INK, Object.DrawPosX, Object.DrawPosY)
196
TempValue2 = 12
197
TempValue2 += Object.Frame
198
DrawSpriteFX(TempValue2, FX_INK, Object.DrawPosX, Object.DrawPosY)
199
break
200
201
case 4
202
case 10
203
TempValue2 = 14
204
TempValue2 += Object.Frame
205
DrawSpriteFX(TempValue2, FX_INK, Object.DrawPosX, Object.DrawPosY)
206
DrawSpriteFX(4, FX_INK, Object.DrawPosX, Object.DrawPosY)
207
break
208
209
case 5
210
case 11
211
TempValue2 = 16
212
TempValue2 += Object.Frame
213
DrawSpriteFX(TempValue2, FX_INK, Object.DrawPosX, Object.DrawPosY)
214
DrawSpriteFX(5, FX_INK, Object.DrawPosX, Object.DrawPosY)
215
break
216
217
end switch
218
219
TempValue0++
220
TempValue1 += 8
221
TempValue3 += 12
222
TempValue3 &= 511
223
Object.Alpha += 32
224
loop
225
226
// Draw the head & wings
227
// Different sprites & priority for the Kabasira's different directions
228
229
TempValue0 = Object.Angle
230
TempValue0 += 8
231
TempValue0 &= 511
232
TempValue0 /= 42
233
TempValue0 %= 12
234
switch TempValue0
235
case 0
236
case 6
237
DrawSpriteXY(0, Object.DrawPosX, Object.DrawPosY)
238
TempValue2 = 6
239
TempValue2 += Object.Frame
240
DrawSpriteXY(TempValue2, Object.DrawPosX, Object.DrawPosY)
241
break
242
243
case 1
244
case 7
245
DrawSpriteXY(1, Object.DrawPosX, Object.DrawPosY)
246
TempValue2 = 8
247
TempValue2 += Object.Frame
248
DrawSpriteXY(TempValue2, Object.DrawPosX, Object.DrawPosY)
249
break
250
251
case 2
252
case 8
253
DrawSpriteXY(2, Object.DrawPosX, Object.DrawPosY)
254
TempValue2 = 10
255
TempValue2 += Object.Frame
256
DrawSpriteXY(TempValue2, Object.DrawPosX, Object.DrawPosY)
257
break
258
259
case 3
260
case 9
261
DrawSpriteXY(3, Object.DrawPosX, Object.DrawPosY)
262
TempValue2 = 12
263
TempValue2 += Object.Frame
264
DrawSpriteXY(TempValue2, Object.DrawPosX, Object.DrawPosY)
265
break
266
267
case 4
268
case 10
269
TempValue2 = 14
270
TempValue2 += Object.Frame
271
DrawSpriteXY(TempValue2, Object.DrawPosX, Object.DrawPosY)
272
DrawSpriteXY(4, Object.DrawPosX, Object.DrawPosY)
273
break
274
275
case 5
276
case 11
277
TempValue2 = 16
278
TempValue2 += Object.Frame
279
DrawSpriteXY(TempValue2, Object.DrawPosX, Object.DrawPosY)
280
DrawSpriteXY(5, Object.DrawPosX, Object.DrawPosY)
281
break
282
283
end switch
284
285
end if
286
287
end sub
288
289
290
sub ObjectStartup
291
292
LoadSpriteSheet("R7/Objects.gif")
293
294
// Kabasira Body Frames
295
SpriteFrame(-8, -8, 16, 16, 133, 100)
296
SpriteFrame(-8, -8, 16, 16, 150, 100)
297
SpriteFrame(-8, -8, 16, 16, 167, 100)
298
SpriteFrame(-8, -8, 16, 16, 184, 100)
299
SpriteFrame(-8, -8, 16, 16, 99, 100)
300
SpriteFrame(-8, -8, 16, 16, 116, 100)
301
302
// Kabasira Wing Frames
303
SpriteFrame(-8, -6, 8, 8, 243, 101)
304
SpriteFrame(-8, -6, 8, 8, 243, 110)
305
SpriteFrame(-12, -6, 24, 8, 218, 101)
306
SpriteFrame(-12, -6, 24, 8, 218, 110)
307
SpriteFrame(-8, -6, 16, 8, 218, 92)
308
SpriteFrame(-8, -6, 16, 8, 235, 92)
309
SpriteFrame(0, -6, 8, 8, 240, 74)
310
SpriteFrame(0, -6, 8, 8, 240, 83)
311
SpriteFrame(-8, -6, 16, 8, 218, 92)
312
SpriteFrame(-8, -6, 16, 8, 235, 92)
313
SpriteFrame(-12, -6, 24, 8, 218, 101)
314
SpriteFrame(-12, -6, 24, 8, 218, 110)
315
316
// Setup all Kabasira objects in the level
317
ArrayPos0 = 32
318
while ArrayPos0 < 1056
319
if Object[ArrayPos0].Type == TypeName[Kabasira]
320
321
// Store the starting Positions since the Kabasira moves around
322
Object[ArrayPos0].StartPosX = Object[ArrayPos0].XPos
323
Object[ArrayPos0].StartPosY = Object[ArrayPos0].YPos
324
325
// Kabasira's tail has a fade effect, so give it the INK_ALPHA effect
326
Object[ArrayPos0].InkEffect = INK_ALPHA
327
328
// Give it 2 seconds of starting idle time before it starts to shoot
329
Object[ArrayPos0].Timer = 120
330
331
end if
332
333
ArrayPos0++
334
loop
335
336
end sub
337
338
339
// ========================
340
// Editor Subs
341
// ========================
342
343
sub RSDKEdit
344
if Editor.ReturnVariable == true
345
switch Editor.VariableID
346
case EDIT_VAR_PROPVAL // Property Value
347
CheckResult = Object.PropertyValue
348
break
349
case 0 // Condition
350
CheckResult = Object.PropertyValue
351
break
352
end switch
353
else
354
switch Editor.VariableID
355
case EDIT_VAR_PROPVAL // Property Value
356
Object.PropertyValue = Editor.VariableValue
357
break
358
case 0 // Condition
359
Object.PropertyValue = Editor.VariableValue
360
break
361
end switch
362
end if
363
end sub
364
365
366
sub RSDKDraw
367
DrawSprite(1)
368
DrawSprite(0)
369
end sub
370
371
372
sub RSDKLoad
373
LoadSpriteSheet("R7/Objects.gif")
374
SpriteFrame(-8, -8, 16, 16, 116, 100)
375
SpriteFrame(-8, -6, 8, 8, 243, 101)
376
377
AddEditorVariable("Condition")
378
SetActiveVariable("Condition")
379
AddEnumVariable("Good", GOOD_QUALITY)
380
AddEnumVariable("Bad", BAD_QUALITY)
381
end sub
382
383