Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/Enemies/BuzzBomber.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Buzz Bomber Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
private alias object.value0 : object.timer
13
private alias object.value1 : object.startPos.x
14
private alias object.value2 : object.hasShot
15
private alias object.value3 : object.hideOnOffScreen // Set from the editor
16
17
// Player Aliases
18
private alias object.value40 : player.hitboxLeft
19
private alias object.value38 : player.hitboxTop
20
private alias object.value41 : player.hitboxRight
21
private alias object.value39 : player.hitboxBottom
22
23
private alias 0 : BUZZBOMBER_BUZZAROUND
24
private alias 1 : BUZZBOMBER_IDLEDELAY
25
private alias 2 : BUZZBOMBER_FOUNDPLAYER
26
private alias 3 : BUZZBOMBER_SHOOTING
27
private alias 4 : BUZZBOMBER_HIDDEN
28
29
private alias 0 : BUZZBOMBER_ANI_FLY
30
private alias 1 : BUZZBOMBER_ANI_FLY_IDLE
31
private alias 2 : BUZZBOMBER_ANI_SHOOT
32
private alias 3 : BUZZBOMBER_ANI_NONE
33
34
35
// ========================
36
// Function Declarations
37
// ========================
38
39
reserve function BuzzBomber_DebugDraw
40
reserve function BuzzBomber_DebugSpawn
41
42
43
// ========================
44
// Function Definitions
45
// ========================
46
47
private function BuzzBomber_DebugDraw
48
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
49
DrawSpriteFX(2, FX_FLIP, object.xpos, object.ypos)
50
end function
51
52
53
private function BuzzBomber_DebugSpawn
54
CreateTempObject(TypeName[Buzz Bomber], 0, object.xpos, object.ypos)
55
GetBit(temp0, object.direction, 0)
56
if temp0 == FLIP_NONE
57
// Facing left
58
object[tempObjectPos].direction = FLIP_NONE
59
object[tempObjectPos].xvel = -0x40000
60
else
61
// Facing right
62
object[tempObjectPos].direction = FLIP_X
63
object[tempObjectPos].xvel = 0x40000
64
end if
65
66
end function
67
68
69
// ========================
70
// Events
71
// ========================
72
73
event ObjectUpdate
74
switch object.state
75
case BUZZBOMBER_BUZZAROUND
76
object.priority = PRIORITY_ACTIVE
77
if object.timer < 127
78
object.timer++
79
object.xpos += object.xvel
80
else
81
object.timer = 0
82
object.state = BUZZBOMBER_IDLEDELAY
83
object.animation = BUZZBOMBER_ANI_FLY_IDLE
84
object.direction ^= FLIP_X
85
FlipSign(object.xvel)
86
end if
87
break
88
89
case BUZZBOMBER_IDLEDELAY
90
if object.timer < 59
91
object.timer++
92
else
93
object.timer = 0
94
object.state = BUZZBOMBER_BUZZAROUND
95
object.animation = BUZZBOMBER_ANI_FLY
96
object.hasShot = false
97
end if
98
break
99
100
case BUZZBOMBER_FOUNDPLAYER
101
if object.timer < 29
102
object.timer++
103
else
104
object.timer = 0
105
object.state++
106
object.animation = BUZZBOMBER_ANI_SHOOT
107
end if
108
break
109
110
case BUZZBOMBER_SHOOTING
111
if object.timer < 59
112
object.timer++
113
if object.timer == 15
114
CreateTempObject(TypeName[Buzz Bomber Shot], 0, object.xpos, object.ypos)
115
object[tempObjectPos].direction = object.direction
116
if object.direction == FLIP_NONE
117
object[tempObjectPos].xpos -= 0x180000
118
object[tempObjectPos].xvel = -0x20000
119
else
120
object[tempObjectPos].xpos += 0x180000
121
object[tempObjectPos].xvel = 0x20000
122
end if
123
object[tempObjectPos].ypos += 0x1C0000
124
object[tempObjectPos].yvel = 0x20000
125
end if
126
else
127
object.timer = 0
128
object.state = BUZZBOMBER_BUZZAROUND
129
object.animation = BUZZBOMBER_ANI_FLY
130
object.hasShot = true
131
end if
132
break
133
134
case BUZZBOMBER_HIDDEN
135
object.animation = BUZZBOMBER_ANI_NONE
136
break
137
138
end switch
139
140
if object.outOfBounds == true
141
temp0 = object.xpos
142
object.xpos = object.startPos.x
143
if object.hideOnOffScreen == true
144
object.state = BUZZBOMBER_HIDDEN
145
end if
146
147
if object.outOfBounds == true
148
object.xpos = object.startPos.x
149
150
GetBit(temp0, object.propertyValue, 0)
151
if temp0 == false
152
object.direction = FLIP_NONE
153
object.xvel = -0x40000
154
else
155
object.direction = FLIP_X
156
object.xvel = 0x40000
157
end if
158
object.timer = 0
159
object.animation = BUZZBOMBER_ANI_FLY
160
object.priority = PRIORITY_BOUNDS
161
object.state = BUZZBOMBER_BUZZAROUND
162
else
163
object.xpos = temp0
164
end if
165
end if
166
167
// Player Collisons
168
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
169
if object.state == BUZZBOMBER_BUZZAROUND
170
if object.hasShot == false
171
if object.propertyValue < 2
172
BoxCollisionTest(C_TOUCH, object.entityPos, -96, -256, 96, 256, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
173
else
174
BoxCollisionTest(C_TOUCH, object.entityPos, -48, -256, 48, 256, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
175
end if
176
177
if checkResult == true
178
object.state = BUZZBOMBER_FOUNDPLAYER
179
object.timer = 0
180
object.animation = BUZZBOMBER_ANI_FLY_IDLE
181
end if
182
end if
183
end if
184
185
if object.state < BUZZBOMBER_HIDDEN
186
BoxCollisionTest(C_TOUCH, object.entityPos, -24, -12, 24, 12, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
187
if checkResult == true
188
CallFunction(Player_BadnikBreak)
189
end if
190
end if
191
next
192
193
object.frame = object.animationTimer
194
object.frame >>= 1
195
object.frame += 2
196
object.animationTimer++
197
object.animationTimer &= 3
198
end event
199
200
201
event ObjectDraw
202
if object.state < BUZZBOMBER_HIDDEN
203
if object.direction == FLIP_NONE
204
DrawSpriteFX(object.frame, FX_INK, object.xpos, object.ypos)
205
else
206
object.frame += 2
207
DrawSpriteFX(object.frame, FX_INK, object.xpos, object.ypos)
208
object.frame -= 2
209
end if
210
end if
211
212
switch object.animation
213
case BUZZBOMBER_ANI_FLY
214
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
215
object.frame += 4
216
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
217
object.frame -= 4
218
break
219
220
case BUZZBOMBER_ANI_FLY_IDLE
221
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
222
break
223
224
case BUZZBOMBER_ANI_SHOOT
225
DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
226
break
227
228
default
229
break
230
231
end switch
232
end event
233
234
235
event ObjectStartup
236
CheckCurrentStageFolder("Zone01")
237
if checkResult == true
238
LoadSpriteSheet("GHZ/Objects.gif")
239
SpriteFrame(-23, -9, 45, 19, 98, 74)
240
SpriteFrame(-23, -9, 36, 29, 149, 49)
241
SpriteFrame(-17, -15, 35, 8, 144, 79)
242
SpriteFrame(-18, -10, 37, 5, 144, 88)
243
SpriteFrame(-18, -15, 35, 8, 145, 220)
244
SpriteFrame(-19, -10, 37, 5, 143, 229)
245
SpriteFrame(13, 4, 6, 5, 98, 68)
246
SpriteFrame(13, 4, 10, 5, 104, 68)
247
end if
248
249
CheckCurrentStageFolder("Zone02")
250
if checkResult == true
251
LoadSpriteSheet("MZ/Objects.gif")
252
SpriteFrame(-23, -9, 45, 19, 1, 127)
253
SpriteFrame(-23, -9, 36, 29, 1, 147)
254
SpriteFrame(-17, -15, 35, 8, 38, 147)
255
SpriteFrame(-18, -10, 37, 5, 38, 156)
256
SpriteFrame(-18, -15, 35, 8, 38, 162)
257
SpriteFrame(-19, -10, 37, 5, 38, 171)
258
SpriteFrame(13, 4, 6, 5, 76, 153)
259
SpriteFrame(13, 4, 10, 5, 74, 147)
260
end if
261
262
CheckCurrentStageFolder("Zone03")
263
if checkResult == true
264
LoadSpriteSheet("SYZ/Objects.gif")
265
SpriteFrame(-23, -9, 45, 19, 1, 81)
266
SpriteFrame(-23, -9, 36, 29, 1, 101)
267
SpriteFrame(-17, -15, 35, 8, 38, 101)
268
SpriteFrame(-18, -10, 37, 5, 38, 110)
269
SpriteFrame(-18, -15, 35, 8, 38, 116)
270
SpriteFrame(-19, -10, 37, 5, 38, 125)
271
SpriteFrame(13, 4, 6, 5, 76, 123)
272
SpriteFrame(13, 4, 10, 5, 83, 123)
273
end if
274
275
CheckCurrentStageFolder("Zone07")
276
if checkResult == true
277
LoadSpriteSheet("MBZ/Objects.gif")
278
SpriteFrame(-23, -9, 45, 19, 1, 1)
279
SpriteFrame(-23, -9, 36, 29, 1, 21)
280
SpriteFrame(-17, -15, 35, 8, 38, 21)
281
SpriteFrame(-18, -10, 37, 5, 38, 30)
282
SpriteFrame(-18, -15, 35, 8, 38, 36)
283
SpriteFrame(-19, -10, 37, 5, 38, 45)
284
SpriteFrame(13, 4, 6, 5, 47, 15)
285
SpriteFrame(13, 4, 10, 5, 54, 15)
286
end if
287
288
// propertyValue info:
289
// bit 0 = direction
290
// bit 1 = range type (large/small)
291
292
foreach (TypeName[Buzz Bomber], arrayPos0, ALL_ENTITIES)
293
object[arrayPos0].startPos.x = object[arrayPos0].xpos
294
object[arrayPos0].inkEffect = 2
295
object[arrayPos0].alpha = 0xC0
296
GetBit(temp0, object[arrayPos0].propertyValue, 0)
297
if temp0 == 0
298
object[arrayPos0].direction = FLIP_NONE
299
object[arrayPos0].xvel = -0x40000
300
else
301
object[arrayPos0].direction = FLIP_X
302
object[arrayPos0].xvel = 0x40000
303
end if
304
next
305
306
SetTableValue(TypeName[Buzz Bomber], DebugMode_ObjCount, DebugMode_TypesTable)
307
SetTableValue(BuzzBomber_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
308
SetTableValue(BuzzBomber_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
309
DebugMode_ObjCount++
310
end event
311
312
313
// ========================
314
// Editor Events
315
// ========================
316
317
event RSDKEdit
318
if editor.returnVariable == true
319
switch editor.variableID
320
case EDIT_VAR_PROPVAL // property value
321
checkResult = object.propertyValue
322
break
323
324
case 0 // direction
325
GetBit(checkResult, object.propertyValue, 0)
326
break
327
328
case 1 // rangeSize
329
GetBit(checkResult, object.propertyValue, 1)
330
break
331
332
case 2 // hideOnOffScreen
333
CheckEqual(object.hideOnOffScreen, true)
334
break
335
336
end switch
337
else
338
switch editor.variableID
339
case EDIT_VAR_PROPVAL // property value
340
object.propertyValue = editor.variableValue
341
break
342
343
case 0 // direction
344
CheckNotEqual(editor.variableValue, false)
345
SetBit(object.propertyValue, 0, checkResult)
346
break
347
348
case 1 // rangeSize
349
CheckNotEqual(editor.variableValue, false)
350
SetBit(object.propertyValue, 1, checkResult)
351
break
352
353
case 2 // hideOnOffScreen
354
object.hideOnOffScreen = editor.variableValue
355
break
356
357
end switch
358
end if
359
end event
360
361
362
event RSDKDraw
363
GetBit(object.direction, object.propertyValue, 0)
364
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
365
DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
366
end event
367
368
369
event RSDKLoad
370
// Make sure we have a fall-back, in case the current folder isn't actually a valid one
371
temp0 = false
372
373
CheckCurrentStageFolder("Zone02")
374
temp0 |= checkResult
375
if checkResult == true
376
LoadSpriteSheet("MZ/Objects.gif")
377
SpriteFrame(-23, -9, 45, 19, 1, 127)
378
SpriteFrame(-17, -15, 35, 8, 38, 147)
379
end if
380
381
CheckCurrentStageFolder("Zone03")
382
temp0 |= checkResult
383
if checkResult == true
384
LoadSpriteSheet("SYZ/Objects.gif")
385
SpriteFrame(-23, -9, 45, 19, 1, 81)
386
SpriteFrame(-17, -15, 35, 8, 38, 101)
387
end if
388
389
CheckCurrentStageFolder("Zone07")
390
temp0 |= checkResult
391
if checkResult == true
392
LoadSpriteSheet("MBZ/Objects.gif")
393
SpriteFrame(-23, -9, 45, 19, 1, 1)
394
SpriteFrame(-17, -15, 35, 8, 38, 21)
395
end if
396
397
if temp0 == false
398
// We use GHZ's sprites as the fallback, "Zone01" (GHZ's folder) will come here too
399
LoadSpriteSheet("GHZ/Objects.gif")
400
SpriteFrame(-23, -9, 45, 19, 98, 74)
401
SpriteFrame(-17, -15, 35, 8, 144, 79)
402
end if
403
404
AddEditorVariable("direction")
405
SetActiveVariable("direction")
406
AddEnumVariable("Left", 0)
407
AddEnumVariable("Right", 1)
408
409
AddEditorVariable("rangeSize")
410
SetActiveVariable("rangeSize")
411
AddEnumVariable("Large", 0)
412
AddEnumVariable("Small", 1)
413
414
AddEditorVariable("hideOnOffScreen")
415
SetActiveVariable("hideOnOffScreen")
416
AddEnumVariable("False", false)
417
AddEnumVariable("True", true)
418
end event
419
420