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/MCZ/RotatingSpike.txt
1480 views
1
// ----------------------------------
2
// RSDK Project: Sonic 2
3
// Script Description: Rotating Spike 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.swingAngle
13
private alias object.value1 : object.spinSpeed
14
private alias object.value2 : object.length
15
private alias object.value3 : object.amplitude
16
private alias object.value4 : object.spikePos.x
17
private alias object.value5 : object.spikePos.y
18
19
private alias object.value17 : debugMode.currentSelection
20
21
22
// ========================
23
// Function Declarations
24
// ========================
25
26
reserve function RotatingSpike_DebugDraw
27
reserve function RotatingSpike_DebugSpawn
28
29
30
// ========================
31
// Static Values
32
// ========================
33
34
private value RotatingSpike_startDebugID = 0
35
36
37
// ========================
38
// Function Definitions
39
// ========================
40
41
private function RotatingSpike_DebugDraw
42
temp7 = debugMode[0].currentSelection
43
temp7 -= RotatingSpike_startDebugID
44
45
temp6 = object.direction
46
temp6 <<= 8
47
DrawSprite(0)
48
49
temp0 = 0
50
temp1 = 16
51
while temp0 < temp7
52
Cos(temp2, temp6)
53
temp2 *= temp1
54
temp2 <<= 7
55
temp2 += object.xpos
56
Sin(temp3, temp6)
57
temp3 *= temp1
58
temp3 <<= 7
59
temp3 += object.ypos
60
DrawSpriteXY(1, temp2, temp3)
61
temp0++
62
temp1 += 16
63
loop
64
Cos(temp2, temp6)
65
temp2 *= temp1
66
temp2 <<= 7
67
temp2 += object.xpos
68
69
Sin(temp3, temp6)
70
temp3 *= temp1
71
temp3 <<= 7
72
temp3 += object.ypos
73
74
DrawSpriteXY(2, temp2, temp3)
75
end function
76
77
78
private function RotatingSpike_DebugSpawn
79
CreateTempObject(TypeName[Rotating Spike], 0, object.xpos, object.ypos)
80
81
object[tempObjectPos].swingAngle = object.direction
82
object[tempObjectPos].swingAngle <<= 16 // ObjectStartup shifts it by 15...
83
84
if object.direction == FACING_RIGHT
85
object[tempObjectPos].spinSpeed = 0x100
86
else
87
object[tempObjectPos].spinSpeed = -0x100
88
end if
89
90
object[tempObjectPos].length = debugMode[0].currentSelection
91
object[tempObjectPos].length -= RotatingSpike_startDebugID
92
object[tempObjectPos].length++
93
94
object[tempObjectPos].amplitude = object[tempObjectPos].length
95
object[tempObjectPos].amplitude <<= 4
96
end function
97
98
99
// ========================
100
// Events
101
// ========================
102
103
event ObjectUpdate
104
object.swingAngle += object.spinSpeed
105
object.swingAngle &= 0x1FFFF
106
temp0 = object.swingAngle
107
temp0 >>= 8
108
109
// Calculate the spike ball's position
110
Cos(object.spikePos.x, temp0)
111
object.spikePos.x *= object.amplitude
112
object.spikePos.x <<= 7
113
object.spikePos.x += object.xpos
114
115
Sin(object.spikePos.y, temp0)
116
object.spikePos.y *= object.amplitude
117
object.spikePos.y <<= 7
118
object.spikePos.y += object.ypos
119
120
// Backup the object position and replace it with the spike ball's position for collision checks
121
temp0 = object.xpos
122
temp1 = object.ypos
123
object.xpos = object.spikePos.x
124
object.ypos = object.spikePos.y
125
126
foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
127
BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, C_BOX, C_BOX, C_BOX, C_BOX)
128
129
if checkResult == true
130
CallFunction(Player_Hit)
131
end if
132
next
133
134
// Restore that backed-up position from earlier
135
object.xpos = temp0
136
object.ypos = temp1
137
end event
138
139
140
event ObjectDraw
141
// Draw the post first
142
DrawSprite(0)
143
144
// Then draw the chains
145
temp0 = 0
146
temp1 = 16
147
temp4 = object.swingAngle
148
temp4 >>= 8
149
while temp0 < object.length
150
Cos(temp2, temp4)
151
temp2 *= temp1
152
temp2 <<= 7
153
temp2 += object.xpos
154
155
Sin(temp3, temp4)
156
temp3 *= temp1
157
temp3 <<= 7
158
temp3 += object.ypos
159
160
DrawSpriteXY(1, temp2, temp3)
161
162
temp0++
163
temp1 += 16
164
loop
165
temp1 -= 8
166
167
// And finally draw the spike ball itself
168
DrawSpriteXY(2, object.spikePos.x, object.spikePos.y)
169
end event
170
171
172
event ObjectStartup
173
LoadSpriteSheet("MCZ/Objects.gif")
174
175
SpriteFrame(-8, -8, 16, 16, 135, 148) // 0 - Post (same frame as Chain)
176
SpriteFrame(-8, -8, 16, 16, 135, 148) // 1 - Chain
177
SpriteFrame(-16, -16, 32, 32, 103, 0) // 2 - Spike ball
178
179
foreach (TypeName[Rotating Spike], arrayPos0, ALL_ENTITIES)
180
object[arrayPos0].swingAngle = object[arrayPos0].direction
181
object[arrayPos0].swingAngle <<= 15 // To make it around 256 or -256
182
183
object[arrayPos0].direction = FLIP_NONE
184
185
object[arrayPos0].spinSpeed = object[arrayPos0].propertyValue
186
object[arrayPos0].spinSpeed &= 0xF0
187
if object[arrayPos0].spinSpeed >= 0x80
188
object[arrayPos0].spinSpeed -= 0x100
189
end if
190
object[arrayPos0].spinSpeed <<= 4
191
192
object[arrayPos0].length = object[arrayPos0].propertyValue
193
object[arrayPos0].length &= 0x0F
194
195
object[arrayPos0].amplitude = object[arrayPos0].length
196
object[arrayPos0].amplitude <<= 4
197
next
198
199
// Add the object to the debug item list a few times for different lengths
200
temp0 = 0
201
RotatingSpike_startDebugID = DebugMode_ObjCount
202
RotatingSpike_startDebugID--
203
while temp0 < 4
204
SetTableValue(TypeName[Rotating Spike], DebugMode_ObjCount, DebugMode_TypesTable)
205
SetTableValue(RotatingSpike_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
206
SetTableValue(RotatingSpike_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
207
DebugMode_ObjCount++
208
temp0++
209
loop
210
end event
211
212
213
// ========================
214
// Editor Events
215
// ========================
216
217
event RSDKEdit
218
if editor.returnVariable == true
219
switch editor.variableID
220
case EDIT_VAR_PROPVAL // property value
221
checkResult = object.propertyValue
222
break
223
224
case 0 // length
225
checkResult = object.propertyValue
226
checkResult &= 0x0F
227
break
228
229
case 1 // spinSpeed
230
checkResult = object.propertyValue
231
checkResult &= 0xF0
232
checkResult >>= 4
233
break
234
235
case 2 // initialDir
236
checkResult = object.direction
237
break
238
239
end switch
240
else
241
switch editor.variableID
242
case EDIT_VAR_PROPVAL // property value
243
object.propertyValue = editor.variableValue
244
break
245
246
case 0 // length
247
object.propertyValue &= 0xF0
248
editor.variableValue &= 0x0F
249
250
object.propertyValue |= editor.variableValue
251
break
252
253
case 1 // spinSpeed
254
object.propertyValue &= 0x0F
255
editor.variableValue &= 0x0F
256
editor.variableValue <<= 4
257
258
object.propertyValue |= editor.variableValue
259
break
260
261
case 2 // initialDir
262
object.direction = editor.variableValue
263
break
264
265
end switch
266
end if
267
end event
268
269
270
event RSDKDraw
271
object.length = object.propertyValue
272
object.length &= 15
273
object.amplitude = object.length
274
object.amplitude <<= 4
275
276
object.swingAngle = object.direction
277
object.swingAngle <<= 15
278
object.swingAngle &= 0x1FFFF
279
temp4 = object.swingAngle
280
temp4 >>= 8
281
282
Cos(object.spikePos.x, temp4)
283
object.spikePos.x *= object.amplitude
284
object.spikePos.x <<= 7
285
object.spikePos.x += object.xpos
286
287
Sin(object.spikePos.y, temp4)
288
object.spikePos.y *= object.amplitude
289
object.spikePos.y <<= 7
290
object.spikePos.y += object.ypos
291
292
DrawSprite(0)
293
294
temp0 = 0
295
temp1 = 16
296
while temp0 < object.length
297
Cos(temp2, temp4)
298
temp2 *= temp1
299
temp2 <<= 7
300
temp2 += object.xpos
301
302
Sin(temp3, temp4)
303
temp3 *= temp1
304
temp3 <<= 7
305
temp3 += object.ypos
306
307
DrawSpriteXY(1, temp2, temp3)
308
temp0++
309
temp1 += 16
310
loop
311
temp1 -= 8
312
313
DrawSpriteXY(2, object.spikePos.x, object.spikePos.y)
314
end event
315
316
317
event RSDKLoad
318
LoadSpriteSheet("MCZ/Objects.gif")
319
SpriteFrame(-8, -8, 16, 16, 135, 148) // 0 - Post (same frame as Chain)
320
SpriteFrame(-8, -8, 16, 16, 135, 148) // 1 - Chain
321
SpriteFrame(-16, -16, 32, 32, 103, 0) // 2 - Spike ball
322
323
AddEditorVariable("length")
324
SetActiveVariable("length")
325
326
AddEditorVariable("spinSpeed")
327
SetActiveVariable("spinSpeed")
328
329
AddEditorVariable("initialDir")
330
SetActiveVariable("initialDir")
331
AddEnumVariable("Right", 0)
332
AddEnumVariable("Down", 1)
333
AddEnumVariable("Left", 2)
334
AddEnumVariable("Up", 3)
335
end event
336
337