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/Bomb.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Bomb 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.startPos.y
15
private alias object.value3 : object.fusePos
16
17
private alias 0 : BOMB_WALK
18
private alias 1 : BOMB_IDLE
19
private alias 2 : BOMB_EXPLODE
20
21
private alias 0 : BOMB_ANI_WALK
22
private alias 1 : BOMB_ANI_IDLE
23
private alias 2 : BOMB_ANI_EXPLODING
24
25
26
// ========================
27
// Function Declarations
28
// ========================
29
30
reserve function Bomb_DebugDraw
31
reserve function Bomb_DebugSpawn
32
33
34
// ========================
35
// Function Definitions
36
// ========================
37
38
private function Bomb_DebugDraw
39
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
40
DrawSpriteFX(8, FX_FLIP, object.xpos, object.ypos)
41
end function
42
43
44
private function Bomb_DebugSpawn
45
CreateTempObject(TypeName[Bomb], 0, object.xpos, object.ypos)
46
object[tempObjectPos].startPos.x = object[tempObjectPos].xpos
47
object[tempObjectPos].startPos.y = object[tempObjectPos].ypos
48
object[tempObjectPos].xvel = -0x1000
49
50
temp0 = object.direction
51
object[tempObjectPos].direction = temp0
52
temp0 &= FLIP_X
53
if temp0 == FLIP_X
54
FlipSign(object[tempObjectPos].xvel)
55
end if
56
57
object[tempObjectPos].timer = 0x600
58
object[tempObjectPos].animation = BOMB_ANI_WALK
59
object[tempObjectPos].frame = 0
60
end function
61
62
63
// ========================
64
// Events
65
// ========================
66
67
event ObjectUpdate
68
switch object.state
69
case BOMB_WALK
70
object.priority = PRIORITY_ACTIVE
71
object.timer--
72
if object.timer == 0
73
object.timer = 180
74
object.animation = BOMB_ANI_IDLE
75
object.animationTimer = 0
76
object.frame = 4
77
object.state = BOMB_IDLE
78
else
79
object.xpos += object.xvel
80
end if
81
break
82
83
case BOMB_IDLE
84
object.timer--
85
if object.timer == 0
86
object.timer = 0x600
87
object.animation = BOMB_ANI_WALK
88
object.animationTimer = 0
89
object.frame = 0
90
FlipSign(object.xvel)
91
object.direction ^= FLIP_X
92
object.state = BOMB_WALK
93
end if
94
break
95
96
case BOMB_EXPLODE
97
object.fusePos += 0x1000
98
object.timer--
99
if object.timer == 0
100
ResetObjectEntity(object.entityPos, TypeName[Blank Object], 0, object.xpos, object.ypos)
101
CreateTempObject(TypeName[Explosion], 0, object.xpos, object.ypos)
102
103
CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)
104
object[tempObjectPos].xvel = -0x20000
105
object[tempObjectPos].yvel = -0x30000
106
107
CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)
108
object[tempObjectPos].xvel = -0x10000
109
object[tempObjectPos].yvel = -0x20000
110
111
CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)
112
object[tempObjectPos].xvel = 0x20000
113
object[tempObjectPos].yvel = -0x30000
114
115
CreateTempObject(TypeName[Bomb Shrapnel], 0, object.xpos, object.ypos)
116
object[tempObjectPos].xvel = 0x10000
117
object[tempObjectPos].yvel = -0x20000
118
119
PlaySfx(SfxName[Explosion], false)
120
end if
121
break
122
123
end switch
124
125
if object.outOfBounds == true
126
temp0 = object.xpos
127
temp1 = object.ypos
128
object.xpos = object.startPos.x
129
object.ypos = object.startPos.y
130
if object.outOfBounds == true
131
object.xvel = -0x1000
132
temp0 = object.propertyValue
133
object.direction = temp0
134
temp0 &= FLIP_X
135
if temp0 == FLIP_X
136
FlipSign(object.xvel)
137
end if
138
object.timer = 0x600
139
object.animation = BOMB_ANI_WALK
140
object.frame = 0
141
object.priority = PRIORITY_BOUNDS
142
object.state = BOMB_WALK
143
else
144
object.xpos = temp0
145
object.ypos = temp1
146
end if
147
end if
148
149
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
150
if object.state != BOMB_EXPLODE
151
BoxCollisionTest(C_TOUCH, object.entityPos, -96, -96, 96, 96, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
152
if checkResult == true
153
object.animation = BOMB_ANI_EXPLODING
154
object.frame = 6
155
object.timer = 144
156
object.fusePos = 0
157
object.state = BOMB_EXPLODE
158
end if
159
end if
160
161
BoxCollisionTest(C_TOUCH, object.entityPos, -12, -18, 12, 18, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
162
if checkResult == true
163
CallFunction(Player_Hit)
164
end if
165
next
166
167
switch object.animation
168
case BOMB_ANI_WALK
169
if object.animationTimer == 20
170
object.animationTimer = 0
171
object.frame++
172
object.frame &= 3
173
end if
174
object.animationTimer++
175
break
176
177
case BOMB_ANI_IDLE
178
case BOMB_ANI_EXPLODING
179
if object.animationTimer == 20
180
object.animationTimer = 0
181
object.frame ^= 1
182
end if
183
object.animationTimer++
184
break
185
186
end switch
187
end event
188
189
190
event ObjectDraw
191
if object.state == BOMB_EXPLODE
192
temp0 = object.timer
193
temp0 >>= 2
194
temp0 &= 1
195
temp0 += 8
196
temp1 = object.ypos
197
198
// Get the Y-Flip bit
199
GetBit(temp2, object.direction, 1)
200
if temp2 == FLIP_NONE
201
// FLIP_NONE or FLIP_X (aka upright)
202
temp1 += object.fusePos
203
else
204
// FLIP_Y or FLIP_XY (aka on a roof)
205
temp1 -= object.fusePos
206
end if
207
208
DrawSpriteFX(temp0, FX_FLIP, object.xpos, temp1)
209
end if
210
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
211
end event
212
213
214
event ObjectStartup
215
// Load sprites depending on current scene folder
216
217
CheckCurrentStageFolder("Zone05")
218
if checkResult == true
219
LoadSpriteSheet("SLZ/Objects.gif")
220
SpriteFrame(-10, -21, 20, 37, 53, 131)
221
SpriteFrame(-10, -22, 20, 38, 28, 131)
222
SpriteFrame(-10, -21, 20, 37, 3, 131)
223
SpriteFrame(-10, -22, 20, 38, 53, 92)
224
SpriteFrame(-11, -21, 23, 37, 2, 92)
225
SpriteFrame(-11, -21, 23, 37, 27, 92)
226
SpriteFrame(-11, -9, 23, 25, 2, 170)
227
SpriteFrame(-11, -9, 23, 25, 27, 170)
228
SpriteFrame(-3, -23, 6, 14, 51, 170)
229
SpriteFrame(-4, -25, 8, 16, 58, 170)
230
end if
231
232
CheckCurrentStageFolder("Zone06")
233
if checkResult == true
234
LoadSpriteSheet("SBZ/Objects.gif")
235
SpriteFrame(-10, -21, 20, 37, 52, 40)
236
SpriteFrame(-10, -22, 20, 38, 27, 40)
237
SpriteFrame(-10, -21, 20, 37, 2, 40)
238
SpriteFrame(-10, -22, 20, 38, 52, 1)
239
SpriteFrame(-11, -21, 23, 37, 1, 1)
240
SpriteFrame(-11, -21, 23, 37, 26, 1)
241
SpriteFrame(-11, -9, 23, 25, 1, 79)
242
SpriteFrame(-11, -9, 23, 25, 26, 79)
243
SpriteFrame(-3, -23, 6, 14, 50, 79)
244
SpriteFrame(-4, -25, 8, 16, 57, 79)
245
end if
246
247
// Unused stuff from the "MBZ" Zone
248
CheckCurrentStageFolder("Zone07")
249
if checkResult == true
250
LoadSpriteSheet("MBZ/Objects.gif")
251
SpriteFrame(-10, -21, 20, 37, 53, 328)
252
SpriteFrame(-10, -22, 20, 38, 28, 328)
253
SpriteFrame(-10, -21, 20, 37, 3, 328)
254
SpriteFrame(-10, -22, 20, 38, 53, 289)
255
SpriteFrame(-11, -21, 23, 37, 2, 289)
256
SpriteFrame(-11, -21, 23, 37, 27, 289)
257
SpriteFrame(-11, -9, 23, 25, 2, 367)
258
SpriteFrame(-11, -9, 23, 25, 27, 367)
259
SpriteFrame(-3, -23, 6, 14, 51, 367)
260
SpriteFrame(-4, -25, 8, 16, 58, 367)
261
end if
262
263
foreach (TypeName[Bomb], arrayPos0, ALL_ENTITIES)
264
object[arrayPos0].startPos.x = object[arrayPos0].xpos
265
object[arrayPos0].startPos.y = object[arrayPos0].ypos
266
object[arrayPos0].xvel = -0x1000
267
temp0 = object[arrayPos0].propertyValue
268
object[arrayPos0].direction = temp0
269
temp0 &= FLIP_X
270
if temp0 == FLIP_X
271
FlipSign(object[arrayPos0].xvel)
272
end if
273
object[arrayPos0].timer = 0x600
274
object[arrayPos0].animation = BOMB_ANI_WALK
275
object[arrayPos0].frame = 0
276
next
277
278
// Add the object to the debug item list
279
SetTableValue(TypeName[Bomb], DebugMode_ObjCount, DebugMode_TypesTable)
280
SetTableValue(Bomb_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
281
SetTableValue(Bomb_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
282
DebugMode_ObjCount++
283
end event
284
285
286
// ========================
287
// Editor Events
288
// ========================
289
290
event RSDKEdit
291
if editor.returnVariable == true
292
switch editor.variableID
293
case EDIT_VAR_PROPVAL // property value
294
checkResult = object.propertyValue
295
break
296
297
case 0 // direction
298
checkResult = object.propertyValue
299
break
300
301
end switch
302
else
303
switch editor.variableID
304
case EDIT_VAR_PROPVAL // property value
305
object.propertyValue = editor.variableValue
306
break
307
308
case 0 // direction
309
object.propertyValue = editor.variableValue
310
break
311
312
end switch
313
end if
314
end event
315
316
317
event RSDKDraw
318
object.direction = object.propertyValue
319
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
320
end event
321
322
323
event RSDKLoad
324
// Make sure we have a fall-back, in case the current folder isn't actually a valid one
325
temp0 = false
326
327
CheckCurrentStageFolder("Zone06")
328
temp0 |= checkResult
329
if checkResult == true
330
LoadSpriteSheet("SBZ/Objects.gif")
331
SpriteFrame(-10, -21, 20, 37, 52, 40)
332
SpriteFrame(-10, -22, 20, 38, 27, 40)
333
SpriteFrame(-10, -21, 20, 37, 2, 40)
334
SpriteFrame(-10, -22, 20, 38, 52, 1)
335
SpriteFrame(-11, -21, 23, 37, 1, 1)
336
SpriteFrame(-11, -21, 23, 37, 26, 1)
337
SpriteFrame(-11, -9, 23, 25, 1, 79)
338
SpriteFrame(-11, -9, 23, 25, 26, 79)
339
SpriteFrame(-3, -23, 6, 14, 50, 79)
340
SpriteFrame(-4, -25, 8, 16, 57, 79)
341
end if
342
343
CheckCurrentStageFolder("Zone07")
344
temp0 |= checkResult
345
if checkResult == true
346
LoadSpriteSheet("MBZ/Objects.gif")
347
SpriteFrame(-10, -21, 20, 37, 53, 328)
348
SpriteFrame(-10, -22, 20, 38, 28, 328)
349
SpriteFrame(-10, -21, 20, 37, 3, 328)
350
SpriteFrame(-10, -22, 20, 38, 53, 289)
351
SpriteFrame(-11, -21, 23, 37, 2, 289)
352
SpriteFrame(-11, -21, 23, 37, 27, 289)
353
SpriteFrame(-11, -9, 23, 25, 2, 367)
354
SpriteFrame(-11, -9, 23, 25, 27, 367)
355
SpriteFrame(-3, -23, 6, 14, 51, 367)
356
SpriteFrame(-4, -25, 8, 16, 58, 367)
357
end if
358
359
if temp0 == false
360
// We use SLZ's sprites as the fallback, "Zone05" (SLZ's folder) will come here too
361
LoadSpriteSheet("SLZ/Objects.gif")
362
SpriteFrame(-10, -21, 20, 37, 53, 131)
363
SpriteFrame(-10, -22, 20, 38, 28, 131)
364
SpriteFrame(-10, -21, 20, 37, 3, 131)
365
SpriteFrame(-10, -22, 20, 38, 53, 92)
366
SpriteFrame(-11, -21, 23, 37, 2, 92)
367
SpriteFrame(-11, -21, 23, 37, 27, 92)
368
SpriteFrame(-11, -9, 23, 25, 2, 170)
369
SpriteFrame(-11, -9, 23, 25, 27, 170)
370
SpriteFrame(-3, -23, 6, 14, 51, 170)
371
SpriteFrame(-4, -25, 8, 16, 58, 170)
372
end if
373
374
AddEditorVariable("direction")
375
SetActiveVariable("direction")
376
AddEnumVariable("Left", 0)
377
AddEnumVariable("Right", 1)
378
AddEnumVariable("Left (Flip Y)", 2)
379
AddEnumVariable("Right (Flip Y)", 3)
380
end event
381
382