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