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