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