Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 2/Scripts/Enemies/Buzzer.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Buzzer 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.shootTimer
16
17
// States
18
private alias 0 : BUZZER_FLYING
19
private alias 1 : BUZZER_STOPPED
20
private alias 2 : BUZZER_SHOOTING
21
private alias 3 : BUZZER_INVISIBLE
22
23
// Animations
24
private alias 0 : BUZZER_ANI_FLYING
25
private alias 1 : BUZZER_ANI_STOPPED
26
private alias 2 : BUZZER_ANI_SHOOTING
27
private alias 3 : BUZZER_ANI_INVISBLE
28
29
// Player Aliases
30
private alias object.value40 : player.hitboxLeft
31
private alias object.value38 : player.hitboxTop
32
private alias object.value41 : player.hitboxRight
33
private alias object.value39 : player.hitboxBottom
34
35
36
// ========================
37
// Function Declarations
38
// ========================
39
40
reserve function Buzzer_DebugDraw
41
reserve function Buzzer_DebugSpawn
42
43
44
// ========================
45
// Function Definitions
46
// ========================
47
48
private function Buzzer_DebugDraw
49
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
50
end function
51
52
53
private function Buzzer_DebugSpawn
54
CreateTempObject(TypeName[Buzzer], 0, object.xpos, object.ypos)
55
GetBit(temp0, object.direction, 0)
56
if temp0 == FACING_RIGHT
57
object[tempObjectPos].direction = FLIP_NONE
58
object[tempObjectPos].xvel = -0x10000
59
else
60
object[tempObjectPos].direction = FLIP_X
61
object[tempObjectPos].xvel = 0x10000
62
end if
63
end function
64
65
66
// ========================
67
// Events
68
// ========================
69
70
event ObjectUpdate
71
switch object.state
72
case BUZZER_FLYING
73
object.priority = PRIORITY_ACTIVE
74
if object.timer < 256
75
object.timer++
76
object.xpos += object.xvel
77
else
78
object.timer = 0
79
object.state = BUZZER_STOPPED
80
object.animation = BUZZER_ANI_STOPPED
81
object.direction ^= FLIP_X
82
FlipSign(object.xvel)
83
end if
84
break
85
86
case BUZZER_STOPPED
87
if object.shootTimer < 30
88
object.shootTimer++
89
else
90
object.shootTimer = 0
91
object.state = BUZZER_FLYING
92
object.animation = BUZZER_ANI_FLYING
93
object.hasShot = false
94
end if
95
break
96
97
case BUZZER_SHOOTING
98
if object.shootTimer < 50
99
object.shootTimer++
100
if object.shootTimer == 30
101
CreateTempObject(TypeName[Buzzer Shot], 0, object.xpos, object.ypos)
102
object[tempObjectPos].direction = object.direction
103
if object.direction == FLIP_NONE
104
object[tempObjectPos].xpos += 0xD0000
105
object[tempObjectPos].xvel = -0x18000
106
else
107
object[tempObjectPos].xpos -= 0xD0000
108
object[tempObjectPos].xvel = 0x18000
109
end if
110
object[tempObjectPos].ypos += 0x180000
111
object[tempObjectPos].yvel = 0x18000
112
end if
113
else
114
object.shootTimer = 0
115
object.state = BUZZER_FLYING
116
object.animation = BUZZER_ANI_FLYING
117
object.hasShot = true
118
end if
119
break
120
121
case BUZZER_INVISIBLE
122
object.animation = BUZZER_ANI_INVISBLE
123
break
124
125
end switch
126
127
if object.outOfBounds == true
128
temp0 = object.xpos
129
object.xpos = object.startPos.x
130
if object.shootTimer == 1
131
object.state = BUZZER_INVISIBLE
132
end if
133
134
if object.outOfBounds == true
135
object.xpos = object.startPos.x
136
GetBit(temp0, object.propertyValue, 0)
137
if temp0 == 0
138
object.direction = FLIP_NONE
139
object.xvel = -0x10000
140
else
141
object.direction = FLIP_X
142
object.xvel = 0x10000
143
end if
144
145
#platform: USE_ORIGINS
146
if game.playMode == BOOT_PLAYMODE_MISSION
147
GetBit(temp0, object.propertyValue, 1)
148
if temp0 != false
149
object.xvel = 0
150
end if
151
end if
152
#endplatform
153
154
object.timer = 0
155
object.animation = BUZZER_ANI_FLYING
156
object.priority = PRIORITY_BOUNDS
157
object.state = BUZZER_FLYING
158
else
159
object.xpos = temp0
160
end if
161
end if
162
163
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
164
if object.state == BUZZER_FLYING
165
if object.hasShot == false
166
if object.direction == FLIP_NONE
167
BoxCollisionTest(C_TOUCH, object.entityPos, -28, -256, -30, 256, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
168
else
169
BoxCollisionTest(C_TOUCH, object.entityPos, 28, -256, 30, 256, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
170
end if
171
172
if checkResult == true
173
object.state = BUZZER_SHOOTING
174
object.animation = BUZZER_ANI_SHOOTING
175
end if
176
end if
177
end if
178
179
if object.state < BUZZER_INVISIBLE
180
BoxCollisionTest(C_TOUCH, object.entityPos, -16, -12, 16, 12, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
181
if checkResult == true
182
CallFunction(Player_BadnikBreak)
183
end if
184
end if
185
next
186
187
object.frame = object.animationTimer
188
object.frame /= 3
189
object.frame += 3
190
object.animationTimer++
191
if object.animationTimer >= 6
192
object.animationTimer = 0
193
end if
194
end event
195
196
197
event ObjectDraw
198
switch object.animation
199
case BUZZER_ANI_FLYING
200
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
201
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
202
break
203
204
case BUZZER_ANI_STOPPED
205
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
206
break
207
208
case BUZZER_ANI_SHOOTING
209
DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
210
break
211
212
case BUZZER_ANI_INVISBLE
213
break
214
215
end switch
216
end event
217
218
219
event ObjectStartup
220
CheckCurrentStageFolder("Zone01")
221
if checkResult == true
222
LoadSpriteSheet("EHZ/Objects.gif")
223
SpriteFrame(-24, -8, 48, 16, 1, 1)
224
SpriteFrame(-24, -8, 42, 31, 1, 18)
225
SpriteFrame(1, 6, 17, 17, 50, 1)
226
SpriteFrame(5, -8, 6, 5, 19, 50)
227
SpriteFrame(5, -8, 7, 5, 19, 56)
228
else
229
LoadSpriteSheet("MBZ/Objects.gif")
230
SpriteFrame(-24, -8, 48, 16, 1, 256)
231
SpriteFrame(-24, -8, 42, 31, 1, 273)
232
SpriteFrame(1, 6, 17, 17, 268, 501)
233
SpriteFrame(5, -8, 6, 5, 137, 331)
234
SpriteFrame(5, -8, 7, 5, 137, 337)
235
end if
236
237
foreach (TypeName[Buzzer], arrayPos0, ALL_ENTITIES)
238
object[arrayPos0].startPos.x = object[arrayPos0].xpos
239
240
GetBit(temp0, object[arrayPos0].propertyValue, 0)
241
if temp0 == 0
242
object[arrayPos0].direction = FLIP_NONE
243
object[arrayPos0].xvel = -0x10000
244
else
245
object[arrayPos0].direction = FLIP_X
246
object[arrayPos0].xvel = 0x10000
247
end if
248
249
#platform: USE_ORIGINS
250
if game.playMode == BOOT_PLAYMODE_MISSION
251
GetBit(temp0, object.propertyValue, 1)
252
if temp0 != false
253
object.xvel = 0
254
end if
255
end if
256
#endplatform
257
next
258
259
SetTableValue(TypeName[Buzzer], DebugMode_ObjCount, DebugMode_TypesTable)
260
SetTableValue(Buzzer_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
261
SetTableValue(Buzzer_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
262
DebugMode_ObjCount++
263
end event
264
265
266
// ========================
267
// Editor Events
268
// ========================
269
270
event RSDKEdit
271
if editor.returnVariable == true
272
switch editor.variableID
273
case EDIT_VAR_PROPVAL // property value
274
checkResult = object.propertyValue
275
break
276
277
case 0 // direction
278
GetBit(checkResult, object.propertyValue, 0)
279
break
280
281
case 1 // static
282
GetBit(checkResult, object.propertyValue, 1)
283
break
284
285
end switch
286
else
287
switch editor.variableID
288
case EDIT_VAR_PROPVAL // property value
289
object.propertyValue = editor.variableValue
290
break
291
292
case 0 // direction
293
CheckNotEqual(editor.variableValue, 0)
294
SetBit(object.propertyValue, 0, checkResult)
295
break
296
297
case 1 // static
298
CheckNotEqual(editor.variableValue, 0)
299
SetBit(object.propertyValue, 1, checkResult)
300
break
301
302
end switch
303
end if
304
end event
305
306
307
event RSDKDraw
308
GetBit(object.direction, object.propertyValue, 0)
309
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
310
DrawSpriteFX(1, FX_FLIP, object.xpos, object.ypos)
311
end event
312
313
314
event RSDKLoad
315
CheckCurrentStageFolder("Zone01")
316
if checkResult == true
317
LoadSpriteSheet("EHZ/Objects.gif")
318
SpriteFrame(-24, -8, 48, 16, 1, 1)
319
SpriteFrame(5, -8, 6, 5, 19, 50)
320
else
321
LoadSpriteSheet("MBZ/Objects.gif")
322
SpriteFrame(-24, -8, 48, 16, 1, 256)
323
SpriteFrame(5, -8, 6, 5, 137, 331)
324
end if
325
326
AddEditorVariable("direction")
327
SetActiveVariable("direction")
328
AddEnumVariable("Left", 0)
329
AddEnumVariable("Right", 1)
330
331
// Only functional in Origins' Mission Mode
332
// Not much of a good way to show that in the editor, though...
333
AddEditorVariable("static")
334
SetActiveVariable("static")
335
AddEnumVariable("False", 0)
336
AddEnumVariable("True", 1)
337
end event
338
339