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/Slicer.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Slicer 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.value31 : object.wrapOffset.y
16
17
// States
18
private alias 0 : SLICER_MOVING
19
private alias 1 : SLICER_CHECKPLAYERINRANGE
20
private alias 2 : SLICER_THROWARM
21
private alias 3 : SLICER_ARMTHROWN
22
23
// Player Aliases
24
private alias object.value40 : player.hitboxLeft
25
private alias object.value38 : player.hitboxTop
26
private alias object.value41 : player.hitboxRight
27
private alias object.value39 : player.hitboxBottom
28
29
// Path ID Aliases
30
private alias 0 : PATH_A
31
32
33
// ========================
34
// Function Declarations
35
// ========================
36
37
reserve function Slicer_Setup
38
reserve function Slicer_DebugDraw
39
reserve function Slicer_DebugSpawn
40
41
42
// ========================
43
// Function Definitions
44
// ========================
45
46
private function Slicer_Setup
47
object[arrayPos0].direction = object[arrayPos0].propertyValue
48
GetBit(temp0, object[arrayPos0].direction, 0)
49
if temp0 == FACING_RIGHT
50
object[arrayPos0].xvel = 0x4000
51
else
52
object[arrayPos0].xvel = -0x4000
53
end if
54
55
object[arrayPos0].frame = 0
56
object[arrayPos0].timer = 0
57
object[arrayPos0].state = SLICER_MOVING
58
object[arrayPos0].priority = PRIORITY_BOUNDS
59
end function
60
61
62
private function Slicer_DebugDraw
63
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
64
end function
65
66
67
private function Slicer_DebugSpawn
68
CreateTempObject(TypeName[Slicer], object.direction, object.xpos, object.ypos)
69
arrayPos0 = object[tempObjectPos].entityPos
70
object[arrayPos0].startPos.x = object.xpos
71
object[arrayPos0].startPos.y = object.ypos
72
CallFunction(Slicer_Setup)
73
end function
74
75
76
// ========================
77
// Events
78
// ========================
79
80
event ObjectUpdate
81
switch object.state
82
case SLICER_MOVING
83
object.priority = PRIORITY_ACTIVE
84
object.xpos += object.xvel
85
86
GetBit(temp0, object.direction, 1) // see if the Y flip bit is set
87
if temp0 == false
88
ObjectTileGrip(CSIDE_FLOOR, 0, 17, PATH_A)
89
else
90
ObjectTileGrip(CSIDE_ROOF, 0, -17, PATH_A)
91
end if
92
93
if checkResult == false
94
object.state = SLICER_CHECKPLAYERINRANGE
95
object.timer = 60
96
end if
97
98
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
99
if object.direction == FLIP_NONE
100
BoxCollisionTest(C_TOUCH, object.entityPos, 0, -256, 128, 256, currentPlayer, -1, -1, 1, 1)
101
else
102
BoxCollisionTest(C_TOUCH, object.entityPos, -128, -256, 0, 256, currentPlayer, -1, -1, 1, 1)
103
end if
104
105
if checkResult == true
106
object.timer = 9
107
object.frame = 3
108
object.state = SLICER_THROWARM
109
end if
110
next
111
112
object.animationTimer++
113
if object.animationTimer >= 20
114
object.animationTimer = 0
115
object.frame ^= 1
116
end if
117
break
118
119
case SLICER_CHECKPLAYERINRANGE
120
object.timer--
121
if object.timer == 0
122
object.direction ^= FLIP_X
123
FlipSign(object.xvel)
124
object.state = SLICER_MOVING
125
end if
126
127
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
128
if object.direction == FLIP_NONE
129
BoxCollisionTest(C_TOUCH, object.entityPos, 0, -256, 128, 256, currentPlayer, -1, -1, 1, 1)
130
else
131
BoxCollisionTest(C_TOUCH, object.entityPos, -128, -256, 0, 256, currentPlayer, -1, -1, 1, 1)
132
end if
133
134
if checkResult == true
135
object.timer = 9
136
object.frame = 3
137
object.state = SLICER_THROWARM
138
end if
139
next
140
break
141
142
case SLICER_THROWARM
143
object.timer--
144
if object.timer == 0
145
CreateTempObject(TypeName[Slicer Arm], 0, object.xpos, object.ypos)
146
object[tempObjectPos].direction = object.direction
147
object[tempObjectPos].startPos.x = object.entityPos
148
if object.direction == FLIP_NONE
149
object[tempObjectPos].xvel = 0x20000
150
object[tempObjectPos].xpos += 0x60000
151
else
152
object[tempObjectPos].xvel = -0x20000
153
object[tempObjectPos].xpos -= 0x60000
154
end if
155
156
CreateTempObject(TypeName[Slicer Arm], 0, object.xpos, object.ypos)
157
object[tempObjectPos].direction = object.direction
158
object[tempObjectPos].startPos.x = object.entityPos
159
if object.direction == FLIP_NONE
160
object[tempObjectPos].xvel = 0x20000
161
object[tempObjectPos].xpos -= 0x100000
162
else
163
object[tempObjectPos].xvel = -0x20000
164
object[tempObjectPos].xpos += 0x100000
165
end if
166
167
object.frame = 4
168
object.state = SLICER_ARMTHROWN
169
end if
170
break
171
172
case SLICER_ARMTHROWN
173
break
174
175
end switch
176
177
if object.outOfBounds == true
178
temp0 = object.xpos
179
temp1 = object.ypos
180
object.xpos = object.startPos.x
181
object.ypos = object.startPos.y
182
object.ypos += object.wrapOffset.y
183
if object.outOfBounds == true
184
arrayPos0 = object.entityPos
185
CallFunction(Slicer_Setup)
186
else
187
object.xpos = temp0
188
object.ypos = temp1
189
end if
190
end if
191
192
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
193
BoxCollisionTest(C_TOUCH, object.entityPos, -16, -16, 16, 16, currentPlayer, player[currentPlayer].hitboxLeft, player[currentPlayer].hitboxTop, player[currentPlayer].hitboxRight, player[currentPlayer].hitboxBottom)
194
if checkResult == true
195
CallFunction(Player_BadnikBreak)
196
end if
197
next
198
end event
199
200
201
event ObjectDraw
202
DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
203
end event
204
205
206
event ObjectStartup
207
CheckCurrentStageFolder("Zone09")
208
if checkResult == true
209
LoadSpriteSheet("MPZ/Objects.gif")
210
SpriteFrame(-16, -16, 47, 32, 29, 1)
211
SpriteFrame(-16, -16, 47, 32, 77, 1)
212
SpriteFrame(-16, -16, 47, 32, 125, 1)
213
SpriteFrame(-16, -32, 47, 48, 125, 34)
214
SpriteFrame(-17, -16, 31, 32, 92, 34)
215
else
216
LoadSpriteSheet("MBZ/Objects.gif")
217
SpriteFrame(-16, -16, 47, 32, 880, 256)
218
SpriteFrame(-16, -16, 47, 32, 928, 256)
219
SpriteFrame(-16, -16, 47, 32, 976, 256)
220
SpriteFrame(-16, -32, 47, 48, 976, 289)
221
SpriteFrame(-17, -16, 31, 32, 943, 289)
222
end if
223
224
foreach (TypeName[Slicer], arrayPos0, ALL_ENTITIES)
225
object[arrayPos0].startPos.x = object[arrayPos0].xpos
226
object[arrayPos0].startPos.y = object[arrayPos0].ypos
227
object[arrayPos0].propertyValue ^= 1
228
CallFunction(Slicer_Setup)
229
next
230
231
SetTableValue(TypeName[Slicer], DebugMode_ObjCount, DebugMode_TypesTable)
232
SetTableValue(Slicer_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
233
SetTableValue(Slicer_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
234
DebugMode_ObjCount++
235
end event
236
237
238
// ========================
239
// Editor Events
240
// ========================
241
242
event RSDKEdit
243
if editor.returnVariable == true
244
switch editor.variableID
245
case EDIT_VAR_PROPVAL // property value
246
checkResult = object.propertyValue
247
break
248
249
case 0 // direction
250
checkResult = object.propertyValue
251
break
252
253
end switch
254
else
255
switch editor.variableID
256
case EDIT_VAR_PROPVAL // property value
257
object.propertyValue = editor.variableValue
258
break
259
260
case 0 // direction
261
object.propertyValue = editor.variableValue
262
break
263
264
end switch
265
end if
266
end event
267
268
269
event RSDKDraw
270
object.direction = object.propertyValue
271
object.direction ^= FLIP_X
272
DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
273
end event
274
275
276
event RSDKLoad
277
CheckCurrentStageFolder("Zone09")
278
if checkResult == true
279
LoadSpriteSheet("MPZ/Objects.gif")
280
SpriteFrame(-16, -16, 47, 32, 29, 1)
281
else
282
LoadSpriteSheet("MBZ/Objects.gif")
283
SpriteFrame(-16, -16, 47, 32, 880, 256)
284
end if
285
286
AddEditorVariable("direction")
287
SetActiveVariable("direction")
288
AddEnumVariable("Left", 0)
289
AddEnumVariable("Right", 1)
290
AddEnumVariable("Left (Flip Y)", 2)
291
AddEnumVariable("Right (Flip Y)", 3)
292
end event
293
294