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/Crabmeat.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Crabmeat 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.canShoot
16
17
private alias 0 : CRABMEAT_MOVING
18
private alias 1 : CRABMEAT_IDLE
19
private alias 2 : CRABMEAT_SHOOT
20
private alias 3 : CRABMEAT_SHOOTDELAY
21
22
private alias 0 : CRABMEAT_ANI_MOVING
23
private alias 1 : CRABMEAT_ANI_SHOOT
24
private alias 2 : CRABMEAT_ANI_IDLE
25
26
// Player Aliases
27
private alias object.value40 : player.hitboxLeft
28
private alias object.value38 : player.hitboxTop
29
private alias object.value41 : player.hitboxRight
30
private alias object.value39 : player.hitboxBottom
31
32
// Path ID Aliases
33
private alias 0 : PATH_A
34
35
36
// ========================
37
// Function Declarations
38
// ========================
39
40
reserve function Crabmeat_DebugDraw
41
reserve function Crabmeat_DebugSpawn
42
43
44
// ========================
45
// Function Definitions
46
// ========================
47
48
private function Crabmeat_DebugDraw
49
DrawSprite(0)
50
end function
51
52
53
private function Crabmeat_DebugSpawn
54
CreateTempObject(TypeName[Crabmeat], 0, object.xpos, object.ypos)
55
object[tempObjectPos].startPos.x = object.xpos
56
object[tempObjectPos].startPos.y = object.ypos
57
58
GetBit(temp0, object.direction, 0)
59
if temp0 == FLIP_NONE
60
object[tempObjectPos].direction = FLIP_X
61
object[tempObjectPos].xvel = 0x8000
62
else
63
object[tempObjectPos].direction = FLIP_X
64
object[tempObjectPos].xvel = -0x8000
65
end if
66
67
object[tempObjectPos].canShoot = false
68
end function
69
70
71
// ========================
72
// Events
73
// ========================
74
75
event ObjectUpdate
76
switch object.state
77
case CRABMEAT_MOVING
78
object.priority = PRIORITY_ACTIVE
79
80
if object.timer < 127
81
object.timer++
82
object.xpos += object.xvel
83
if object.xvel > 0
84
ObjectTileGrip(CSIDE_FLOOR, 14, 15, PATH_A)
85
else
86
ObjectTileGrip(CSIDE_FLOOR, -14, 15, PATH_A)
87
end if
88
89
if checkResult == false
90
if object.canShoot == true
91
object.state = CRABMEAT_SHOOT
92
else
93
object.state = CRABMEAT_IDLE
94
object.canShoot = true
95
end if
96
object.timer = 0
97
object.animation = CRABMEAT_ANI_SHOOT
98
end if
99
ObjectTileGrip(CSIDE_FLOOR, 0, 15, PATH_A)
100
else
101
if object.canShoot == true
102
object.state = CRABMEAT_SHOOT
103
else
104
object.state = CRABMEAT_IDLE
105
object.canShoot = true
106
end if
107
108
object.timer = 0
109
object.animation = CRABMEAT_ANI_SHOOT
110
end if
111
break
112
113
case CRABMEAT_IDLE
114
if object.timer < 59
115
object.timer++
116
else
117
object.timer = 0
118
object.state = CRABMEAT_MOVING
119
object.animation = CRABMEAT_ANI_MOVING
120
object.animationTimer = 0
121
FlipSign(object.xvel)
122
end if
123
break
124
125
case CRABMEAT_SHOOT
126
if object.timer < 59
127
object.timer++
128
else
129
CreateTempObject(TypeName[Crabmeat Shot], 0, object.xpos, object.ypos)
130
object[tempObjectPos].xpos -= 0x100000
131
object[tempObjectPos].xvel = -0x10000
132
object[tempObjectPos].yvel = -0x40000
133
134
CreateTempObject(TypeName[Crabmeat Shot], 0, object.xpos, object.ypos)
135
object[tempObjectPos].xpos += 0x100000
136
object[tempObjectPos].xvel = 0x10000
137
object[tempObjectPos].yvel = -0x40000
138
139
object.timer = 0
140
object.state++
141
object.animation = CRABMEAT_ANI_IDLE
142
end if
143
break
144
145
case CRABMEAT_SHOOTDELAY
146
if object.timer < 59
147
object.timer++
148
else
149
object.timer = 0
150
object.state = CRABMEAT_MOVING
151
object.animation = CRABMEAT_ANI_MOVING
152
object.animationTimer = 0
153
FlipSign(object.xvel)
154
end if
155
break
156
157
end switch
158
159
if object.outOfBounds == true
160
temp0 = object.xpos
161
temp1 = object.ypos
162
object.xpos = object.startPos.x
163
object.ypos = object.startPos.y
164
if object.outOfBounds == true
165
if object.propertyValue == 1
166
object.direction = FLIP_X
167
object.xvel = 0x8000
168
else
169
object.direction = FLIP_X
170
object.xvel = -0x8000
171
end if
172
173
object.canShoot = false
174
object.state = CRABMEAT_MOVING
175
object.timer = 0
176
object.priority = PRIORITY_BOUNDS
177
object.animation = CRABMEAT_ANI_MOVING
178
object.animationTimer = 0
179
else
180
object.xpos = temp0
181
object.ypos = temp1
182
end if
183
end if
184
185
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
186
BoxCollisionTest(C_TOUCH, object.entityPos, -14, -14, 14, 14, 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
next
191
192
switch object.animation
193
case CRABMEAT_ANI_MOVING
194
object.frame = object.animationTimer
195
object.frame >>= 4
196
object.animationTimer++
197
object.animationTimer %= 48
198
break
199
200
case CRABMEAT_ANI_SHOOT
201
object.frame = 0
202
break
203
204
case CRABMEAT_ANI_IDLE
205
object.frame = 3
206
break
207
208
end switch
209
end event
210
211
212
event ObjectDraw
213
DrawSprite(object.frame)
214
end event
215
216
217
event ObjectStartup
218
CheckCurrentStageFolder("Zone01")
219
if checkResult == true
220
LoadSpriteSheet("GHZ/Objects.gif")
221
SpriteFrame(-21, -16, 42, 31, 138, 157)
222
SpriteFrame(-22, -16, 44, 31, 98, 189)
223
SpriteFrame(-22, -16, 44, 31, 98, 221)
224
SpriteFrame(-24, -15, 48, 30, 143, 189)
225
end if
226
227
CheckCurrentStageFolder("Zone03")
228
if checkResult == true
229
LoadSpriteSheet("SYZ/Objects.gif")
230
SpriteFrame(-21, -16, 42, 31, 184, 1)
231
SpriteFrame(-22, -16, 44, 31, 184, 34)
232
SpriteFrame(-22, -16, 44, 31, 184, 66)
233
SpriteFrame(-24, -15, 48, 30, 184, 173)
234
end if
235
236
CheckCurrentStageFolder("Zone07")
237
if checkResult == true
238
LoadSpriteSheet("MBZ/Objects.gif")
239
SpriteFrame(-21, -16, 42, 31, 168, 81)
240
SpriteFrame(-22, -16, 44, 31, 211, 81)
241
SpriteFrame(-22, -16, 44, 31, 211, 113)
242
SpriteFrame(-24, -15, 48, 30, 162, 114)
243
end if
244
245
foreach (TypeName[Crabmeat], arrayPos0, ALL_ENTITIES)
246
object[arrayPos0].startPos.x = object[arrayPos0].xpos
247
object[arrayPos0].startPos.y = object[arrayPos0].ypos
248
if object[arrayPos0].propertyValue == 1
249
object[arrayPos0].direction = FLIP_X
250
object[arrayPos0].xvel = 0x8000
251
else
252
object[arrayPos0].direction = FLIP_X
253
object[arrayPos0].xvel = -0x8000
254
end if
255
256
object[arrayPos0].canShoot = false
257
next
258
259
SetTableValue(TypeName[Crabmeat], DebugMode_ObjCount, DebugMode_TypesTable)
260
SetTableValue(Crabmeat_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
261
SetTableValue(Crabmeat_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
checkResult = object.propertyValue
279
break
280
281
end switch
282
else
283
switch editor.variableID
284
case EDIT_VAR_PROPVAL // property value
285
object.propertyValue = editor.variableValue
286
break
287
288
case 0 // direction
289
object.propertyValue = editor.variableValue
290
break
291
292
end switch
293
end if
294
end event
295
296
297
event RSDKDraw
298
DrawSprite(0)
299
end event
300
301
302
event RSDKLoad
303
// Make sure we have a fall-back, in case the current folder isn't actually a valid one
304
temp0 = false
305
306
CheckCurrentStageFolder("Zone03")
307
temp0 |= checkResult
308
if checkResult == true
309
LoadSpriteSheet("SYZ/Objects.gif")
310
SpriteFrame(-21, -16, 42, 31, 184, 1)
311
end if
312
313
CheckCurrentStageFolder("Zone07")
314
temp0 |= checkResult
315
if checkResult == true
316
LoadSpriteSheet("MBZ/Objects.gif")
317
SpriteFrame(-21, -16, 42, 31, 168, 81)
318
end if
319
320
if temp0 == false
321
// We use GHZ's sprites as the fallback, "Zone01" (GHZ's folder) will come here too
322
LoadSpriteSheet("GHZ/Objects.gif")
323
SpriteFrame(-21, -16, 42, 31, 138, 157)
324
end if
325
326
AddEditorVariable("direction")
327
SetActiveVariable("direction")
328
AddEnumVariable("Left", 0)
329
AddEnumVariable("Right", 1)
330
end event
331
332